Hi All,

          Does anyone know if there is any way to provide data to a test
through a class?

Let's suppose we have the following test:

  public void testSiteResponse() {
                webtest("Testing Title - Meta Description - MetaKeyword"){
                config haltonerror: "false", haltonfailure: "false"
                storeResponseCode description:"Storing the Web Response" ,
property:"webstatus"
                verifyProperty description:" Web status should be 200",
name:"webstatus", text:"200",
                {}

        }

   }


and you have in your application database a list with all the web urls. So
what do you want to do is to provide that data to your test. Right now the
only way I have found to do this is using the dataDriven ant task :

  public void testSiteResponse() {
       dataDriven (tableContainer:"urls.xls" {
                webtest("Testing Title - Meta Description - MetaKeyword"){
                config haltonerror: "false", haltonfailure: "false"
                invoke url:"http://$webUrl"; , description:"Go to $webUrl" ,
saveResponse:"false"
                storeResponseCode description:"Storing the Web Response" ,
property:"webstatus"
                verifyProperty description:" Web status should be 200",
name:"webstatus", text:"200",
                {}
}
        }

   }


where urls.xls has a list of the the urls.

the cons of this is that you will need to keep updating the excel sheet. In
this case is not complicated but it would be really great if there is a
class that is in charge of providing the data to your test case. TestNg
already offers this functionality:

http://testng.org/doc/documentation-main.html#parameters-dataproviders


public static class StaticProvider {
  @DataProvider(name = "create")
  public static Object[][] createData() {
    return new Object[][] {
      new Object[] { new Integer(42) }
    }
  }
}

public class MyTest {
  @Test(dataProvider = "create", dataProviderClass = StaticProvider.class)
  public void test(Integer n) {
    // ...
  }
}


the createData() method could be a connection to a database with the logic
you need to create the combinations you need to use based on the same test
logic.


Does anyone know if this is already possible in WebTest? Is there anyway to
provide data to a test associating the provider to a class?


Thanks,

              Hernan

Reply via email to