Java 转换为Webdriver后Selenium Grid出现问题

Java 转换为Webdriver后Selenium Grid出现问题,java,selenium-webdriver,selenium-grid,Java,Selenium Webdriver,Selenium Grid,从RC切换到Selenium Webdriver后,Selenium网格不再工作。请注意,我的大多数测试仍在RC中,但每次都会转换为Webdriver,因此仍然需要Selenium实例。我的驱动程序和/或浏览器(Selenium)实例在并行运行时似乎被覆盖 这是我的密码: public class SeleniumTestSupport { private static Properties singleSharedProperties; private static Sele

从RC切换到Selenium Webdriver后,Selenium网格不再工作。请注意,我的大多数测试仍在RC中,但每次都会转换为Webdriver,因此仍然需要Selenium实例。我的驱动程序和/或浏览器(Selenium)实例在并行运行时似乎被覆盖

这是我的密码:

public class SeleniumTestSupport
{

    private static Properties singleSharedProperties;
    private static Selenium webmailsingleSharedBrowser;
    protected Selenium webmailbrowser;
    protected WebDriver singleSharedDriver;

    protected WebDriver driver;
    protected Selenium browser;//was protected, now public
    protected static String domain;
    Integer flag = 0;

    @BeforeSuite(alwaysRun = true)
    public void startSeleniumClient() {
    }

    @BeforeTest(alwaysRun = true)
    public void distributeTests(){
    }

    @BeforeClass(alwaysRun = true)
    public void initBrowser() {
    }

    @BeforeMethod(alwaysRun = true)
    public void logIn() {

        singleSharedProperties = new Properties(System.getProperties());
        try {
            singleSharedProperties.load(getClass().getClassLoader().getResourceAsStream("selenium.properties"));
            } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
            } catch (IOException e) {
            throw new RuntimeException(e);
        }

        String serverHost = singleSharedProperties.getProperty("selenium.serverHost", "localhost");
        String serverPortText = singleSharedProperties.getProperty("selenium.serverPort", "4444");
        int serverPort;
        try {
            serverPort = Integer.parseInt(serverPortText);
            } catch (NumberFormatException e) {
            throw new RuntimeException("Unable to parse selenium.serverPort '" + serverPortText + "'");
        }
        String browserStartCommand = singleSharedProperties.getProperty("selenium.browserStartCommand");

        System.out.println("serverhost=" + serverHost);
        System.out.println("serverport=" + serverPort);
        System.out.println("browserStartCommand=" + browserStartCommand);
        System.out.println("url=" + singleSharedProperties.getProperty("teamconnect.url"));


        DesiredCapabilities capability = DesiredCapabilities.firefox();
        singleSharedDriver = new RemoteWebDriver(capability);
        driver=singleSharedDriver;
        browser = new WebDriverBackedSelenium(singleSharedDriver, singleSharedProperties.getProperty("teamconnect.url"));


        String usernamePassword = singleSharedProperties.getProperty("teamconnect.user." + getUserGroup());
        String username = StringUtils.substringBefore(usernamePassword, "/");
        String password = StringUtils.substringAfter(usernamePassword, "/");



        driver.get(singleSharedProperties.getProperty("teamconnect.url"));


        //This code is some setup for each Test, basically, logging into the application...
        LoginPage loginPage = new LoginPage(browser);
        loginPage.setUsername(username);
        loginPage.setPassword(password);
        loginPage.clickLogIn();
        //more code later, removed for brevity


    }
以下是更多信息:

以下是测试的java代码:

包装XXXXXXXXXXXXX; 进口XXXXXXXXXXXXX

@测试(组={“管理”}) 公共类EN1200_SR0050_DesignerRightsTest扩展了SeleniumTest支持 {

以下是GlobalNavigationPage java代码:

包装XXXXXXXXXX

进口XXXXXXXXXXXXX

公共类GlobalNavigationPage扩展了EntityPage {

可重用_操作可重用_操作=新的可重用_操作();
页面=新页面(浏览器);
公共全局导航页面(Selenium浏览器){
超级(浏览器);
}
公共无效clickAdminTab(){
长启动=System.currentTimeMillis();
while(System.currentTimeMillis()-start
我猜您有一个关于如何运行测试的自定义配置

您的集线器配置很可能表示:

只运行RC测试

如果要运行WebDriver测试,则需要指定要使用的WebDriver浏览器的数量

{
  "capabilities":
      [
        {
          "browserName": "*firefox",
          "maxInstances": 5,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "*googlechrome",
          "maxInstances": 5,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "*iexplore",
          "maxInstances": 1,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5555,
    "host": ip,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": ip
  }
}

您可以看到,我们可以为RC测试指定
“Selenium”
,为Selenium 2测试指定
“WebDriver”

我的中心配置:java-jar Selenium-server-standalone-2.39.0.jar-角色中心我的节点配置:java-jar Selenium-server-standalone-2.39.0.jar-角色节点-中心-浏览器“browserName=firefox,实例=1”-maxSession=1我使用批处理文件运行这些文件。进一步检查后,似乎我丢失了驱动程序实例,因为它没有被传递下去。
Reusable_Actions reusable_Actions = new Reusable_Actions();
Page page = new Page(browser);

public GlobalNavigationPage(Selenium browser) {
    super(browser);
}


public void clickAdminTab() {

    long start = System.currentTimeMillis();

    while (System.currentTimeMillis() - start < WAIT_TIME_IN_SECONDS * 2000) {

        // if element is present return
        if (browser.isElementPresent(LNK_ADMIN)) {
            return;
        }
        // wait for 1/10 of a second
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }}

    driver.findElement(By.id(LNK_ADMIN)).click();
    browser.setTimeout(Integer.toString(WAIT_TIME_IN_SECONDS * 2000));
    browser.waitForPageToLoad(Integer.toString(WAIT_TIME_IN_SECONDS * 2000));
    assertTextNotPresent("System Error Has Occured!");
}
{
  "capabilities":
      [
        {
          "browserName": "*firefox",
          "maxInstances": 5,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "*googlechrome",
          "maxInstances": 5,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "*iexplore",
          "maxInstances": 1,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5555,
    "host": ip,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": ip
  }
}