硒中的并行测试-使用命令行的Cucumber Maven框架

时间:2018-09-13 03:48:22

标签: java maven cucumber-junit selenium3

我正在使用带有Junit的硒黄瓜Maven框架。我需要并行运行测试。我需要的是同时在Chrome和Firefox中运行功能文件。我已经搜索了很多天,只得到TestNG的解决方案。我该如何实现?谁能帮我解决这个问题?我的TestRunnerTest.java文件如下:

package 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");
// System.out.println(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().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();
 }
}

我的baseDefinition如下:

public class baseDefinition {
public Boolean beforsuit=true;
public String baseurl = "https://click2rail-dev.cloudiumedge.com";
private static TestRunnerTest runner_TestObj = TestRunnerTest.getInstance();
public  WebDriver driver = runner_TestObj.driver;   
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new 
Date());
}

现在,我需要同时在多个浏览器(Chrome,Firefox,IE)中运行测试。我需要在TestRunner.java文件和baseDefinition文件中进行哪些更改?如果您是我的初学者,那么如果您能帮助我提供解决方案将非常有帮助。我已经搜索了很多次..但是我正在用TestNG获得解决方案。

0 个答案:

没有答案