DeeJay007
DeeJay007

Reputation: 509

Selenium- Run a method once and use the return value for all @Test methods in the class

My requirement goes like this.

  1. Log in to the application and open the System property menu to return a value of the property.
  2. Open Another menu in the application and based on the value returned in the above step, perform the test scenario.

The problem is, for each @Test methods in the same class I need to perform both step 1 and 2 which is a time taking and unnecessary. The property retrieved from 'step 1' will be the same throughout the execution of the tests in the class.

Is there anyway I can execute 'step 1' just once at the start of the test and use the property value returned for all the @Test methods in the class following it?

P.S- I checked on the dependsOnMethods annotation and not sure whether it is a solution I am looking for.

Upvotes: 0

Views: 1184

Answers (1)

JDelorean
JDelorean

Reputation: 641

If you're using JUnit, it sounds like @BeforeClass is what you are looking for. Method with this annotation runs only once per class and you can store any value returned in a global variable. Or, you might consider @Before annotation (runs before each test) if that suits you better.

Other testing frameworks use similar idea.

Upvotes: 1

Related Questions