I have written the Selenium scripts (page object model) to navigate a website, fill in form data, and submit the form. I next need to verify that the form data was indeed saved in the database.

My current solution is to capture 'date time' upon submitting the form in test class 1 to compare to database date time in test class 2. However, I do not know how to make this 'date time' available in test class 2. How can I make this work? I have a little Java experience but don't know if I am simply missing a fundamental concept of Java??

Both Class 1 and Class 2 are inheriting from a base class; can I store the variable there? I tried writing the variable to my properties file which did not work. I am also fairly new to Selenium so please help.

  • 1
    Is "test class 1" a test by itself, isolated from "test class 2"? If so, do you want to use "test class 1" as a setup for "test class 2"? Sep 18, 2019 at 23:56

4 Answers 4


Not sure you want to share data between tests, as they should be able to run independent from other.

You can create a global class which you can use from mutliple locations:

public class GlobalDataStore {
    public static int a;
    public static int b;


public void test1() {
  GlobalDataStore.a = 2

public void test2() {
  GlobalDataStore.a //2

I use something like this to share data between steps in Cucumber.


From what you have said I assume that you have several tests (otherwise you wouldn't call the classes "test class") which are cross-dependent. This is always a bad idea. The best way for you is to change the approach. You should have a sort of Utils class where you would have a method like checkFormSubmition(DateTime dateTime, FormData expectedData) where dateTime is and object that you have captured within your test1 and expectedData is a POJO that you build basing on the data you're trying to submit in UI.

Thus, the method would take care of all the database-related things and can be re-used in different tests (including data-driven ones).

The approach you're trying to implement is a bit risky since you can run into issues when run your tests in parallel.


I am not sure if you used the Page Object (PO) correctly. Basically, in PO for each web page/element in the application, there should be corresponding page class.

As an idea in your case, define one class for the first page (submit data), and another class for second page (e.g the one which queries and shows the data). And 3rd class which is the main test class which would call these two classes in sequence.

If you use this design, then you can define in your first class a property called "submittedDate" and use the getter and setter anywhere else, or in class methods, return an object which contains necessary priorities.


There are few ways to do it, but all of them are working as global variables in your test scripts.

I agree also that there is no need to divide both tests you've mentioned into two classes. Altough if you must for some reason, then I would suggest to use Niels solution with GlobalDataStore or get familiar with TestContext which needs Cucumber in your tests (BDD is quite nice though).

There is a great article about it here: https://www.toolsqa.com/selenium-cucumber-framework/sharing-test-context-between-cucumber-step-definitions/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.