Posts

Setup TestNG in eclipse for automating test using Selenium Webdriver and Java

Image
TestNG is a testing framework developed in the lines of JUnit and NUnit, however it introduces some new functionalities that make it more powerful and easier to use. TestNG is designed to cover all categories of tests − unit, functional, end-to-end, integration, etc., and it requires JDK 5 or higher. Some of its features are listed down: Annotations.Flexible test configuration.Support for data-driven testing (with @DataProvider).Support for parameters.Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).Default JDK functions for runtime and logging (no dependencies).Dependent methods for application server testing.Annotation in TestNG actually is code snippet which lies just ahead of the method declaration and controls the execution of the method. Annotation starts with @ sign. Below is the example of it:


Install TestNG in Eclipse:
You need to install TestNG plugin in your Eclipse to work with it. Below are the steps: Open Eclipse.Click on the 'Help' menu op…

How To Handle Dynamic Web Table In Selenium WebDriver

Image
In this selenium webdriver post, we will learn how to handle dynamic web table. There might occur some scenarios where every time a page loads with different number of rows and columns or different columns for each row.





For that, we have to put two for loops,
1. first loop will iterate all the rows and
2. second loop inside it will iterate the columns of each row



import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class DynamicTable { WebDriver driver = new FirefoxDriver(); @BeforeTest public void setup() throws Exception { driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("http://only-testing-blog.blogspot.in/2014/05/form.html"); } …

How To Extract Table Data/Read Table Data Using Selenium WebDriver

Image
Following Script will extract table data:

import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class table { WebDriver driver = new FirefoxDriver(); @BeforeTest public void setup() throws Exception { driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.get("http://only-testing-blog.blogspot.in/2013/09/test.html"); } @AfterTest public void tearDown() throws Exception { driver.quit(); } @Test public void print_data(){ //Get number of rows In table. int Row_count = driver.findElements(By.xpath("//*[@id='post-body-6522850981930750493']/div[1]/table/tbody/tr")).size(); System.out.println("Number Of Rows = &q…

Handling Multiple Browser Tabs Using Selenium Webdriver

Image
We can perform a number of actions by combining third party things along with Webdriver, which webdriver is not capable if doing it alone. In this context sharing with you a program of handling multiple tabs. We can make use of Key controls which Robot api of java provides, to handle multiple tabs.








import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Switchbetweenbrowsertab { public static void main(String[] a) throws InterruptedException { // Initialize driver WebDriver driver = new FirefoxDriver(); //Maximize browser window driver.manage().window().maximize(); //Go to URL driver.get("http://www.google.com"); //Set timeout driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Open new tab driver.findElement(By.cssSelector("bod…

Code Resuablity & Maintainablility Using Action Methods in Selenium Webdriver

Image
In this post I'm going to share kind of coding pattern which is very helpful in maintaining our automation code. This post is written insight to help beginners. We'll learn that instead of writing a linear script, we should create action methods (functions) which in general contain actions which we are going to performing on our web software.

Let's say, we have a login functionality in our software and we have to automate it. In that case we'll create a method named login and write the commands like, entering username, password and click login in that method. Now we can use that method wherever we need it in other test cases as well. Benefits of using action methods are:

Code ReusabilityBetter maintainability of code Sharing below a sample script, in which I'm entering data in a web form using action methods:




Feel free to ask queries. Happy Coding :)


@uthor 
Vaneesh Behl vaneesh.behl@gmail.com
http://vaneeshbehl.branded.me/
Image
TECHLISTICSPACE  covers Automation Testing & Tools, Mobile Automation, Selenium Webdriver, Sikuli, Robot Framework, Appium, Java, TestNG, JUNIT, JENKINS, Automation Frameworks etc.

Blog Sections:





















Selenium Essentials - Become Expert in Selenium Webdriver Automation with JAVA

Image
Folks, I thought of sharing Selenium Essentials which you must cover if you want to get expertise in Selenium Automation. It might help beginners and intermediate techies. I have divided the content in to two parts, Basic and Advanced. And I have linked the content to other web links of the blog, and planning to cover all in my future blog posts, and link all the contents periodically. Find below the Selenium Essentials:

Course content is divided into two Parts:
PART 1 - Basic Selenium which teaches you about Selenium IDE – Record and Play, Debug, Verification points and XPATH.
PART 2 - Advanced Selenium using Java which teaches Java/JUnit, Eclipse IDE, Selenium RC, Data Driven Testing, Ajax based application Testing.

1) Automation 1.1 Introduction to Automation 1.2 Test Automation of Web Application

PART I
1) Selenium Overview
2) Introduction to Selenium
3) Selenium IDE Basics
3.1 Getting Started
3.2 Selenium Commands – Selenese


4) Selenium IDE
4.1 Introduction of Selenium IDE 4.2 Insta…