简体   繁体   中英

Running test with different drivers java eclipse

I have class Login.

public class Login
{
private WebDriver driver;

@Beforetest
public void SetUp()
{
doingsmth();
//How to do this?
driver = FirefoxDriver or Chromedriver depending on smth.
}

@test
public void loginFirefox_a(){}
@test
public void loginFirefox_b(){}
@test
public void loginFirefox_c(){}
@test
public void loginFirefox_d(){}
@test
public void loginChrome_a(){}
@test
public void loginChrome_b(){}
@test
public void loginChrome_c(){}
@test
public void loginChrome_d(){}
}

I know I somehow can use parametrized, but don't know how to use it (fe how test recognise param name?) Any help will be appreciated.

Basically you can pass FirefoxDriver or Chromedriver as a run time custom parameter while running junit class. Ex : -Ddriverclass="FirefoxDriver". In doingsmth you can get the driver value by System.getProperty("driverclass").

How to pass the -D System properties while testing on Eclipse?

Pass command line arguments to JUnit test case being run programmatically

Either one of these:

You can use the Parameterized runner, more here https://github.com/junit-team/junit/wiki/Parameterized-tests

If you're familiar with Guice I would use Jukito with @All, more https://github.com/ArcBees/Jukito/wiki/@All

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM