java - How do run each browserdriver based on enum list value? -
hi using code found in first answer on page: click here
i able run , choose browser changing environment used_driver line number of different browsers.
i wandering if possible run test runs through each case once before finishing, i.e. has been tested on each of selected browsers once have had go @ using for, , if havnt been successful. please bare me new java , oo. thanks.
example test
driver.get("calc.php"); driver.findelement(by.name("firstnumber")).sendkeys("2"); thread.sleep(500); driver.findelement(by.name("secondnumber")).sendkeys("2"); thread.sleep(500); driver.findelement(by.name("calculate")).click(); thread.sleep(500); driver.findelement(by.name("save")).click(); thread.sleep(500);
i believe asking run single test multiple times, once each browser.
there different ways can this...i'll start simplest (but hardest maintain in future, make sure understand each choice before choosing):
solution 1: simplest way put loop around test. have list of different webdrivers tests run on. this:
webdriver[] drivers = new webdriver[]{firefoxdriver, chromedriver}; (webdriver driver:drivers){ ...test goes here..... }
the problem method each test run have have loop, , create own drivers.
solution 2: have central method call each of tests. this:
public void runtests(){ ...create drivers here (and array)... (webdriver driver: drivers){ runfirsttest(driver); runsecondtest(driver); } } public void runfirsttest(driver){ ...code using driver goes here.... }
this solves problem of having loop , creating driver instances in every test, now, whenever write new test, have add loop.
solution 3: solution exists, using testing framework. 2 popular testng , junit. i'm going assume of tests in same class, if have multiple classes, want have 1 class have @dataprovider
@dataprovider(name = "drivers") public providedrivers(){ ...create drivers here... return new object[][]{{firefoxdriver},{chromedriver},....}; } @test(dataprovider = "drivers") public runtest(webdriver driver){ ...do stuff driver here... }
this solution run every method has @test(dataprovider = "...") once every driver pass in. more information here
if have questions, feel free comment. respond.
Comments
Post a Comment