Skip to main content

Data Provider: AUTOMATION TESTING FACTS

=================================================
Data Provide TestNG:

Parameters from Testng.xml can be suite or test level

Parameter from DataProvider can take Method and ITestContext as the parameter.
=============================================================
Test Level TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="TestSuite" thread-count="3" >

<parameter name="author" value="Guru99" />

<parameter name="searchKey" value="India" />

<test name="testGuru">

<parameter name="searchKey" value="UK" />

<classes>

<class name="parameters.ParameterWithTestNGXML">

</class>

</classes>

</test>

</suite>
==================================
Data provider returns a two-dimensional JAVA object to the test method and the test method, will invoke M times in a M*N type of object array. For example, if the DataProvider returns an array of 2*3 objects, the corresponding testcase will be invoked 2 times with 3 parameters each time.
================================
/** Test case to verify google search box
     * @param author
     * @param searchKey
     * @throws InterruptedException
     */

    @Test(dataProvider="SearchProvider")
    public void testMethod(String author,String searchKey) throws InterruptedException{
    {
        WebElement searchText = driver.findElement(By.name("q"));
        //search value in google searchbox
        searchText.sendKeys(searchKey);
        System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
        Thread.sleep(3000);
        String testValue = searchText.getAttribute("value");
        System.out.println(testValue +"::::"+searchKey);
        searchText.clear();
        //Verify if the value in google search box is correct
        Assert.assertTrue(testValue.equalsIgnoreCase(searchKey));
    }
    }
    /**
     * @return Object[][] where first column contains 'author'
     * and second column contains 'searchKey'
     */

    @DataProvider(name="SearchProvider")
    public Object[][] getDataFromDataprovider(){
    return new Object[][]
    {
            { "Guru99", "India" },
            { "Krishna", "UK" },
            { "Bhupesh", "USA" }
        };

    }
==================================================================

Comments

  1. ================

    TestClass ParameterDataproviderWithClassLevel.java

    @Test(dataProvider="SearchProvider",dataProviderClass=DataproviderClass.class)
    public void testMethod(String author,String searchKey) throws InterruptedException{

    WebElement searchText = driver.findElement(By.name("q"));
    //Search text in google text box
    searchText.sendKeys(searchKey);
    System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
    Thread.sleep(3000);
    //get text from search box
    String testValue = searchText.getAttribute("value");
    System.out.println(testValue +"::::"+searchKey);
    searchText.clear();
    //verify if search box has correct value
    Assert.assertTrue(testValue.equalsIgnoreCase(searchKey));
    }
    }
    =================
    DataproviderClass.java

    package parameters;

    import org.testng.annotations.DataProvider;
    public class DataproviderClass {
    @DataProvider(name="SearchProvider")
    public static Object[][] getDataFromDataprovider(){
    return new Object[][] {
    { "Guru99", "India" },
    { "Krishna", "UK" },
    { "Bhupesh", "USA" }
    };
    }}

    ReplyDelete

Post a Comment

Popular posts from this blog

Want to Study: Benefit from Knowledge

Problem every lazy guy facing: i want to study not all the time but sometime. But somehow I got distracted the path which i choose. seriously, how i want to study i actually not learnt yet. some friends said me that, default in your routine and some friends said me your idea is wrong. You wana study then you go to study. after all..i ABDUL m reading in 3rd yr..5th sem..in B.tech..cse..when i thought about these things, i totally confused that how i reached in 3rd yr. but in xam times those type of tensions that if i do not studied then i will sure fail.how in those days i have read.this questions are asking inside me. when i m playing around in the time of reading. firstly  want to study. but i don't sit to study. heartly, i m not studying since the last xam of the 4th sem..its 6:38pm..i m going to study now and now. for god sake. if i do not, then i will meet again to myself in this blog. and i m sure i will found the reasonable answer..... Lets answer now: Lets read these two exa...