[英]How to run an entire test suite with Selenium & JUnit 5 on different URLs
[英]How tu run junit test suite multiple times with different WebDriver configuration
我正在使用junit在Selenium webdriver的网站上运行测试。 我想要实现的是多次运行相同的测试类,但每次我想更改我的网站登录凭据,以便可以使用不同的访问权限进行测试。 我不知道如何解决这个问题。
我正在使用TestSuite类来指定应该运行哪些测试类,并在TestRunner类中初始化WebDriver
testSuite类:
@RunWith(Suite.class)
@Suite.SuiteClasses({
DhcpReservationTest.class,
})
public class TestSuite {
}
TestRunner类:
public class TestRunner {
/**
* Init web driver
*/
private static WebDriver driver = DriverManager.createDriver(ProjectSettings.Roles.NETADMIN);
/**
* This static method serves for getting instance of web driver for executing tests.
* @return web driver
*/
public static WebDriver getWebDriver() {
return driver;
}
static JUnitCore junitCore;
static Class<?> testClasses;
public static void main(String[] args) {
System.out.println("Running Junit Test Suite.");
junitCore = new JUnitCore();
junitCore.addListener(new CustomExecutionListener());
Result result = junitCore.run(TestSuite.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println("Successful: " + result.wasSuccessful() + " ran " + result.getRunCount() + " tests");
}
}
目标是在每次测试完成时将webdriver从“NETADMIN”初始化为例如“SYSADMIN”等时再更改TestRunner中的权限角色,并再次运行相同的测试套件。
有什么方法可以做到这一点,还是应该以不同的方式处理? 谢谢。
我不擅长Java,但我在C#和Nunit做过类似的事情。 我在父类中拥有所有测试方法。 并且有多个派生类,它们实现了保持差异的方法。
所以你有类似的东西(伪代码):
parentClass{
[Test]
testMethod1(){
login();
//test things
}
[Test]
testMethod2(){
login();
//test other things
}
}
[TestSuite]
subclass1()<<parentClass{
login(){
//do first type of login
}
}
subclass2()<<parentClass{
login(){
//do second type of login
}
}
因此,测试在2个派生类中执行,但它们从父类继承所有测试方法。 可能会有一些我想念的细节,但这是我的方法。
实际上我在派生类中的beforeEach方法中有所区别,但我猜上面的内容非常相似。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.