Tuesday, 23 January 2018

How to scroll browser in Selenium


Hello friends,

In this article we will discuss that how to perform scroll operation in selenium.

For Video :- Click Here



Watch Video for more Understanding





While automating an application we generally found that we need to perform here scroll Up or scroll down or Scroll up to an element, So in this demo we will learn that how to perform these all operations.

In selenium, we have JavascriptExecutor interface, to perform the scroll operation, which provide us a method "executeScript".

1). How to Scroll up :
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,-500)", "");

2). How to Scroll Down :
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0, 500)", "");

3). How to Scroll Up to an element :
WebElement webelement = driver.findElement(By.xpath("xpath of your elements"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView(true);", webelement);

4). How to Scroll up to bottom of webpage:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,document.body.scrollHeight)");

Below is the example that how to perform the above three operation in some realtime application :

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Scroll_demo
{
WebDriver driver;
@BeforeTest
public void navigate() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\ChromeDriver\\chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("http://www.way2testing.com");
Thread.sleep(3000);
}
@Test
public void scrollTest()
{
WebElement link = driver.findElement(By.xpath(".//*[@id='post-body-751561208295527719']/div[1]/div[4]/div/table/tbody/tr[1]/td[1]/a"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
//jse.executeScript("window.scrollBy(0,500)", "");
jse.executeScript("arguments[0].scrollIntoView(true);", link);
link.click();
}
}

Thanks :)

How to scroll in Appium: click here

Wednesday, 3 January 2018

Cucumber Tutorials for Beginners



Hello friends,

In this article we will learn, what is Behavior Driven Development framework and Cucumber from beginner to advance level. BDD : Behavior-driven development is a software development process which is extension of TDD(Test Driven Development)
(in TDD we just write our code we write the test cases and run test cases & report the failed cases to get fix.)
It is used to test the system rather than testing the particular piece of code.
BDD focuses on behavior and not tests.
BDD defines application behavior using simple English text, defined by a language called Gherkin.
Behavior Driven Development gives us an opportunity to create test scripts from both the developer's and customer's prospective as well.

Features of BDD :
0). Extends Test Driven Development(TDD) by utilizing natural language that non technical stakeholder can understand.
1). Shifting from thinking in "tests" to thinking in "behaviour"
2). Common language, it is easy to describe.
3). Collaboration between business stakeholder, Business Analysts, QA Team and develops.
4). Driven by Business value.

Introduction of Cucumber :
What is Cucumber :
Cucumber is a testing framework which supports Behavior Driven Development(BDD). It lets us define application behavior in plain meaningful English text using a simple grammar defined by a language called Gherkins.
Feature file :
The file, in which Cucumber tests are written, is known as feature files.
The extension of the feature file needs to be ".feature".
One can create as many feature files as needed. To have an organized structure, each feature should have one feature file.

For Example : user-login.feature
A feature file is an entry point to the Cucumber tests. This is a file where you will describe your tests in Descriptive language(Like English). It is an essential part of Cucumber, as it serves as an automation test script as well as live documents. A feature file can contains a scenario or can contain many scenarios in a single feature file.