Friday 26 July 2013

Sauce Labs With Selenium Webdriver



Overview

Ø  Sauce on Demand is a cloud-based service that allows you to run 
automated cross- browser functional tests at high speeds in parallel, 
so you   don’t need to maintain testing infrastructure.

Ø  Easy-to-use tools let you build both manual and automated tests 
that produce media-rich results, including screen shots and videos 
of bugs that can be added to any bug tracking system.

Ø  Sauce Support 65+browser and OS combination.

Ø  Operating Systems like Windows, Linux, Mac,

Ø  Browsers like Internet Explorer, Chrome, Firefox, Safari, Opera,
 I Phone, IPod, Android.

Ø  All latest browsers versions are available.

Ø  It has commercial support for selenium.

SAUCE CONNECT

Ø  Sauce Connect securely proxies browser traffic between Sauce 
Labscloud-based 
VMs and your local servers. Connect uses ports 443 and 80for communication
 with Sauces cloud.

Ø  Sauce Connect helps to do HTML Layout Testing.

Ø  This can be used by both Front End designers and Testers for performing manual compatibility testing.

Configure Sauce Connect

Ø   First we need to register in https://saucelabs.com/ website.

Ø  Download Sauce Connect.jar file from the Sauce labs site.

Ø  Run the Jar as below 
java -jar Sauce-Connect.jar YOUR-SAUCE-USERNAME(sivaprasadk) 
YOUR- SAUCE-API-KEY(d75aaba0-ed9c-4ec8-aa35-17c5ed17b402)

Ø  Login to the Sauce Labs web site using valid user credentials.( Here I have given my        credentials mentioned in previous point)

Ø  Select “New Interactive Session”
Ø  Browse the url`s (we can use the localhost url`s as well).

Screenshot of configured sauce Connect:

 Example Script for Sauce:

package sample;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;

public class Test2 {
private WebDriver driver;
@Test

public void setUp() throws Exception {
  DesiredCapabilities capabilities = DesiredCapabilities.firefox();
  capabilities.setCapability("version", "5");
  capabilities.setCapability("platform", Platform.windows);

  this.driver = new RemoteWebDriver(new URL
("http://sivaprasadk:d75aaba0-ed9c-4ec8-aa35-17c5ed17b402@ondemand.saucelabs.com:80/wd/hub"),
                capabilities);
    }

   
@Test
    public void Login_Paytm() throws Exception {
   
driver.get("https://www.paytm.com/");
driver.findElement(By.cssSelector("span")).click();
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("9880070959");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("Proceed")).click();
driver.findElement(By.id("opns")).click();
driver.findElement(By.id("loggedout")).click();
driver.quit();
}}

 Integration of Web driver and Sauce Services Sauce support Web 
driver scripts and can compatible with multiple programming languages 
like Java, Python, NodeJs, Perl. Here,

We are using java language for Integration and Functional Test Automation 
    (Selenium2 with java bindings).

Steps to Follow:

Ø    A Java File is written, which will take browsers Name, OS and browser 
    version as run time arguments.

Ø   The Script reads the inputs and invokes the Sauce browser with the given
    OS and browser combination in Sauce Cloud.

Ø   On invoking the Selenium functional script the tests will get executed in
    the Sauce Cloud.

Ø   Here we used HtmlTestRunner(unit test module for python) for maintaining
    test suite.

Ø   The test results can be captured from Sauce or from Html Test Report 
    (which will be generated using HtmlTestRunner).

 Dashboard – Sauce

    Like below we can find the results after completing test scripts.



Features of Sauce Cloud:

·       Developer Tools in Every Browser
·       Selenium RC & WebDriver Compatible
·       Video Recordings of Every Test
·       Test Local and Firewalled Servers
·       Any Programming Language
·       Browsers and Mobile Emulators

Advantages:

·       Easy to Integrate with Continuous Integration and Selenium2 test scripts.
·       Able to run the Parallel functional tests, which helps to optimize the 
    test execution Time.
·       Supports multiple browsers and OS combination including mobile browsers.
·       By using this approach, we can perform Functional, Layout, Compatibility 
    testing.
·       Sauce, in built support of Video recording and Screenshot capturing is very
    helpful and good.
·       Availability of updated Browsers and Versions.
·       Secure Tunnel system.

Dis Advantages:

·       Issues with Corporate Proxy environment.
·       As this tool works over cloud script runs very slowly.

References:

    http://saucelabs.com/features 

1 comment: