繁体   English   中英

无法运行黄瓜文件的场景大纲示例

[英]unable to run scenario outline example of cucumber file

我在学黄瓜。 在尝试执行黄瓜场景大纲时,出现错误。 以下是黄瓜特征文件

Feature: to test pages titles    
Scenario Outline: to check title of the mutliple pages
Given Open the browser
When navigate to <Link> page
Then check <Title> of the page
Then close the browser

Examples: 
  | Link                     | Title                  |
  | https://cucumber.io/     | Cucumber               |
  | https://cucumber.io/docs | Documentation·Cucumber |
  | https://cucumber.io/blog | Blog·Cucumber          |

以下是cucumber文件的步骤定义

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class scenario_outline_sd 
{
static WebDriver driver;
@Given("^Open the browser$")
public void open_the_browser() throws Throwable 
{
    System.setProperty("webdriver.chrome.driver", "E:\\selenium bwosers\\chrome 2.35\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
}

@When("^navigate to \"([^\"]*)\" page$")
public void navigate_to_page(String page) throws Throwable 
{
    driver.get(page);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}

@Then("^check \"([^\"]*)\" of the page$")
public void check_title_of_the_page(String title) throws Throwable 
{
    if(driver.getTitle().equalsIgnoreCase(title))
    {
        System.out.println("Verified title of : "+title);
    }
}

@Then("^close the browser$")
public void close_the_browser() throws Throwable 
{
    driver.close();
    driver.quit();
}

}

在运行 cuucmber 功能文件时,它打开浏览器 3 次但不接受 URL 参数。 请帮我解决这个问题。

因为您在步骤定义中给出了错误正则表达式。

功能步骤中的 step 参数没有双重配额:

在此处输入图片说明

但是您在步骤定义中的正则表达式中使用双配额:

在此处输入图片说明

删除\\"如下应该工作

@When("^navigate to ([^\"]*) page$")
public void navigate_to_page(String page) throws Throwable 
{
    System.out.println(page);
    driver.get(page);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}

@Then("^check ([^\"]*) of the page$")
public void check_title_of_the_page(String title) throws Throwable 
{
    System.out.println(title);
    if(driver.getTitle().equalsIgnoreCase(title))
    {
        System.out.println("Verified title of : "+title);
    }
}

我可以使用以下练习代码在本地运行它:
特征文件:
在此处输入图片说明

步骤定义和运行结果:
在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM