Save variable from java test class 1 and use variable in java test class 2



  • 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.



  • 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;
    }
    

    Usage:

    public void test1() {
      GlobalDataStore.a = 2
    }
    
    public void test2() {
      GlobalDataStore.a //2
    }
    

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



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2