“EXECUTE TEST CASES IN Virtual Machine which are not in your control”
A Cloud Service Provider with one of the biggest grids for running Selenium and Appium test cases is Sauce Labs. Multiple operating systems, browsers, mobile emulators, simulators, and even actual devices are supported by Sauce Labs. According to the Sauce Labs Official Website, they support over 800 Different Operating Systems, Browsers, and Emulator and Simulator Combinations.
If you want to Execute your script on Firefox 24 which is Not Available to you. Yet the client is asking you to execute the selenium test cases in different Browser Combinations and different OS Combinations. In this scenario we do not need to buy this infrastructure. Here the concept Cloud-Based Testing arises. Accessing the servers which have the required infrastructure will help Execute our selenium test cases from our local into those Servers. Organizations have gradually begun to migrate to the cloud to overcome the issue of obtaining physical machines and increasing costs.
In this blog we’ll be focusing on Creating an Account and will Run a Sample Test Case in cloud.
Create an account:
Visit the link Sauce Labs and click on “Try it now”
Sign-up using any of the available methods.
You are all set and ready to run your first test.
We will be using the concept of Digital Capabilities. Desired capabilities class is used when test cases are running on Server or on Virtual Machine outside your local PC scope. When we are using cloud computing, running Appium test cases, we provide the Requirements to the Desired Capability class.
Whenever we start running the Selenium or Appium Test Cases, first it will Read and Understand what capabilities a host is expecting to run.
Which OS?
Which browser?
Then it will go and connect to the source labs, and it will check all the versions and will connect where the requirements are Satisfied.
Run a Sample Test Case.
public static final String USERNAME = “JohnDoe”;
public static final String ACCESS_KEY = “xxxxx”;
public static final String URL = “http://” + USERNAME + “:” + ACCESS_KEY + “@ondemand.saucelabs.com:80/wd/hub”;
We are defining a string “URL”. It is for the connection establishment with Sauce Labs
Here the username will be the one you specified. To generate the access key, please follow the steps:
Click on Account Icon
Click on “User Setting”
You can find the access key here.
Next, we need to send the Desired Capabilities with the desired requirement.
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(“platform”, “Windows 7”);
caps.setCapability(“version”, “47.0”);
In this scenario “caps” are the Desired Capabilities which we are Sending to the sauce labs. In response we will get a RemoteWebDriver which will be used to carry out our testing.
public class SauceLabDemo{
public static final String USERNAME = “JohnDoe”;
public static final String ACCESS_KEY = “xxxxx”;
public static final String URL = “http://” + USERNAME + “:” + ACCESS_KEY + “@ondemand.saucelabs.com:80/wd/hub”;
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(“platform”, “Windows 7”);
caps.setCapability(“version”, “47.0”);
WebDriver driver=new RemoteWebDriver(new URL(URL), caps);
driver.get(“https://google.com”);
System.out.println(driver.getTitle());
}
}
To avoid any confusion and error while specifying the desired capabilities, SauceLabs came up with one Tool called Platform Configurator which Generates The Code for desired capabilities based on our preferences.
By opening the link and providing all your capabilities, it will generate the code for you.
After running your test, you can also Monitor Your Test Result.
Steps:
Go to the Sauce Labs
Click on “Dashboard”
Click on “Automatic Test”
You can verify that the test is present
To know more about “Selenium With Sauce Labs” you can visit the link.
Conclusion: Congratulations, You have successfully Created your SauceLabs Account and also Configured your selenium with it. In addition, you have also Tested the report through the dashboard.
Happy Coding!
Leave A Comment