场景:用Selenium来做对web的自动化测试通常需要在多个浏览器下测试。本方法可以用来不用启动多次JUNIT来分别对每个浏览器测试。而是只需启动一次就可以依次对每一种浏览器执行一遍case。
方法如下:
修改Junit源码的:
org.junit.runner.JUnitCore 这个类中的:
注释掉这一行,那么JUNIT跑完以后就不会退出,反而会等到你自己写的main方法执行完以后才推出。
@RunWith(Cucumber.class)
@CucumberOptions(
features = "features",
format = { "pretty","html:IE-Reports",
"json:/IE-Reports/cucumber.json",
"junit:/IE-Reports/cucumber.xml"},
tags = {"@all"},
monochrome = true,
dryRun = false,
glue = "demo.java" ---package name.
)
public class RunIEBrowser {
public static void execute()
{
System.setProperty("webdriver.ie.driver", "resources/IEDriverServer.exe");
JUnitCore.main("test.java.runner.browser.RunIEBrowser");
}
}
https://cucumber.io/docs/reference/jvm#running-cucumber