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

Islamic Terms

A Adhan (أذان) The call to prayer. Adhan (أذان) The call to prayer. Ahadith (أحاديث) [sing. Hadith (حديث)] The sayings and traditions of the Holy Prophet Muhammad (Peace be upon him). Ahkam (أحكام) Rulings and orders derived from the Qu’ran and Sunnah. Five kinds of orders: Wajib, Mustahab, Mubah, Makruh, and Haram. Ahl al-Kitab (أهل الكتاب) “People of the Scripture”, or followers of pre-Islamic monotheistic religions with some form of scripture believed to be of divine origin. It refers to Jews, Christians and Sabians. Akhirah (آخرة) Hereafter. `Alayhi As-Salaam (عليه السلام) “Peace be upon him.” This expression follows after naming a prophet (other than Muhammad), or one of the noble Angels (i.e. Jibreel (Gabriel), Mikaeel (Michael), etc.) AlhamdulilLah (الحمد لله) “Praise be to God!” Allah (الله) God; the only deity worthy of worship. It derives from the word “Ilah” which means “the One deserving all worship”, the One to whom all hearts s...

Sabhyata Dwar- Patna Zoo and Patna Gate- Bihar India

We wanted to celebrate 1st year 2021, So, decided to go to Sabhyata dwar and to Patna Zoo. Sabhyata dwar is situated at Gandhi maidaan, you can reach to Golgarh too and there is Gandhi museum is also there. Sabhyata dwar is newly built buildings and in the wall of Sabhyata dwar, four great man Budhhda, Mahavir, Ashoka and Megasthenese words are written. showing the great cultures of Bihar. Its completely free to visit this place. For Patna Zoo, Adult ticket price is 100 and child price is 50 rupees. but in normal days, price fare is very low compare to special days. Very very nice place to visit, outside you can have street foods variety. Some Pics of Patna Zoo. Nice place to visit in patna. Visit time is early in the morning, So you can travel all of the Zoo. Hindi: हम 1 जनवरी 2021 को मनाना चाहते थे, इसलिए सबयता द्वार और पटना चिड़ियाघर जाने का फैसला किया। सबयाता द्वार गांधी मैदान में स्थित है, आप गोलगढ़ भी पहुँच सकते हैं और वहाँ गांधी संग्रहालय भी है। सबयाता द्वार नवनिर्मित इमारतें है...

The Meanings of Shema-- Jewish concepts

“Hear, O Israel, the Lord is our G-d, the Lord is one.” These words are the supreme testimony of Jewish faith. Each word is worthy of careful study, but it is the first – the verb  Shema  – that deserves special attention. There was a profound difference between the two civilizations of antiquity that between them shaped the culture of the West: ancient Greece and ancient Israel. The Greeks were the supreme masters of the visual arts: art, sculpture, architecture and the theatre. Jews, as a matter of profound religious principle, were not. G-d, the sole object of worship, is invisible. He transcends nature. He created the universe and is therefore beyond the universe. He cannot be seen. He reveals Himself only in speech. Therefore the supreme religious act in Judaism is to listen . Ancient Greece was a culture of the eye; ancient Israel a culture of the ear. The Greeks worshipped what they saw; Israel worshipped what they heard. This is how Hans Kohn put it in his...