Java, Cucumber, Maven - Feature runs without any class

Asked

Viewed 1,229 times

0

I did a test automation project using Eclipse + Java + Maven + Cucumber + Selenium

I have the following problem:

Since I’m not using git yet, I exported this project to a file. zip, and in my work imported it through the option 'Existing project into Workspace'.

My exemplified project:

Feature - Pay request

Class to call Cucumber - Pagarpedidotest

Class to define the steps - Pagarpedidostepdef

In addition to other page Objects in another package

I noticed that when I was changing my step definition class, this same change was having no effect on the execution of my Feature (at home it was all OK, one reflected the other normally)

So I deleted my two classes and tried to run Feature again. It ran, even with no class associated with it. Delete all project classes and Feature continues to run successfully. Who knows Cucumber knows that Feature has only annotations, it does not call any method.

Can anyone explain to me why this is happening? I’m kind of a beginner in java, a friend said that 'it may be that Feature is taking a jar of a path that is set in the project'. But how do I make sure that’s it and resolve?

My Feature:

  // package - bdd_smoke_prod

    Feature: Login with Gigya

      Scenario Outline: Login
        Given I am in the Site
        When I log in with "<UserName>" and "<Password>"
        Then I will be redirected to the home page logged under my "<Name>"

        Examples: 
          | UserName     | Password  | Name |
          | [email protected]  | test123   | Luis |
          | [email protected] | erwerewre | Jack  |

My runnerclass:

 package cucumber_tests;

    import org.junit.runner.RunWith;

    import cucumber.api.CucumberOptions;
    import cucumber.api.junit.Cucumber;

    @RunWith(Cucumber.class)
    @CucumberOptions(plugin= {"pretty", "json:target/"},
    features = {"src/main/java/Login.feature"})


    public class LoginTest {

    }

My definition of steps:

 package cucumber_tests;

    import cucumber.api.PendingException;
    import cucumber.api.java.en.Given;
    import cucumber.api.java.en.Then;
    import cucumber.api.java.en.When;
    import pages.HomePage;
    import pages.Login;
    import tests.BeforeTests;
    import utils.DriverMaker;
    import utils.DriverMaker.BrowserType;

    import static org.junit.Assert.*;

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

    public class LoginStepsDef  {

        WebDriver driver = new FirefoxDriver();

        HomePage dologin = new HomePage(driver);
        Login assertlogged = new Login(driver);

        @Given("^I am in the Site$")
        public void i_am_in_the_Site() throws Throwable {

            driver.get("http://www.site.com.br");
            driver.manage().window().maximize();
            Thread.sleep(2000);

            String verificaSite = driver.getCurrentUrl();

            assertTrue(verificaSite.contains("www.site.com.br"));

            }

        @When("^I log in with \"([^\"]*)\" and \"([^\"]*)\"$")
        public void i_log_in_with_and(String email, String senha) throws Throwable {

            dologin.AcessaLogin().FazLogin(email, senha);

        }
        @Then("^I will be redirected to the home page logged under my \"([^\"]*)\"$")
        public void i_will_be_redirected_to_the_home_page_logged_under_my(String username) throws Throwable {
            assertlogged.ValidaAcesso(username); 

        }




    }

Emphasizing that this class is the only place in the project able to reproduce these steps (access the site, log in, check if the name is correct). If I delete this class and try to run Feature, I can do all this normally, as if Feature were looking for this code from beyond...?

Thank you.

  • Cara has never used Cucumber with Java, only Ruby, put your Feature and your step Definition, your step defined in Feature is unique so if you set Voce Given that I am on the start screen your step Definition has no way to get the "jar" of another class. @Luísgustavovieira

  • @Wellingtonavelino First of all, thank you for helping! I edited the post with the code. The class that performs the steps is unique, there is no other of it. But even if I delete it, or delete ALL classes in my project, only leaving the package containing the '.Feature' file, even then, that file will run, open the browser, log in, and check if the name exists. It’s like I’m pulling the code from somewhere else.

  • Coming home I’ll take a look

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.