September 25, 2020

How to Implement BrowserStack in Selenium

BrowserStack is a necessary supporter of Selenium, resulting from it automating testing and making that tests run within the cloud. It is exceptionally straightforward and victimization BrowserStack. It tends to do Cross Browser Testing victimization in Selenium.

BrowserStack provides instant access to real Android & iOS devices for testing that conjointly supports multiple operating systems like Windows and macOS. A broad vary of debugging tools performs to troubleshoot tests instantly for more selenium training.

How does one implement BrowserStack Automate?

Log in to BrowserStack and navigate to the modified page.

In the high left corner, click on the 'Show +' button to retrieve your Username and Access Keys.

Before proceeding to the ensuing steps

It is essential to understand. 

In Selenium, the design base will be 'Hubs 'and 'Nodes. 

The Hub is that the central purpose, which will receive all the requests and knowledge on that browser, platform, and device the check ought, will distribute them to the registered nodes. 

Nodes area unit the corresponding tests can run. Every node may be a machine, a truly mobile device that registers with the Hub.

once we write a node, the Hub has the node's data. 

It will show the browser and configuration details of the nodes.The conditions needed to line up the BrowserStack area unit, the Capabilities object, and Remote WebDriver. 

Remote WebDriver is employed to hit the BrowserStack API when the capability objects facilitate the test's specific property and platform.

Based on the desired capabilities instance, the Hub can aim the tests to a node that matches the preference sets.

Here may be a sample code snip in Java that sets the aptitude to the purpose of the desired node to the individual Hub:

final String USERNAME = "";final String AUTOMATEKEY = ""; final String URL = "https://" + USERNAME + ":" + AUTOMATEKEY + "@hub-cloud.browserstack.com/wd/hub"; try {   DesiredCapabilities caps = new DesiredCapabilities();   caps.setCapability("browser",browser);   caps.setCapability("browser_vversion",browserrsion);   caps.setCapability("os",os);   caps.setCapability("os_verversion",osion);   caps.setCapability("resolution",resolution);   caps.setCapability("project","Project-1");   caps.setCapability("build","1.0");   caps.setCapability("browserstack.debug","true");   caps.setCapability(CapabilityType.ACCEPTSSLCSSL true);   driver = new RemoteWebDriver(new URL(URL),caps); } catch(MalformedURLException e) {   e.getMessage(); }<?xml version=”1.0″ encoding=”UTF-8″?><!DOCTYPE suite SYSTEM “https://testng.org/testng-1.0.dtd”><suite thread-count=”3″ name=”Suite” parallel=”tests”><test name=”Test on Chrome”>  <parameter name=”browser” value=”Chrome”/>  <parameter name=”browserversion” value=”43.0″/>  <parameter name=”os” value=”Windows”/>  <parameter name=”osversion” value=”7″/>  <parameter name=”resolution” value=”1024×768″/>  <classes>    <class name=”BrowserStack.ExecuteFunctionalities”/>  </classes></test> <!– Test –><test name=”Test on Edge”>  <parameter name=”browser” value=”Edge”/>  <parameter name=”browser_vversion” value=”13.0″/>  <parameter name=”os” value=”Windows”/>  <parameter name=”osrsion” value=”10″/>  <parameter name=”resolution” value=”1024×768″/>  <classes>    <class name=”BrowserStack.ExecuteFunctionalities”/>  </classes></test> <!– Test –><test name=”Test on Firefox”>  <parameter name=”browser” value=”Firefox”/>  <parameter name=”browser_verversion” value=”44.0″/>  <parameter name=”os” value=”Windows”/>  <parameter name=”osion” value=”10″/>  <parameter name=”resolution” value=”1024×768″/>  <classes>    <class name=”BrowserStack.ExecuteFunctionalities”/>  </classes></test> <!– Test –></suite> <!– Suite –>

What are the Desired Capabilities in Selenium?

Desired Capabilities has a collection of code-value pairs that encode as a JSON object.

It helps QA's outline primarily take a look at needs like operational systems, browser mixtures, and browser versions.

This category has multiple ways that permit QAs to specify the specified properties relating to the specified take a look at environments.

Each specific action at law has to execute in an exceedingly different setting as per the market trends.

A QA may get to take a look at a Web-application on two different browsers (Chrome, Safari) put in on mobile devices running on totally different operating systems (Android, iOS).

Desired capabilities, allows QA’s to instruct the Selenium online training about the setting to use.

QAs will perform parallel tests on desired devices, browsers, and operational systems that harm Selenium's set capabilities technique.

Methods:getCapability();This method helps in retrieving the capabilities of the current system on which the tests will perform.

publicjava.lang.Object getCapability(java.lang.String capabilityName)

setCapability();The setCapability() method uses to declare test environments like device name, operating system name, operating system versions, browser, and browser versions.

Declarations in Java:

setCapability :public void setCapability(java.lang.String capabilityName,boolean value)setCapability :public void setCapability(java.lang.String capabilityName,java.lang.String value)setCapability :public void setCapability(java.lang.String capabilityName,Platform value)setCapability :public void setCapability(java.lang.String key,java.lang.Object value).