3
votes

I have a problem with my Automated test, My test is running without problems trough Eclipse.

But when i want to run this test on Jenkins, it always fail on the same line(on same selector).

Running TestSuite Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 21173 Only local connections are allowed. Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 34.563 sec <<< FAILURE! - in TestSuite f(webdriver.Single_match_ticket) Time elapsed: 33.86 sec <<< FAILURE! org.openqa.selenium.TimeoutException: Timed out after 19 seconds waiting for element to be clickable: By.cssSelector: a[id='PopularOpener'] > span[tittle='All'] Build info: version: '2.50.1', revision: 'd7fc91b29de65b790abb01f3ac5f7ea2191c88a7', time: '2016-01-29 11:11:26' System info: host: 'Ivan-HP', ip: '192.168.221.103', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Windows\TEMP\scoped_dir676_8604}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=48.0.2564.97, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 634bd38ceca35f9fabe19d967ad5d847 at webdriver.Single_match_ticket.f(Single_match_ticket.java:85)

Results :

Failed tests: Single_match_ticket.f:85 ยป Timeout Timed out after 19 seconds waiting for elem...

Here is part of my code:

public void f() throws Exception {

    WebDriver driver;
    System.setProperty("webdriver.chrome.driver", "webdriver\\chromedriver.exe");



    // open Google Chrome




    driver = new ChromeDriver();
    // Maximize window
    driver.manage().window().maximize();
    driver.manage().deleteAllCookies();

    WebDriverWait wait = new WebDriverWait(driver, 19);

    driver.navigate().to("TESTED SITE");

  
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name='username']")));

    // Set values for username and pass
    driver.findElement(By.cssSelector("input[name='username']")).sendKeys("1testuser");
    driver.findElement(By.cssSelector("input[name='password']")).sendKeys("testtest");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button[type='submit']")));

    // Click on LogIn button
    driver.findElement(By.cssSelector("button[type='submit']")).click();

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='userName']")));

    String Username = driver.findElement(By.xpath(".//*[@id='userName']")).getText();

    String Username1 = "1testuser";

    if (!Username1.equals(Username)) {
      throw new Exception("You are not logged in");

    } else {

      wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.logout-btn.balance.visible")));
      String Balance = driver.findElement(By.cssSelector("div.logout-btn.balance.visible")).getText();

      String[] parts = Balance.split("\\.");
      String part1 = parts[0];

      String secondpart = "";

      if (part1.contains(",")) {

        secondpart = part1.replace(",", "");
      } else {
        secondpart = part1;

      }

      int BalanceInt = Integer.parseInt(secondpart);

      if (BalanceInt > 200) {

        wait.until(ExpectedConditions
          .visibilityOfElementLocated(By.cssSelector("a[id='PopularOpener'] > span[title='All']")));

        driver.findElement((By.cssSelector("a[id='PopularOpener'] > span[title='All']"))).click();

        

        for (int i = 0; i < 3; i++) {
3
Do you run the Jenkins test on the same OS and the same browser as your local machine? - Eugene
Yes i'm running Jenkins test actually on same machine. - Ivan Todorovski

3 Answers

1
votes

the test fail on this line:

wait.until(ExpectedConditions
      .visibilityOfElementLocated(By.cssSelector("a[id='PopularOpener'] > span[title='All']")));

try to select this element not by css as you do

By.cssSelector("a[id='PopularOpener'] > span[title='All']" 

select it by something else for example id, name, xpath.

1
votes

Or if it fails only through Jenkins, check the difference Your local machine from the machine you run the test through Jenkins. Check java version, chrome driver, OS version etc.

0
votes

I resolve this issue with JavascriptExecutor.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("Categories.readPopular()");

This function works fine on J