java - Repeat entire test class in TestNG, with different parameters -
i have code testing site selenium webdriver. there 4 @test
methods, , @dataprovider
3 values. so, in total twelve tests run.
public class sometest { webdriver driver; @dataprovider(name = "urls") public object[][] createdata1() { return new object[][] { {"url 1"}, {"url 2"}, {"url 3"}}; } @beforemethod //right i'm setting weddriver chrome, //i'll need run test firefox, chrome, , ie public void setupwebdriver(){ driver = webdrivers.getchromedriver(); } @aftermethod public void closewebdriver(){ driver.quit(); } //test methods below @test(dataprovider = "urls") public void test1(string url){ //test 1 url } @test(dataprovider = "urls") public void test2(string url){ //test 2 url } @test(dataprovider = "urls") public void test3(string url){ //test 3 url } @test(dataprovider = "urls") public void test4(string url){ //test 4 url } }
right now, these tests running under chrome. want repeat of these tests, of data provider variations, on firefox , internet explorer. how can entire class of tests repeat these other webdrivers? it's need @dataprovider
entire class (for beforemethod).
you should use @factory.
public class sometest { @factory public object[] createinstances() { object[] result = new object[]{ new sometest(webdrivers.getchromedriver()) // can add other drivers here }; return result; } private final webdriver driver; public sometest(webdriver driver) { this.driver = driver } @dataprovider(name = "urls") public object[][] createdata1() { return new object[][] { {"url 1"}, {"url 2"}, {"url 3"}}; } @afterclass public void closewebdriver(){ driver.quit(); } //test methods below @test(dataprovider = "urls") public void test1(string url){ //test 1 url } @test(dataprovider = "urls") public void test2(string url){ //test 2 url } @test(dataprovider = "urls") public void test3(string url){ //test 3 url } @test(dataprovider = "urls") public void test4(string url){ //test 4 url } }
Comments
Post a Comment