I'm looking for a way to store an instantiated object and all of its properties to an external location and reuse it later.
What I tried so far:
I came across this [Serialization?] answer and tried it but the object I'm getting is null.
Algo / Rough code:
@Listeners(TestListener.class)
public class TestRunner {
protected static Driver driver; //Driver implements WebDriver interface
//Step 1
public void method1(){
driver = new Driver(1); //creates a customized chromedriver instance. Chrome driver / browser session is opened here.
}
//Step 2
public void method2(){
try {
FileOutputStream fileOut = new FileOutputStream("card.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(driver);
out.close();
fileOut.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
//Step 3
//Just manually stop the test/debugger for testing
//Step 4
public void method4(){
try {
FileInputStream fileIn = new FileInputStream("card.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
driver = (Driver) in.readObject(); //here driver returns as null. In this line, im hoping to recreate the previous object to somehow control the browser again
in.close();
fileIn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Some info:
This is actually related to a Selenium WebDriver problem in this SO question.
So what I'm trying to do is:
I don't have prior background with serialization and I'm not sure if what I'm trying to do is possible. Any help or guidance is much appreciated.