0

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

一些打开网页并停止
一些进入登录页面并停止一些登录并停止并给我错误为

  • 未找到元素
  • 无法单击元素
  • 在缓存中找不到元素

任何人都可以帮助我...在此先感谢。

我的示例代码是

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>
4

1 回答 1

1

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

于 2013-02-10T12:39:33.070 回答