2013-02-09 81 views
0

我想为我的测试使用Selenium Grid,我已经成功地启动了Grid并启动了HUB和NODE ..我也设置了我的RemoteWebdriver Capability ..但是当我尝试运行在测试中,所有的browers被完全打开,但我现在面临的问题是,在中间的一些浏览器停止像Selenium Grid 2并行测试用例执行

一些打开网页,并停止
一些进入登录页面,在停止 一些包厢和停止并给我错误,因为

  • 未找到元素
  • 无法点击元素
  • 元素在缓存

没有发现任何人都可以请帮我... 先谢谢了。

我的示例代码是

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; 
    } 
    } 
} 

和我的testng.xml是

<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

乍一看,这似乎是一个同步问题。如果您可以分享您的代码的适当部分,可能会更容易找出问题。

+0

嗨感谢您的答复..我不能给你整个测试代码,但生病给你相同的代码,也面临着同样的问题。 – selva 2013-02-11 05:02:03

+0

嗨selva,在isElementPresent方法中使用循环。 对于每个导航,在对其执行动作之前等待该元素存在 private boolean isElementPresent {By} { \t int counter; (计数器= 1;计数器<= 10;计数器++){ 尝试{driver.findElement(by); } catch(NoSuchElementException e){ \t Thread.sleep(1000); } return true; \t} \t return false; } – Sai 2013-02-11 08:55:03

+0

您的主要代码与此类似 @Test public void testUntitled()throws Exception { 布尔结果; driver.get(baseUrl); \t result = isElementPresent(By.id(“Email”)); \t如果(结果=真){ \t \t //执行你的行动 \t其余} 其他{ \t \t //报告故障 }} 的 – Sai 2013-02-11 08:55:32