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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -