Selenium Testing - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Selenium Server

Selenium Server

shape Description

Selenium Server is nothing but little code to interact with the browsers. As of now discussed some of the other selenium technologies like Selenium IDE, which was a Firefox plug-in that the developer could use to record and replay tests and generate selenium web driver tests which just took a look at, which is a technology that allows to automate the browser using C sharp or another language. Now Selenium Server is a little bit different than either one of those.

shape Conceptual Figure

Selenium Server is nothing but a way that one can remote execute out test, in the above diagram selenium test is a web driver test that the developer may have written , just like the web driver tests that already have written in the previous chapters. When the developer run the web driver test, one can tell this web driver test the address of a selenium server by giving port number. Now by default it will runn locally, but if the developer give it a valid address of a selenium server, then it will send that Selenese -- or that test language -- over across a wire to Selenium Server instead of sending it back to our local box and one could even run Selenium Server on the local box. Here the basic idea is that it is going to send those commands to the server, and then server is going to execute those commands on a browser that already have specified. The developer is going to tell selenium server what type of browser would like. It is going to execute that test or those commands on that browser, and then it is going to return the results.

Selenium Server starting in CMD.

shape CMD

Following is the way to start the SELENIUM SERVER. First check whether JDK installed or not by giving java command in the command prompt, then type the following command in the CMD that is java -jar E:\selenium-server-standalone-3.0.0-beta3.jar -port 4444 as follows.

shape Example

Following is an example code to connect to the server. Before writing the code the developer need to import the jar file to the file by using build path as follows. rcdemo.java [java] import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.Selenium; public class rcdemo { public static void main(String[] args) throws InterruptedException { // Instatiate the RC Server Selenium selenium = new DefaultSelenium("localhost", 4444 , "Firefox", "http://www.google.com"); selenium.start(); // Start selenium.open("/"); // Open the URL selenium.windowMaximize(); } } [/java] Where 4444 is nothing but port number to connect to the server, firefox is a browser selenium will only support for Mozilla Firefox and there given a google web site link to connect. While testing any automated web application it is recommended to start Selenium server why because Selenium server session will communicate with the browser, some times it is better to start the Selenium server by using the code as follows in IDE. [java] import org.openqa.selenium.server.RemoteControlConfiguration; import org.openqa.selenium.server.SeleniumServer; import com.thoughtworks.selenium.Selenium; import java.net.BindException; import java.net.ServerSocket; public class Server { public static SeleniumServer server; public static void startSeleniumServer() throws Exception { try { ServerSocket serverSocket = new ServerSocket(RemoteControlConfiguration.DEFAULT_PORT); serverSocket.close(); //Server not up, start it try { RemoteControlConfiguration rcc = new RemoteControlConfiguration(); rcc.setPort(RemoteControlConfiguration.DEFAULT_PORT); server = new SeleniumServer(false, rcc); } catch (Exception e) { System.err.println("Could not create Selenium Server because of: " + e.getMessage()); e.printStackTrace(); } try { server.start(); System.out.println("Server started"); } catch (Exception e) { System.err.println("Could not start Selenium Server because of: " + e.getMessage()); e.printStackTrace(); } } catch (BindException e) { System.out.println("Selenium server already up, will reuse..."); } } public static void stopSeleniumServer(Selenium selenium){ selenium.stop(); if (server != null) { try { selenium.shutDownSeleniumServer(); server.stop(); server = null; } catch (Exception e) { e.printStackTrace(); } } } } [/java] Here the developer directly starting the Selenium server by using code so exception may be occured, here created the class Server and started the Selenium server. [java] public class Server { public static SeleniumServer server; public static void startSeleniumServer() throws Exception { //code } }[/java] To connect to the rowser the default port number is "4444". here used server.start() method. [java] rcc.setPort(RemoteControlConfiguration.DEFAULT_PORT); server.start(); [/java]

Summary

shape Key Points

  • The output of the test is printed on the Eclipse console like pass.
  • Make sure to use advanced version of Selenium Server.
  • The sleep() and setSleep() methods of functionality is same that delay the execution speed.
  • SIDE stands for Selenium integrated development environment.