我正在使用带有Junit的硒黄瓜Maven框架。我需要并行运行测试。我需要的是同时在Chrome和Firefox中运行功能文件。 下面是TestRunner文件:
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/"
, glue= {"stepDefinition"}
, plugin = { "com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"},
monochrome = true
public class TestRunnerTest {
public static WebDriver driver;
public static String timeStamp = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a").format(new Date());
public static String browserName;
private static TestRunnerTest sharedInstance = new TestRunnerTest();
private TestRunnerTest() { }
public static TestRunnerTest getInstance() {
return sharedInstance;
}
@BeforeClass
public static void before() {
browserName = System.getProperty("browserName");
if(browserName==null)
{
browserName= "chrome";
}
if (browserName.equalsIgnoreCase("Chrome"))
{
System.setProperty("webdriver.chrome.driver", "E:\\ChromeDriverNew\\chromedriver.exe");
driver=new ChromeDriver();
}
else if (browserName.equalsIgnoreCase("Firefox"))
{
System.setProperty("webdriver.gecko.driver","E:\\geckoNew\\geckodriver.exe");
driver = new FirefoxDriver();
}
else {
System.out.println("Error Message----> "
+ "browser name not mentioned properly");
System.exit(0);
}
driver.manage().window().maximize();
// driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@AfterClass
public static void after() {
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
{
try {
Reporter.loadXMLConfig(new File("config/report.xml"));
// Reporter.setSystemInfo("os", "Windows");
// Reporter.addScreenCaptureFromPath("ScreenShot/screenshot.png");
Files.move(Paths.get("target/cucumber-reports"), Paths.get("target/cucumber-reports_ "+
LocalDateTime.now().format(DateTimeFormatter.ofPattern("L-d-YYYY h-m-s")) + "_" + browserName),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
});
if(driver!=null)
driver.quit();
}
}
我一直在寻找解决方案,但已找到TestNG的解决方案。如果你们帮助我提供解决方案,那就太好了。