Selenium 4 - Running scripts without StandaloneConfiguration

45 views
Skip to first unread message

kfauto13

unread,
Apr 30, 2020, 1:03:59 PM4/30/20
to Selenium Users
I apologize for what may be a dumb question but this code isn't something I've worked with before as it was already in the project once I joined.  I am looking ahead to Selenium 4 and am looking to run some of our tests using Selenium 4 alpha 5.

The way we currently execute our tests is to instantiate the Selenium Server (which does not exist in Selenium 4). We then use StandaloneConfiguration (which also doesn't exist in Selenium 4) to set the port then we start the server:

protected static SeleniumServer server;

In our beforeSuite:

if(seleniumServer.equals("localhost") || seleniumServer.equals("hub")) { // hub means inside Box but not using the grid

     StandaloneConfiguration sc = new StandaloneConfiguration();

     if (null != port && ""!=port)

sc.port = Integer.parseInt(port);

     try {

server = new SeleniumServer(sc);

server.boot();

     } catch (Exception e) {

throw new IllegalStateException("Can't start selenium server", e);

     }

     } else {

         localExecution = false;

     }

We have the capability to run both locally and using a grid, hence the above code.

I have seen the documentation for Selenium 4 and it shows how to start the server using the command line, but we can't do that within our tests. I have also looked at the changelog and can see the standalone support was removed but there's no indication of what replaced it, and there isn't documentation yet for Selenium 4. 

Any help or pointing in the right direction is greatly appreciated!

⇜Krishnan Mahadevan⇝

unread,
May 1, 2020, 2:41:51 AM5/1/20
to Selenium Users
You are trying to deal with this from the wrong angle. 
Having the ability to toggle between local and remote executions doesn't mean that you need to mandatorily work with a selenium server.

Can you show us how your browser instantiation logic looks like?

You just need to do the following on a high level:
  1. The return type of the browser instantiation method should be "RemoteWebDriver"
  2. If local, then depending upon browser type, toggle between InternetExplorerDriver/ChromeDriver/FirefoxDriver
  3. If remote, then retain your current logic of instantiating a RemoteWebDriver object.
This will do away with the need of having any selenium server locally.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/8c7c89b3-8546-4e53-a39b-996f71cef58e%40googlegroups.com.

kfauto13

unread,
May 5, 2020, 9:14:51 AM5/5/20
to Selenium Users
For Selenium 3, this is the code we're using (including the portions of methods that are relevent) and we're using WebDriverManager to handle the browser drivers because we test different versions of each browser:

protected static WebDriver driverInstance[] = new WebDriver[MAX_DRIVERS+1];


public void beforeSuite(ITestContext context)

{

  ....

  String seleniumServer = AutomationUtility.getProperty("uitest.selenium.host", "localhost");

  String port = AutomationUtility.getProperty("uitest.selenium.port","4444");

  if(seleniumServer.equals("localhost") || seleniumServer.equals("hub")) { // hub means inside qaBox but not using the grid

      StandaloneConfiguration sc = new StandaloneConfiguration();

      if (null != port && ""!=port)

          sc.port = Integer.parseInt(port);

      try {

          server = new SeleniumServer(sc);

  server.boot();

      } catch (Exception e) {

  throw new IllegalStateException("Can't start selenium server", e);

      }

   } else {

      localExecution = false;

   }

}


public void setupDriver(String browser, int num)

{

  ... Get all browser info - type, host, port, grid user, grid token, etc.


  WebDriverManager wdm = null;


  // Example for Chrome

  if(seleniumBrowser.equals("*chrome"))

  {

      options = new ChromeOptions();

      Logger.detailsFine("Starting chrome driver");

      ... Add chrome options

      Reporter.getCurrentTestResult().setAttribute("browser", "Chrome");

      String chromeWebdriver = AutomationUtility.getProperty("uitest.chrome.webdriver", "webdriver.chrome.driver");

      String chromeWebdriverLocation = AutomationUtility.getProperty("uitest.chrome.webdriverLocation", "lib\\chromedriver.exe");

      System.setProperty(chromeWebdriver, chromeWebdriverLocation);

      if(localExecution)

  wdm = WebDriverManager.chromedriver();

      }

  }

    ... other browsers


  if(wdm != null && localExecution)

      wdm.setup();


  driverInstance[num] = new RemoteWebDriver(new URL("http://"+seleniumHost+":"+seleniumPort+"/wd/hub"), options);


  ... other browser-specific code

To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
May 5, 2020, 9:59:18 AM5/5/20
to Selenium Users
You just need to wrap this line driverInstance[num] = new RemoteWebDriver(new URL("http://"+seleniumHost+":"+seleniumPort+"/wd/hub"), options);

within an if condition, wherein you do this only if its not localExecution else you would need to create the InternetExplorerDriver/FirefoxDriver/ChromeDriver instance. That should take care of this.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6b92170b-a2fa-49f1-9f37-22f437828e87%40googlegroups.com.

kfauto13

unread,
May 8, 2020, 8:50:03 AM5/8/20
to Selenium Users
Thank you!! I had been looking at the code for so long that I knew it had to be something easy that I just wasn't seeing. The second set of eyes definitely helped.

Thanks for your help!

Reply all
Reply to author
Forward
0 new messages