I have this quite simple test as you can see below, but there is a problem. In the first test "A_login" i navigate to a specific page and get the contents of a table and I store this content in an ArrayList. When the first test is finished i want to use the data i've gathered in the second test but when i try to use it or print the list out it is empty. Is there any good reason why? It seems that JUnit clears the instance variable. How can i make this work?
public class Crawl extends Driver {
private static WebDriver driver;
private List<String> table_data;
public Crawl() {
super();
this.driver = super.getDriver();
this.table_data = new ArrayList<String>();
}
/*
Login and get all open orders
*/
@Test
public void A_login() {
this.driver.get("http://www.xxxx.no/xxxx/");
this.driver.findElement(By.id("username")).sendKeys("Username");
this.driver.findElement(By.id("password")).sendKeys("Password");
this.driver.findElement(By.xpath("/html/body/div[2]/div/div/form/fieldset/div[4]/div/input[2]")).click();
this.driver.get("http://www.xxxxx.no/xxxx/shops_invoice.php");
WebElement table = this.driver.findElement(By.xpath("/html/body/div/div[2]/div[2]/table/tbody"));
List<WebElement> tr_collection = table.findElements(By.tagName("tr"));
for(int i = 0; i < tr_collection.size() ; i++){
this.table_data.add((tr_collection.get(i).getText());
}
}
@Test
public void B_getCustomerInfo() {
System.out.println(this.table_data);
}
@AfterClass
public static void tearDown() { driver.quit(); }
}