How to Run Selenium Testing Script In Cloud

Problem
Your website users come from all over the world. They use different devices, operating systems and different browsers. There are totally 1500+ web browsers in the world, the browser is used from iPhone, iPad, Android devices, Windows, Linux etc. So to make your web application perfect you had better verify how your web application behaves on all those various different devices, operating systems and browsers. But it is too difficult to maintain so many devices and browsers to verify your web application features effectively in selenium automation test scripts.

Solution
Do not worry, CrossBrowserTesting also called CBT  is coming. It is a cloud-based platform which support almost all of the current devices, operating systems and browsers. You can test both web or mobile applications with real physical machine, mobile devices or web browser simulators. You can run your selenium testing automation scripts through thousands of browsers and devices with CBT. You do not need to maintain those operating system, devices and browsers. You can fully focus on writing your selenium testing scripts. CBT will do other things for you.

Steps
The steps to use CrossBrowserTesting to execute your selenium testing automation scripts in cloud.

  1. Register for free CrossBrowserTesting account. It is so easy.
  2. Find your authkey at Account -> Manage Account after you login.
    find crossbrowsertest auth key in user accountfind crossbrowsertest authkey
  3. Download and add following required library jar files into your java project to run selenium testing automation scripts.
    Click following link to download.
    selenium-server-standalone-2.53.0.jar
    unirest-java-1.4.9.jarDownload unirest java library jar files without maven
    junit-4.11.jar
  4. After all the prepare work is done, now you can write following selenium testing java code in your eclipse and run it. Read code comments for detail explanation.
/* This is the user name you registered in crossbrowsertesting.com, 
 * it is usually an email address, but the @ character is replaced with %40.*/
 String username = "h**************g%40gmail.com";
 
 /*This is the authkey you obtained from crossbrowsertesting.com when you register account.*/
 String authkey = "u*****************e";

/*Because we will run selenium testing script in cloud so we use RemoteWebDriver.*/
 RemoteWebDriver driver = null;
 
 try {
 
 /* Create an instance of DesiredCapabilities, this object is used to transfer detail 
 * information about the device, browser etc to crossbrowsertesting.com, then crossbrowsertesting.com
 * use these information to initiate the web browser for you.*/
 DesiredCapabilities caps = new DesiredCapabilities();
 
 //Set the name attribute.
 caps.setCapability("name", "Selenium Automation Testing Example");
 
 //Set the build number.
 caps.setCapability("build", "1.0");
 
 //Set the browser type which is IE Edge. This is the must set field. This data will tell CBT which web browser to use.
 caps.setCapability("browser_api_name", "Edge20");
 
 //Set the operating system. This is the must set field. This data will tell CBT which os to use.
 caps.setCapability("os_api_name", "Win10");
 
 //Set the screen display resolution.
 caps.setCapability("screen_resolution", "1024x768");
 
 //Set the selenium webdriver library version.
 caps.setCapability("selenium_version", "2.53.1");
 
 /*Create the remote webdriver object use above information. Because the web browser will be running in the remote server so
 we should use RemoteWebDriver instead of WebDriver which is used to initiate web browser locally. */
 driver = new RemoteWebDriver(new URL("http://" + username + ":" + authkey + "@hub.crossbrowsertesting.com:80/wd/hub"), caps);
 
 //Print out session id.
 System.out.println("Session id : " + driver.getSessionId());
 
 //Start to load the web pages we want to test.
 System.out.println("Loading test pages");
 
 //The loaded test page is an example page in crossbrowsertesting.com
 driver.get("http://crossbrowsertesting.github.io/selenium_example_page.html");
 
 //Make the web browser's windown in the cloud platform maximized.
 System.out.println("Make the web browser's windown in the cloud platform maximized.");
 driver.manage().window().maximize();
 
 //Verify the loaded web page title to see whether the page loaded correct or not.
 Assert.assertEquals(driver.getTitle(), "Selenium Test Example Page");
 
 } catch (AssertionError aex) {
 /* If an assertion exception occured, just print the exception trace. 
 * We will show you how to take the screen snapshot in later articles.*/
 aex.printStackTrace();
 } catch (Exception ex) {
 /* If exception occured, just print the exception trace. 
 * We will show you how to take the screen snapshot in later articles.*/
 ex.printStackTrace();
 } finally {
 //Close and quit the web browser in the cloud platform.
 driver.quit();
 }

When you execute the code above in your selenium testing automation project, you can check the CBT test status by following steps.

  1. Log into crossbrowsertesting.com .
  2. Click Selenium in the top navigation menu bar. In “Recent Selenium Tests” area of the page, you will see all of the selenium testing execution status.
    how to check crossbrowsertesting selenium test status
  3. When the selenium testing finished,  you can click the Detail button to see the detail information about the selenium test.
    click detail button to see the selenium testing detail information
  4. Click Detail button to go to this selenium testing detail information page.
    the detail information about the selenium testing processIn above picture you can see all the capabilities you had set in java code above. You can check all the capabilities you can set in Selenium capabilities page.
READ :   WebDriver Event Listener : Take Screenshot On Exception

Download “TestCBTCloud.zip” TestCBTCloud.zip – Downloaded 53 times – 1 KB

(Visited 445 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.