Question

Hi I have setUp a Java project using Maven in eclipse.

I am facing an issue whenever I am trying to run the script. Its is executed by the not opening the desired website which I am parsing from the feature file.

Please have a look to the following code and Image of my directories setup in eclipse

Eclipse Directory Structure

Here is my code for PageStepsDefs.java

package com.workshop.airport.workshop.airport;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;

public class PageStepsDefs {

    public String ChromeDriverPath="C:\\Users\\zain.jamshaid\\Desktop\\chromedriver.exe";
    public WebDriver driver;
    String localhost="www.google.com";

    @Before
    public void deleteAllCookies() {
        driver.manage().deleteAllCookies();
        driver.manage().window().maximize();
    }

    @Before
    public void setup(){
        System.setProperty("webdriver.chrome.driver",ChromeDriverPath);
        driver = new ChromeDriver();    
    }

    @Given("^I browse to the (.+) page$")
    public void open_page(String url)
    {

        driver.get(localhost+url);
        System.out.println(localhost+url);
    }

    @After
    public void tearDown(){
        driver.quit();
    }
}

Here is my code for RunCukeTest.java

package com.workshop.airport.workshop.airport;

import cucumber.api.junit.*;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Cucumber.Options(
        tags={"@mysingle"},
        format={"pretty", "html:target/cucumber-html-report"},
        monochrome=true,
        features={"."}, 
        strict=true)

public class RunCukeTest {

}

Here is statements in feature file

Feature: Login Functionality
@mysingle
Scenario: user successfully logins to the application

    Given I browse to the / page

Any help will be awesome.

Thanks In advance. Zain

Was it helpful?

Solution

I think I know the problem. As per your comment, the '/' from feature file is getting parsed to your step correctly. So this is not a cucumber issue. The issue I think is with your url. The url you have is incorrectly formed. URL should start with http://

I think everything will work fine if you change your localhost variable to String localhost="http://www.google.com";

OTHER TIPS

Is it really executing your feature file? Try putting test.feature under src/test/resources/com/workshop/airport/workshop/airport: the JUnit running uses the unit test package as the location for finding the feature files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top