1

我正在尝试使用我已经拥有的 webdriver 代码设置 selenium grid 2。我正在尝试在谷歌上找到的几个教程,但遇到了同样的问题:每个测试用例一个接一个地开始。我想要的是它们都同时启动(都使用 IE8) 我启动了集线器和节点,当我去的时候,http://localhost:4444/grid/console我可以看到两个节点都使用 IE8。这是我的代码,它现在所做的就是去谷歌。请问有什么帮助吗?谢谢!

public class CodesIntegrationTestCase {

    private static String SELENIUM_HUB_URL;
    private static String TARGET_SERVER_URL;

    @BeforeClass
    public static void initEnvironment() {
        SELENIUM_HUB_URL = getConfigurationProperty(
           "SELENIUM_HUB_URL",
           "test.selenium.hub.url",
           "http://localhost:4444/wd/hub");
        System.out.println("using Selenium hub at: " + SELENIUM_HUB_URL);


        TARGET_SERVER_URL = getConfigurationProperty(
            "TARGET_SERVER_URL",
            "test.target.server.url",
            "http://google.com");
        System.out.println("using target at: " + TARGET_SERVER_URL);

    }

    private static String getConfigurationProperty(
            String envKey, String sysKey, String defValue) {
        String retValue = defValue;
        String envValue = System.getenv(envKey);
        String sysValue = System.getProperty(sysKey);
        // system property prevails over environment variable
        if (sysValue != null) {
            retValue = sysValue;
        } else if (envValue != null) {
            retValue = envValue;
        }
        return retValue;
    }


    @Test
    public void testIE()
            throws MalformedURLException, IOException {
        DesiredCapabilities browser = DesiredCapabilities.internetExplorer();
        testCodesCrud(browser);
    }

    @Test
    public void testIE2()
            throws MalformedURLException, IOException {
        DesiredCapabilities browser = DesiredCapabilities.internetExplorer();
        testCodesCrud(browser);
    }
 public void testCodesCrud(DesiredCapabilities browser)
            throws MalformedURLException, IOException {
        WebDriver driver = null;
        try {
            driver = new RemoteWebDriver(
                new URL(SELENIUM_HUB_URL), browser);

            // test starts in Codes entity list page
            driver.get(TARGET_SERVER_URL + "/CodesView.do");

            // rest of test commands come here
        } finally {
            if (driver != null) {
                driver.quit();
            }
        }
    }

}
4

0 回答 0