Forum Discussion

dasabaja1's avatar
dasabaja1
Visitor
3 years ago

Code executed first, then the step definition is printed. Can I reverse that?

Hi all.

I'm new to Cucumber and I'm fiddling around with it, so this is probably a silly question.

Once I execute my Testrunner class, in my console output the code written in the Given statment gets executed and only after that is the step definition printed. I would like to have that the other way around.

Here's my example, it's quite simple:

 

Scenario Outline: Check login is successful with valid credentials

Given user is on login page
When user enters <username> and <password>

 Here is the glue code:

 

@Given("user is on login page")
public void user_is_on_login_page() {
WebDriverManager.chromedriver().setup();

driver = new ChromeDriver();

driver.get("http://www.google.com");

Assert.assertEquals(driver.getTitle(),"Google");

System.out.println("Print from Given statment");
}

 Selenium gets started, goes to Google, nothing major...note the print statement.

And here's my output:

 

Scenario Outline: Check login is successful with valid credentials # src/test/resources/Features/login.feature:12
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 92.0.4515.107 (87a818b10553a07434ea9e2b6dccf3cbe7895134-refs/branch-heads/4515@{#1634}) on port 24525
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
avg 12, 2021 10:16:09 PRE PODNE org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Print from Given statment
  Given user is on login page                                      # StepDefinitions.LoginSteps.user_is_on_login_page()

 

 

As you can see I get the code execution first (Selenium and the print statement...) and only after that I get what step is that code referring to. Is that standard? It's kind of confusing, I'd like to have a step definition first, and then the code...

 

No RepliesBe the first to reply