简体   繁体   English

使用不同的驱动程序Java Eclipse运行测试

[英]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. 基本上,您可以在运行junit类时将FirefoxDriver或Chromedriver作为运行时自定义参数传递。 Ex : -Ddriverclass="FirefoxDriver". 例如:-Ddriverclass =“ FirefoxDriver”。 In doingsmth you can get the driver value by System.getProperty("driverclass"). 这样做可以通过System.getProperty(“ driverclass”)获得驱动程序值。

How to pass the -D System properties while testing on Eclipse? 在Eclipse上进行测试时如何传递-D系统属性?

Pass command line arguments to JUnit test case being run programmatically 将命令行参数传递给以编程方式运行的JUnit测试用例

Either one of these: 这些之一:

You can use the Parameterized runner, more here https://github.com/junit-team/junit/wiki/Parameterized-tests 您可以使用Parameterized运行器,更多信息请参见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 如果您熟悉Guice,那么我会将Jukito与@All结合使用,更多https://github.com/ArcBees/Jukito/wiki/@All

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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