1
votes

After switching to Selenium Webdriver from RC, Selenium Grid no longer works. Please note that most of my tests are still in RC, but are being converted over to Webdriver a bit at a time, so the Selenium instance is still needed. It looks like my driver and/or browser (Selenium) instances are getting overwritten when running in parallel.

Here is my code:

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


    }

Here is some more info:

Here is the java code for a test:

package XXXXXXXXXXXXXX; import XXXXXXXXXXXXXX;

@Test(groups = { "admin" }) public class EN1200_SR0050_DesignerRightsTest extends SeleniumTestSupport {

@Test
public void testAllowAllAndDenyAllGroupDesignerRights2() {

    GlobalNavigationPage globalNavigationPage = new GlobalNavigationPage(browser);


    // Click Admin tab from global navigation bar.
    globalNavigationPage.clickAdminTab();

Here is the GlobalNavigationPage java code:

package XXXXXXXXXXXX;

import XXXXXXXXXXXXXX;

public class GlobalNavigationPage extends EntityPage {

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!");
}
1

1 Answers

1
votes

My guess is that you have a custom configuration on how to run your tests.

Your hub configuration most likely states:

Only run RC tests.

If you'd like to run WebDriver tests, then you need to specify the amount of WebDriver browsers to use.

{
  "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
  }
}

You can see we can specify "Selenium" for RC tests, and "WebDriver" for Selenium 2 tests.