Tuesday 26 November 2019

Running Selenium script in BrowserStack + Cross Browser testing

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();
//   }

Tuesday 12 November 2019

Jenkins Vs TeamCity tools comparision

Jenkins and Teamcity tools are powerful continuous integration tools. Each tool has it's own features available to support Continuous integration  process.

Please refer following few features we have compared.


Jenkins is good tool when you going for end to end integration in enterprise level as it has more support to integrate 3rd party tools whereas Teamcity is good when you have lesser team working on with specified technology like Microsoft based applications.