目标:运行时在黄瓜中传递的浏览器并行执行
混乱:不想将Testng与黄瓜一起使用[Testng.xml中的避免参数标签],因为@Before [Cucumber api]和@parameters {testng}会导致每个功能的范围报告单独出现
代码: 在挂钩中,我有:
@之前
public void ScenariosetUp(Scenario scenario) throws Exception {
this.scenario = scenario;
Log.startLog("Start of Test cases ");
**TPBaseSteps.openBrowser();**
}
TPBaseSteps class :
public static WebDriver openBrowser() throws Exception {
String browserName = JsonReader.RetrieveTestDataFromExcel("browserConfig", "Browser");
log.info("Chosen browser is " + browserName);
if (!grid) {
switch (browserName.toLowerCase()) {
case "chrome":
log.info("Launching Browse as : " + browserName);
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
case "firefox":
log.info("Launching Browse as : " + browserName);
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
break;
}
问题:我从Excel传递了一个奇异值,RetrieveTestDataFromExcel读取并传递给下面的代码,但是我想为多个浏览器实现它,所以我有网格设置,所以如果我可以用此方法获取参数,那么我将运行他们平行。
答案 0 :(得分:0)
下面是使用Ruby的方法:
您可以在此处使用cucumber.yml作为控制器。 黄瓜.yml
BROWSERS = IE,Chrome,Firefox
从Hooks访问浏览器
puts ENV['BROWSERS']
希望这会有所帮助。让我知道您是否需要有关此方法的更多信息。
答案 1 :(得分:0)
首先,我们将了解Cucumber的创建是为了克服含糊不清的要求和误解,同时针对项目团队的非技术人员和技术人员,但是如果有人认为Cucumber是一种测试工具,那么我们错了。
数据参数化应从功能文件流到步骤实现方法。因此,Cucumber不会一口气直接提供这种参数化选项。
要实现您的方案,唯一要做的就是遵循标记的钩子。
Feature File :- 3 Scenarios
@Chrome
Scenario: This is First Scenario running on chrome browser
Given this is the first step
When this is the second step
Then this is the third step
@Firefox
Scenario: This is Second Scenario running on firefox browser
Given this is the first step
When this is the second step
Then this is the third step
@IE
Scenario: This is Third Scenario running on ie browser
Given this is the first step
When this is the second step
Then this is the third step
@Before("@Chrome")
public void beforeFirst(){
Log.startLog("Start of Test cases ");
TPBaseSteps.openBrowser("Chrome");
System.out.println("This will run only before the chrome Scenario");
}
@Before("@Firefox")
public void beforeSecond(){
Log.startLog("Start of Test cases ");
TPBaseSteps.openBrowser("firefox");
System.out.println("This will run only before the firefox Scenario");
}
@Before("@IE")
public void beforeThird(){
System.out.println("This will run only before the ie Scenario");
}
TPBaseSteps class :
public static WebDriver openBrowser(String browserName) throws Exception {
log.info("Chosen browser is " + browserName);
if (!grid) {
switch (browserName.toLowerCase()) {
case "chrome":
log.info("Launching Browse as : " + browserName);
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
case "firefox":
log.info("Launching Browse as : " + browserName);
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
break;
或通过Chrome浏览器| FF |将IE作为“方案/方案大纲”中的参数,并在步骤实现方法中获取参数值。但是在这种情况下,打开的浏览器不应在钩子中调用,但根据我的理解,不建议使用。
希望它对您有所帮助。