简体   繁体   中英

unable to run scenario outline example of cucumber file

I am learing cucumber. While trying to execute cucumber scenario outline I am getting error. Following is the cucumber feature 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          |

Following is the step defination of the cucumber file

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();
}

}

while running cuucmber feature file it is opening browser 3 times but not taking parameter of URL. Please help me to fix this.

Because you give an error regexp in step definition.

There is no double quota around step argument in feature steps:

在此处输入图片说明

But you use double quota in regexp in step definition:

在此处输入图片说明

Remove \\" as below should work

@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);
    }
}

I can run it on my local with below practice code:
feature file:
在此处输入图片说明

step defintion and run result:
在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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