Showing posts with label Selenium 3. Show all posts
Showing posts with label Selenium 3. Show all posts

Thursday, 18 April 2019

How to send Cookies from Web(GUI) to Web Service


Cookies: Browser Cookies are also referred as Internet Cookie,Web Cookie or HTTP Cookie. A cookie is a "small piece of data" sent from the website to the user's device while the user is accessing the website.
There are multiple ways these cookies are being used in modern world like authentication, browser state information, storing user personal information like name, address etc., tracking the user activity on web, etc., Different types of cookies satisfy different needs.

In certain cases, one might have to test web services which needs cookies to be passed as part of request. One way to address this, is to combine Web application plus web service test steps. 

Below code snippet would open the web application, capture the cookies stored by the application and pass it to web service using Rest Assured.


public class CookiesToWebServices {
static WebDriver driver;
static String driverPath = "C:/Drivers/chromedriver.exe";

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver",driverPath);
ArrayList cookieList = new ArrayList();

String url = "www.testurl.com/testpath/id";
HashMap headermap = new HashMap<>();
headermap.put("Content-Type", "application/json");
headermap.put(....

HashMap queryParammap = new HashMap<>();
queryParammap.put("id", "12345");
queryParammap.put(....

Friday, 14 September 2018

How to run Chrome & Firefox Webdriver in Headless mode

Headless Browser! What does it mean.? As name suggests, It is a browser without head.i.e., without GUI. 

Headless Browsers are a kind of simulation programs of real browsers, but without GUI. Having said that, these may not be 100% equal to real browsers as they have its own limitations. Here are few popular headless browsers:

  • Headless Chrome
  • Headless Firefox
  • HtmlUnit Driver
  • PhantomJS
  • SlimmerJS

Headless browsers come with its own Pros & Cons.
Pros:

  • Improves the execution speed,in turn increases the performance.
  • Can be executed on Browser-less setups like Servers(without browsers).
  • Useful while scraping the web.
  • Simulate multiple browser versions on a single machine.

Cons:

  • It doesn't mimic the real user.
  • Debugging is quite difficult.

Below snippet would show you, How to make Chrome & Firefox work in Headless mode.

Friday, 7 September 2018

Compare Images in Selenium Test

Visual / UI Validation of web pages across different browsers & devices is very important these days as more and more applications are getting web enabled. And most of the websites are eyeing on 'Responsive Web Design' to create a single website across multiple resolutions.

This type of testing is usually performed manually. However, now you can automate these type of tests to an extent using different image comparison libraries like Thumbnailator, Slenium-Shutterbug, ImageMagick Applitools Eyes etc.

Using these libraries, both Functional Testing & Visual Testing can go hand-in-hand without having to maintain separate set of scripts.
One such example using Image-comparison.jar based on Thumbnailator library is as below:


Steps:


Wednesday, 5 September 2018

Capture Full Screenshot in Selenium using Shutterbug


Selenium with the new upgrade 2.0 to 3.* had changed the way it works in the background. Starting with this upgrade, FirefoxDriver has stopped taking the full screenshot. There are many instances where user needs complete screenshot of the web page.
Many teams have worked on it & provided few open source libraries like AShot, ShutterBug etc.

Below code snippet would enable you to get the full screenshot using ShutterBug java library.

STEPS:


Capture Full Screenshot in Selenium using AShot


Selenium with the new upgrade 2.0 to 3.* had changed the way it works in the background. Starting with this upgrade, FirefoxDriver has stopped taking the full screenshot. There are many instances where user needs complete screenshot of the web page.
Many teams have worked on it & provided few open source libraries like AShot, ShutterBug etc.

Below code snippet would enable you to get the full screenshot using AShot java library.

STEPS:


Wednesday, 25 July 2018

Native App Automation using Appium

In the Mobile world, we see multiple types of apps namely Native App, Hybrid App & the browser based application, Web App. Also, we see multiple types of operating systems like Android, iOS, Windows, Firefox OS etc.

Automated testing of these many variation of apps, is very tricky & difficult task. Not all of them are supported by single automation tool. Having said that, Appium which is built over Selenium webdriver supports most of the OS & apps with different configurations.

In this article, you would know a way to automate the Native App using AndroidDriver.

Prerequisites:

  1. Android SDK is downloaded and installed. (ANDROID_HOME env. variable should be set)
  2. Either Emulator or  Real device (USB debugging enabled) is available.
  3. Appium desktop app or non GUI package is installed. 

Steps:

  1. Create a java project in eclipse 'AppiumMobileTesting'.
  2. Create a class 'TestNativeApp' to add the automation code.
  3. Connect your device(USB debugging enabled), to system's USB port & accept if any confirmation pop ups.

Thursday, 7 December 2017

Selenium Tips and Tricks


Get the DOM Object into View:


At times, few actions are not performed on a DOM object until it is visible in the view-port. Below is the small code snippet to get the DOM object into view using WebDriver's 'JavascriptExecutor' interface. 

WebElement element = driver.findElement(By.id("someId"));
JavascriptExecutor js= (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);",element);

OR

((JavascriptExecutor) driver).executeScript("document.getElementById('text123').scrollIntoView(true);");

Selenium WebDriver Wait Commands:

For any automation scripts to work without any sync issues with application, wait statements are very important. Selenium WebDriver provide different types of Wait conditions to make automation scripts effective.

Below are different types of waits & its usage.

Thursday, 24 November 2016

Visual / UI Test Automation using Selenium and Applitools Eyes

Visual / UI Testing is a methodology for validating the multiple visual aspects of Websites, Mobile apps and Desktop apps across multiple browser, resolution and OS combinations.

Visual / UI Testing is very important these days as more and more applications are getting web enabled. (i.e more of the standalone applications are being converted into websites) & most of the websites are eyeing on 'Responsive Web Design' to create a single website across multiple resolutions.The mobile apps designed for a platform has to support multiple screen resolutions or devices.

This type of testing is usually performed manually. However, now you can automate these type of tests using different automation tools available in the market. One such automation tool is Applitools Eyes which has the advantage of validating visual aspects within the existing Selenium scripts.

Thursday, 27 October 2016

Selenium 3 Impact & Changes

Selenium is out with new stable version - Selenium 3.0.1, and this blog would detail out changes & impact the new version of Selenium brings into automation testing. 

Selenium 3, is believed to have major changes in its implementation & quite a few changes to the existing automation.In Sel-3, the original Selenium Core is being taken off & replaced with the alternative implementation that’s backed by WebDriver. It means, Selenium RC users would run into issues & might need to tweak their scripts to support new implementation. However, for web driver users it is believed to be a simple drop-in upgrade.