Al final solucioné mi problema de la siguiente manera
package test_suite;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pageObjects.CreateNewStudyPage;
import pageObjects.LoginPage;
@RunWith(Suite.class)
@SuiteClasses({
LoginPage.class,
CreateNewStudyPage.class,
//OpenAllTabsAndExports.class
})
public class Test_Suite {
public static WebDriver driver;
@BeforeClass
public static void setUpClass() throws MalformedURLException {
System.setProperty("webdriver.chrome.driver", "D:\\WebDriver_Selenium/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("http://10.3.8.50");
}
@AfterClass
public static void setDownClass() {
driver.quit();
}
}
Primer test que realiza la aplicación
package pageObjects;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import test_suite.Test_Suite;
public class LoginPage {
@Test
public void testLogin() {
WebDriver driver = Test_Suite.driver;
driver.findElement(By.id("sponsorname")).clear();
driver.findElement(By.id("sponsorname")).sendKeys("Test");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("admin1");
driver.findElement(By.id("pwd")).clear();
driver.findElement(By.id("pwd")).sendKeys("123");
driver.findElement(By.cssSelector("button.btn.btn-success")).click();
}
}
Luego sin cerrar el browser, el test suite continua ejecutando el siguiente test
package pageObjects;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;
import test_suite.Test_Suite;
public class CreateNewStudyPage {
private StringBuffer verificationErrors = new StringBuffer();
@Test
public void testCreateNewStudy() throws InterruptedException {
WebDriver driver = Test_Suite.driver;
if(isElementPresent(By.id("userMenu"), driver)) {
driver.findElement(By.xpath("//*[@id='dropdownMenu1']/i/i")).click();
for (int second = 0;; second++) {
if (second >= 30) fail("timeout");
try { if (isElementPresent(By.xpath("//*[@id='userMenu']/div/ul/li[3]/a"), driver)) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("//*[@id='userMenu']/div/ul/li[3]/a")).click();
}
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.xpath("//input[@value='Add']"), driver)) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("//input[@value='Add']")).click();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.id("StudyCode"), driver)) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("StudyCode")).clear();
driver.findElement(By.id("StudyCode")).sendKeys("Study_Code_Automation28");
driver.findElement(By.id("GSKBmarcref")).clear();
driver.findElement(By.id("GSKBmarcref")).sendKeys("BMARCREF");
driver.findElement(By.id("StudyShortName")).clear();
driver.findElement(By.id("StudyShortName")).sendKeys("Short Name");
new Select(driver.findElement(By.id("SvtVersionId"))).selectByVisibleText("1");
new Select(driver.findElement(By.id("BudgetTypeId"))).selectByVisibleText("Substudy");
new Select(driver.findElement(By.id("PhaseName"))).selectByVisibleText("I");
new Select(driver.findElement(By.id("PatientTypeId"))).selectByVisibleText("Inpatient");
private boolean isElementPresent(By by, WebDriver driver) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
Aquí la clave está en las primeras líneas de las clases donde se va a realizar el test, y es crear el driver asignandole el valor del driver de la clase Test Suite
WebDriver driver = Test_Suite.driver;
Y de este modo se usa siempre el mismo navegador para todos los tests que ejecute dentro del test suite.