Serenity BDD with jUnit how to inject steps into setup method?

vicusbass

I am working on a test framework which is using Serenity, Selenium and jUnit. I have some tests which depend on user authentication. Basically I have to repeat all login steps for each test. I wanted to move these steps to a @Before method, but it seems that Steps are not being initialized in a method which is not annotated as @Test... See the code snippet below, AuthSteps instance is not being initialized.

Which are my options?

@RunWith(SerenityRunner.class)
public class MyTests extends AbstractTest {
@Managed(driver = "firefox", uniqueSession = false)
@Steps
AuthSteps auth;

@Before
public void authSetup() {
 if (!authenticated){
  auth.login();
  //a lot of other things
 }
}

@Test
public void mytest(){
 //do test related stuff
}
JDelorean

They do. Steps will run with either @BeforeClass, @Before, @Test and so on. It seems that your if (!authenticated) statement might be excluding execution of your auth.login() step.

There's certainly not enough code provided here (like what is boolean authenticated)to clearly examine your issue, but I hope this answer helps you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Timeout setup for Serenity BDD or Cucumber BDD framework?

From Dev

Cucumber-serenity not inject Steps

From Dev

Serenity BDD reports naming

From Dev

How can I change serenity-bdd log settings

From Dev

How to skip steps in background of Behave BDD?

From Dev

Spring Boot BDD Testing with serenity

From Dev

Serenity BDD fun features by groups

From Dev

BDD: Embedded tables with serenity and jbehave

From Dev

Pass parameters to Junit setup method

From Dev

Serenity BDD test cases are not running on Chrome browser

From Dev

Serenity BDD with JBehave loading duplicate requirements

From Dev

Serenity BDD test cases are not running on Chrome browser

From Dev

Remember credentials with serenity BDD (using selenium)

From Dev

serenity-bdd with cucumber feature hooks

From Dev

BDD Proper Given Setup

From Dev

running setup method for junit only once

From Dev

How to inject a @Named bean into a Junit test

From Dev

How to inject a @Named bean into a Junit test

From Dev

How to inject lambda method in constructor?

From Dev

Calling a private method inside every JUnit before any test steps

From Dev

Serenity BDD report does not show stories with Examples (Embedded tables)

From Dev

serenity bdd default url with spring boot random port number

From Dev

How can one inject initialization steps into a workflow service?

From Dev

How to JUnit test a Method with a Scanner?

From Dev

How to tell Junit/Mockito to wait for AndroidAnnotations to inject the dependenices

From Dev

How to setup and call an Async method

From Dev

How to use setup method in moq?

From Dev

Struggling with how test a method with several steps

From Java

How to inject a string in a JAVA servlet´s method?

Related Related

HotTag

Archive