About - Selenium

Definition

Development and Versions

Pre-requisites

Languages supported

Manual vs Automation

Choosing Selenium

Selenium - Components

Selenium IDE

Selenium RC

Selenium WebDriver

Selenium Grid

QTP

Selenium vs QTP

Selenium - IDE

Features

Install and configure

Selenium - Webdriver

About WebDriver

install and configure

First test case

Web element

Element Locators

Example of locators

Chropath

Web driver commands

Eclipse and TestNG

About Eclipse

Choose and download

About TestNG

Testng installation on eclipse

Testng Annotations

Pass Fail and Skip test cases

Run test cases in batch

testng.xml - Explanation

testng grouping

Running tests parallely

dependsOnMethods

dependsOnGroups

Prioritization

Passing parameters

Data providers

Read data from excel

Ant - XSLT reports

Testng listeners

Cross browser testing

Page Object Model



TestNG Annotations
 


6) Annotation means a name that tells or describes what should be the following method that is after annotation name does or indicates. It starts with the symbol @, followed after annotation name.

Eg: @test

This annotation says the following code is a test case in TestNG.

7) IN this part, we will see how a test is performed with TestNG in eclipse.

a) Create a Java Project in eclipse through File-> New->Java Project.

b) Create a package com.testngdemo under the src file.

c) Create a class "TestNGDemo1.Java" class



d) Right click on TestNGDemo1.java and click on "Run As" . You will see TestNG Test.



e) See the data on the console with test cases fail or pass. Our case as follows in the picture.
Default test Tests run: 1, Failures: 0, Skips: 0



8) There are lots of good and useful annotations in TestNG.

i. @Test

ii. @BeforeMethod

iii. @AfterMethod

iv. @BeforeClass

v. @AfterClass

vi. @DataProvider

vii. @BeforeTest

viii. @AfterTest

ix. @BeforeSuite

x. @AfterSuite

xi. @BeforeGroups

xii. @AfterGroups

xiii. @Factory

xiv. @Listeners

xv. @Parameters

a)



b)



@Test

It is used to mark or define a class or method as a test .Generally if it is marked for method then the method defines test case functionality. If it is marked for class,????

package com.testngdemo;

import org.testng.annotations.Test;

public class TestNGDemo1 {

@Test
public void test1(){

System.out.println("Inside test case 1");

}

}



package com.testngdemo;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class LoginFunctionality {

@BeforeClass
public void startBrowser(){

System.out.println("Start bowser");
}

@BeforeMethod
public void befoerLogin(){

System.out.println("User enters the login data");

}

@Test
public void userLogin(){

System.out.println("User Successfully logged in");

}

@AfterMethod
public void afterLogin(){

System.out.println("Logged out to User account");

}

@AfterClass
public void stopBrowser(){

System.out.println("Stop browser");

}

@BeforeTest
public void beforeTest() {

System.out.println("in beforeTest");

}

@AfterTest
public void afterTest() {

System.out.println("in afterTest");

}

@BeforeSuite
public void beforeSuite() {

System.out.println("in beforeSuite");

}

@AfterSuite
public void afterSuite() {

System.out.println("in afterSuite");

}



}

The output can be verified as below:

in beforeSuite
in beforeTest
Start bowser
User enters the login data
User successfully logged in
Logged out to User account
Stop browser
in afterTest
PASSED: userLogin
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
in afterSuite
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
Analysis of the output:

1) @Test is executred only once because is the only Test case annotated with @Test. So here we got "User Successfully logged in" only once.

2) @BeforeMethod and @AfterMethod execute only once but before and after @Test . So we got these output data surrounding "User Successfully logged in" as follows in the console.

User enters the login data
User successfully logged in
Logged out to User account


3) @BeforeClass executed only once but before @Test and before @ BeforeMethod. @AfterClass executed only once but after @Test and @AfterMethod. So we got these output data surrounding "User Successfully logged in" as follows in the console. Observe Start browser and stop browser as follows. These two annotations indicate class level markings.


Start bowser
User enters the login data
User successfully logged in
Logged out to User account
Stop browser


4) @BeforeTest executed only once but before @Test and before @ BeforeMethod and @BeforeClass. @AfterTest executed only once but after @Test, after @AfterMethod and after @AfterClass. So we got these output data as follows.
These two annotations indicate Test level markings.

in beforeTest
Start bowser
User enters the login data
User successfully logged in
Logged out to User account
Stop browser
in afterTest
PASSED: userLogin


5) @BeforeSuite executed only once but before @Test and before @ BeforeMethod and @BeforeClass and @BeforeTest. @AfterSuite executed only once but after @Test, after @AfterMethod and after @AfterClass and after @AfterTest. So we got these output data as follows.
These two annotations indicate Test level markings.

in beforeSuite
in beforeTest
Start bowser
User enters the login data
User successfully logged in
Logged out to User account
Stop browser
in afterTest
PASSED: userLogin

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================

in afterSuite

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0

Rest all annotations will be discussed in later part of tutorial


I conduct online tutions on Manual Testing, Selenium and the following. For more details contact anandaibmindia@gmail.com
Manual Testing - 1600/-           Selenium - 1600/-
           Jsp and Servlet -2000/-           Java training - 2000/-