0

I want to use Selenium Grid for my Testing in that I have successfully launched the Grid and Launched the HUB and NODE .. i also did set my RemoteWebdriver Capability perfectly .. but when I try run the test, all the browers is being opened perfectly but the problem i'm facing is that some browser stop in the middle like

some open the webpage and stops
some enters the login page and stops some loges in and stop and giving me the ERROR as

  • Element Not Found
  • Unable to Click Element
  • Element not found in the cache

Can anyone please help me ... Thanks in Advance.

My sample Code is

public class GmailMail{
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @BeforeClass
public void setup(String browser) throws InterruptedException, IOException {
    DesiredCapabilities capability=null;

    if(browser.equalsIgnoreCase("googlechrome")){ 

        /*ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
        .usingDriverExecutable(
                new File("D:\\downloaded setup\\zip file\\chromedriver_win_26.0.1383.0\\chromedriver.exe"))
        .usingAnyFreePort().build();
chromeDriverService.start();
driver = new ChromeDriver(chromeDriverService);*/

  System.out.println("googlechrome"); 
  capability= DesiredCapabilities.chrome(); 
  capability.setBrowserName("chrome"); 
  capability.setPlatform(org.openqa.selenium.Platform.WINDOWS); 
  //capability.setVersion(""); 

  System.setProperty("webdriver.chrome.driver",
        "D:\\downloaded setup\\zip file\\chromedriver_win_26.0.1383.0\\chromedriver.exe");
        driver = new ChromeDriver();
    }

    if(browser.equalsIgnoreCase("firefox")){
        System.out.println("firefox");
        capability= DesiredCapabilities.firefox();
        capability.setBrowserName("firefox"); 
        capability.setPlatform(org.openqa.selenium.Platform.ANY);
        //capability.setVersion("");
    }

    if(browser.equalsIgnoreCase("iexplore")){
        System.out.println("iexplore");
        capability= DesiredCapabilities.internetExplorer();
        capability.setBrowserName("iexplore"); 
        capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
        //capability.setVersion("");*/
        System.setProperty("webdriver.ie.driver", "D:\\downloaded setup\\zip file\\IEDriverServer_Win32_2.29.0\\IEDriverServer.exe");
        driver = new InternetExplorerDriver();
    }

    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
    driver.navigate().to(baseUrl);
    long ss = Thread.currentThread().getId();
    System.out.println("ss: "+ss);

}


  @Test
  public void testUntitled() throws Exception {
    driver.get(baseUrl + "/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/mail/&scc=1&ltmpl=default&ltmplcache=2");
    driver.findElement(By.id("Email")).clear();
    driver.findElement(By.id("Email")).sendKeys("YourUserName");
    driver.findElement(By.id("Passwd")).clear();
    driver.findElement(By.id("Passwd")).sendKeys("YourPassowrd");
    driver.findElement(By.id("signIn")).click();

  }

  @AfterClass
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alert.getText();
    } finally {
      acceptNextAlert = true;
    }
  }
}

and my Testng.xml is

<suite name="Same TestCases on Different Browser" verbose="3"  parallel="tests" thread-count="2">   
  <test name="Run on Internet Explorer">
    <parameter name="browser"  value="firefox"/>
    <classes>
      <class name="TestPAck1.GmailMail"/>
    </classes>
 </test>  
  <test name="Run on Internet Explorer1">
    <classes>
    <parameter name="browser"  value="googlechrome"/>
      <class name="TestPAck1.GmailMail"/>
    </classes>
 </test>

 </suite>

1 Answer 1

1

at first glance this seems to be a sync issue. If you could share the appropriate section of your code, it might be easier to identify the issue.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi Thanks for the reply .. I cant give u the entire Test Code but ill give you the same Code which is also Facing the same issues.
Hi selva, use a loop within the isElementPresent method. For each navigation, wait for the element to be present before performing an action on it private boolean isElementPresent(By by) { int counter; for (counter=1; counter<=10; counter++){ try { driver.findElement(by); } catch (NoSuchElementException e) { Thread.sleep(1000); } return true; } return false; }
your main code will look similar to this @Test public void testUntitled() throws Exception { boolean result; driver.get(baseUrl); result=isElementPresent(By.id("Email")); if (result=true){ //perform the rest of your actions } else { //report failure } }
The findElemeny(by) function comes with an implicit wait. There are times when an application might take a slightly longer time to load. This time might vary based on the speed of your test environment and the loop allows you to define the worst case scenario.
Hi thanks again .. but some of the browser stops at the beginning itself like it just open the login page and stops and some just enter the username and password than stops ... Is this because of some hardware problem, i dont think so for im using window 7 with 4 GB ram ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.