Data Driven Testing inward Selenium

Data Driven Testing inwards Selenium

Data Driven Testing using Data Provider

Examples:

1) Read Test information (String type) from excel file as well as perform Data driven Testing for Admin Login Functionality.

2) Read Test information (Integer type) from excel file as well as perform Data driven Testing for Addition Functionality.
-------------------------------------------------------
1) Read Test information (String type) from excel file as well as perform Data driven Testing for Login Functionality.
 

Steps for Admin Login
i) Launch the Browser
ii) Navigate to http://www.gcrit.com/build3/admin/
iii) Enter User name
iv) Enter Password
v) Click "Login" Button
-----------------
Verification Point
Capture URL, as well as compare amongst expected.

Expected = http://www.gcrit.com/build3/admin/index.php
--------------------------------------
Prepare Test information file.
--------------------------------
> Download Excel jounce as well as extract
> Add Excel jounce to Java Project inwards Eclipse
-------------------------------------

Selenium Test Case:

public class DatadrivenTest {
public WebDriver driver;
@Test(dataProvider ="testdata")
public void login(String username, String password){
driver = novel FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/");
driver.findElement(By.name("username")).sendKeys(username);
driver.findElement(By.name("password")).sendKeys(password);
driver.findElement(By.id("tdb1")).click();
Assert.assertEquals("http://www.gcrit.com/build3/admin/index.php", driver.getCurrentUrl());
driver.close();
}
   
@DataProvider(name = "testdata")
public Object [] [] readExcel() throws BiffException, IOException {
File f = novel File("C:/Users/gcreddy/Desktop/Input.xls");
Workbook w = Workbook.getWorkbook(f);
Sheet sec = w.getSheet("Sheet1");
int rows = s.getRows();
int columns = s.getColumns();
//System.out.println(rows);
//System.out.println(columns);

String inputData [] [] = novel String [rows] [columns];
for (int i=0; i<rows; i++){
    for (int j=0; j<columns; j++){
    Cell c = s.getCell(j, i);
    inputData [i][j] = c.getContents();
    System.out.println(inputData[i][j]);
}
}
return inputData;
}
}
-----------------------------------------
2) Read Test information (Integer type) from excel file as well as perform Data driven Testing for Addition Functionality.

public class Datadriven2 {
@Test(dataProvider="testdata")
public void add(String val1, String val2, String val3){
int a = Integer.parseInt(val1);
int b = Integer.parseInt(val2);
int c = Integer.parseInt(val3);
int number = a + b + c;
System.out.println(result);
}
@DataProvider(name="testdata")   
public Object [] [] readExcel() throws BiffException, IOException {
File f = novel File("C:/Users/gcreddy/Desktop/Input.xls");
Workbook w = Workbook.getWorkbook(f);
Sheet sec = w.getSheet("Sheet1");
int rows = s.getRows();
int columns = s.getColumns();
//System.out.println(rows);
//System.out.println(columns);

String inputData [] [] = novel String [rows][columns];
for (int i=0; i<rows; i++){
    for (int j=0; j<columns; j++){
        Cell c = s.getCell(j, i);
        inputData[i][j] = c.getContents();
        //System.out.println(inputData[i][j]);
        }
}
return inputData;   
}
}
------------------------------------------------------------
Difference betwixt Reading String type information as well as Integer type data.

If it is String type information therefore you lot tin role the information equally it is.

If it is Integer type data, convert the information (from String type to Integer type) therefore role the data.
-------------------------
Why nosotros postulate to convert the data?

If you lot read information therefore Computer programme considers the information equally String type data,
In social club to perform mathematical operations therefore nosotros postulate to convert the data.
-----------------------------------------------------------
Assignments

i) After Assert fails therefore unopen the Browser.

ii) Read information from excel (range of records)
----------------------------------------
Assignments

i) Verify "Telephone Number" champaign inwards Customer registration form.

Enter valid inputs for all fields except "Telephone Number" as well as click

Capture mistake message as well as compare amongst expected.

Write exception.
------------------------------------------
Data has iii factors

Type (Alfa bytes, numeric, Alfa-numeric etc...)
Size (10 digits)
Range (25 to xxx Years, xxx to 35 Years ....)
--------------------------------------------------------
ii) Verify Email champaign inwards http://niittrainercentral.com/UserRegistration.aspx form

Check Email format
something@something.something
Or
something@something.something.something
------------------------------------------------------
iii) Verify the Date field(Date of Birth:) inwards client Registration form
----------------------------------------------------------------
Project Automation

Selenium WebDriver + Programming (Java) + Testing Framework(JUnit/TestNG)
Or
Selenium WebDriver + Programming (C#) + Testing Framework(NUnit)
Or
Selenium IDE
Or
Selenium WebDriver + Programming (Java)
------------------------------------------------

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post