When you are running your Selenium scripts in multiple browsers or in mobile devices, you might be facing lot challenges in installing browsers or connecting to specific mobile devices and sparing lot of time around this.
BrowserStack is proprietary tool which supports us to run our selenium scripts in various browsers(Chrome, IE, Firefox, Safari) which also supports lots of browser version in various operating systems.
It also supports Android and IOS mobile devices to execute scripts in Native and Hybrid applications.
BrowserStack works on RemoteWebDriver and with Browser/Device DesiredCapabilities options.
Following is the code snippet to run simple script
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class BrowserStackScript {
public static final String USERNAME = "UserName";
public static final String AUTOMATE_KEY = "XXXXX";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
//below code is to run on web browsers on any computer devices(not in mobile devices) through browserstack
public static void main(String[] args) throws Exception {
// To execute scripts through remote server or grid on mulitple browsers, we need to set capabilities of platform, version etc., to run the scripts
DesiredCapabilities capability = new DesiredCapabilities();
capability.setPlatform(Platform.WIN8);
capability.setBrowserName("Chrome");
capability.setVersion("70");
capability.setCapability("browserstack.debug", "true");
// Creatng URL object
URL browserStackUrl = new URL(URL);
// Create object of driver. We execute scripts remotely. So we use RemoteWebDriver
//There are many constructors to remotewebdriver
//To pass URL object and Capabilities object, use the below mentioned constructor
//RemoteWebDriver(URL remoteAddress, Capabilities desiredCapabilities)
WebDriver driver = new RemoteWebDriver (browserStackUrl, capability);
//Implicit wait for 30 seconds
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// to open url
driver.get("http://easy2autotest.blogspot.com/");
WebElement element = driver.findElement(By.xpath("//a[contains(text(),'2018')]"));
element.click();
Thread.sleep(4000);
driver.findElement(By.xpath("//h3[@class='post-title entry-title']//a[contains(text(),'Micro Focus UFT certification exam details')]")).click();
Thread.sleep(4000);
System.out.println(driver.getTitle());
driver.quit();
}
}
// below code is to run on mobile devices
// public static void main(String[] args) throws Exception {
//
// DesiredCapabilities caps = new DesiredCapabilities();
// caps.setCapability("browserName", "iPhone");
// caps.setCapability("device", "iPhone 8 Plus");
// caps.setCapability("realMobile", "true");
// caps.setCapability("os_version", "11");
// caps.setCapability("name", "Bstack-[Java] Sample Test");
//
// WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
// driver.get("http://www.google.com");
// WebElement element = driver.findElement(By.name("q"));
//
// element.sendKeys("BrowserStack");
// element.submit();
//
// System.out.println(driver.getTitle());
// driver.quit();
// }
BrowserStack is proprietary tool which supports us to run our selenium scripts in various browsers(Chrome, IE, Firefox, Safari) which also supports lots of browser version in various operating systems.
It also supports Android and IOS mobile devices to execute scripts in Native and Hybrid applications.
BrowserStack works on RemoteWebDriver and with Browser/Device DesiredCapabilities options.
Following is the code snippet to run simple script
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class BrowserStackScript {
public static final String USERNAME = "UserName";
public static final String AUTOMATE_KEY = "XXXXX";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
//below code is to run on web browsers on any computer devices(not in mobile devices) through browserstack
public static void main(String[] args) throws Exception {
// To execute scripts through remote server or grid on mulitple browsers, we need to set capabilities of platform, version etc., to run the scripts
DesiredCapabilities capability = new DesiredCapabilities();
capability.setPlatform(Platform.WIN8);
capability.setBrowserName("Chrome");
capability.setVersion("70");
capability.setCapability("browserstack.debug", "true");
// Creatng URL object
URL browserStackUrl = new URL(URL);
// Create object of driver. We execute scripts remotely. So we use RemoteWebDriver
//There are many constructors to remotewebdriver
//To pass URL object and Capabilities object, use the below mentioned constructor
//RemoteWebDriver(URL remoteAddress, Capabilities desiredCapabilities)
WebDriver driver = new RemoteWebDriver (browserStackUrl, capability);
//Implicit wait for 30 seconds
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// to open url
driver.get("http://easy2autotest.blogspot.com/");
WebElement element = driver.findElement(By.xpath("//a[contains(text(),'2018')]"));
element.click();
Thread.sleep(4000);
driver.findElement(By.xpath("//h3[@class='post-title entry-title']//a[contains(text(),'Micro Focus UFT certification exam details')]")).click();
Thread.sleep(4000);
System.out.println(driver.getTitle());
driver.quit();
}
}
// below code is to run on mobile devices
// public static void main(String[] args) throws Exception {
//
// DesiredCapabilities caps = new DesiredCapabilities();
// caps.setCapability("browserName", "iPhone");
// caps.setCapability("device", "iPhone 8 Plus");
// caps.setCapability("realMobile", "true");
// caps.setCapability("os_version", "11");
// caps.setCapability("name", "Bstack-[Java] Sample Test");
//
// WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
// driver.get("http://www.google.com");
// WebElement element = driver.findElement(By.name("q"));
//
// element.sendKeys("BrowserStack");
// element.submit();
//
// System.out.println(driver.getTitle());
// driver.quit();
// }
Thanks for sharing!! That's a really interesting article on automation testing.
ReplyDeleteDevOps Training in Bangalore | Certification | Online Training Course institute | DevOps Training in Hyderabad | Certification | Online Training Course institute | DevOps Training in Coimbatore | Certification | Online Training Course institute | DevOps Online Training | Certification | Devops Training Online
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.Really the post is very unique.every concepts are captured nice.
ReplyDeleteoracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
oracle online training
hadoop training in chennai
hadoop training in bangalore