【问题标题】:cucumber -Parameterize browser at run time without using Testng or hardcoding data from Feature files Parallelycucumber - 在运行时参数化浏览器,而不使用 Testng 或从特征文件并行硬编码数据
【发布时间】:2019-03-07 00:53:00
【问题描述】:

目标:在黄瓜运行时并行执行浏览器

困惑:不想将 Testng 与 cucumber [Avoiding Parameters tag in Testng.xml] 一起使用,因为 @Before[Cucumber api] 和 @parameters{testng} 会导致每个功能的 Extent 单独报告

代码: 在 Hooks 中我有:

@之前

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 读取并传递到下面的代码,但我想为多个浏览器实现它,我有网格设置,所以如果我可以在这个方法中获取参数,那么我会运行他们并行。

【问题讨论】:

    标签: selenium cross-browser cucumber


    【解决方案1】:

    以下是 Ruby 的方法:

    您可以在此处使用 cucumber.yml 作为控制器。 黄瓜.yml

    BROWSERS = IE,Chrome,Firefox
    

    从 Hooks 访问浏览器

     puts ENV['BROWSERS']
    

    希望这会有所帮助。如果您需要有关此方法的更多信息,请告诉我。

    【讨论】:

      【解决方案2】:

      首先,我们应该理解创建 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 |法郎 | IE作为Scenario/Scenario Outline中的参数,并在step实现方法中获取参数值。但是在这种情况下,不应在挂钩中调用打开的浏览器,但根据我的理解,这是不可取的。

      希望对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-14
        • 2018-03-11
        • 2016-03-24
        • 1970-01-01
        • 1970-01-01
        • 2017-05-26
        • 2021-08-22
        • 2021-10-23
        相关资源
        最近更新 更多