Forum Discussion

RaghavanG's avatar
RaghavanG
Occasional Contributor
2 years ago

Create Selenium Tests in ReadyAPI

How to Create Selenium Tests in ReadyAPI?. Getting error. Not sure where it went wrong.

I followed the steps in below link.

https://support.smartbear.com/readyapi/docs/integrations/selenium/integrate.html

Getting below error when I have tried sample code in Groovy scripts.

Snippet:

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;

System.setProperty("webdriver.chrome.driver", "C:/Program Files/SmartBear/ReadyAPI-3.42.1/bin/ext/chromedriver.exe");

def driver = new ChromeDriver()

// Navigate to the ReadyAPI documentation
driver.get("https://support.smartbear.com/readyapi/docs/")

// Enter the search string
def searchbox = driver.findElement(By.id("inputSearchBox"));
searchbox.sendKeys("Groovy");

// Command to search for the typed text
def searchbtn = driver.findElement(By.id("btnSearch"));
searchbtn.click();

// List suggestions
def allSuggestions = driver.findElements(By.xpath("//div[@id='search_results_container']/div/h5/a"))
for (def suggestion : allSuggestions)
{
if(suggestion.getAttribute('href') != '')
log.info(suggestion.getAttribute('href'))
else
log.error('The test failed.')
}
// Close the browser
driver.quit();

 

Error:

 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script4.groovy: 7: unable to resolve class ChromeDriver
@ line 7, column 14.
def driver = new ChromeDriver()
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class ChromeDriver
@ line 7, column 14.

 

  • Hello RaghavanG 

     

    If you choose to deviate from the steps described in the instructions, you will need to be prepared for the ramifications...  🙂

     

    You have replaced some firefox values that were defined in the instructions with chrome values.  It looks like you need to change line:

       import org.openqa.selenium.firefox.FirefoxDriver;

    to:

       import org.openqa.selenium.chrome.ChromeDriver;

    in order to overcome your current condition.  After that is done, you may encounter further errors.  I have not debugged your code beyond what jumps out at me.  🙂

     

    Regards,

    Todd

     

    • Kpm's avatar
      Kpm
      Occasional Visitor

      Hi 

      I am facing this failure java.lang.NoClassDefFoundError: org/openqa/selenium/chromium/ChromiumDriver.

      I have kept all necessary selenium jars (selenium api, selenium support, selenium -chrome, chromium, remote all drivers) inside ReadyAPI/bin/ext including chromedriver.exe. How to resolve this failure? plz

      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.openqa.selenium.By;
      import org.openqa.selenium.WebElement;
       
      System.setProperty("webdriver.chrome.driver", "C:/Program Files/SmartBear/ReadyAPI-3.54.0/bin/ext/chromedriver");
       
      //Initialize WebDriver
      def driver = new ChromeDriver();
       
      driver.get("https://support.smartbear.com/readyapi/docs/")
      def searchbox = driver.findElement(By.id("inputSearchBox"));
      def searchbtn = driver.findElement(By.id("btnSearch"));
      searchbtn.click();
          
       

       

      • TNeuschwanger's avatar
        TNeuschwanger
        Champion Level 1

        Hello Kpm ,

        I have never had good results putting my jar files in the location Smartbear says to...

        I do not use:  ReadyAPI/bin/ext

        Use: ReadyAPI/lib

        Where all the other jar files are stored.

        Exit ReadyAPI and delete or move the selenium jar files you put in ReadyAPI/bin/ext to ReadyAPI/lib then restart ReadyAPI.  Remember to rename the originality installed guava jar to guava.ojaro.

        After you restart ReadyAPI with those changes you should be relieved of the error.

        Regards,

        Todd

         

  • TNeuschwanger's avatar
    TNeuschwanger
    Champion Level 1

    Hello RaghavanG 

     

    If you choose to deviate from the steps described in the instructions, you will need to be prepared for the ramifications...  🙂

     

    You have replaced some firefox values that were defined in the instructions with chrome values.  It looks like you need to change line:

       import org.openqa.selenium.firefox.FirefoxDriver;

    to:

       import org.openqa.selenium.chrome.ChromeDriver;

    in order to overcome your current condition.  After that is done, you may encounter further errors.  I have not debugged your code beyond what jumps out at me.  🙂

     

    Regards,

    Todd