Точная конфигурация или парадигма.Вы можете использовать TestNG, Java e Selenium Web Driver.
SuiteTest.xml:
<test name="FIREFOX Test">
<parameter name="browser" value="FIREFOX" />
<classes>
<class name="test.CN01_CT01_IncluirConteudoMP3" />
<class name="test.CN01_CT02_IncluirConteudoMP4" />
</classes>
</test>
<test name="CHROME Test">
<parameter name="browser" value="CHROME" />
<classes>
<class name="test.CN01_CT01_IncluirConteudoMP3" />
<class name="test.CN01_CT02_IncluirConteudoMP4" />
</classes>
</test>
Класс DriveFactory:
Открытый класс DriverFactory {
private static WebDriver driver;
private DriverFactory() {
}
public static WebDriver getDriver(){
if (driver == null) {
switch (Propriedades.browser) {
case CHROME:
executeChrome(BasePage.url);
break;
case FIREFOX:
executeFirefox(BasePage.url);
break;
case IE:
executeIE(BasePage.url);
break;
case EDGE:
executeEgde(BasePage.url);
break;
}
driver.manage().window().maximize();
}
return driver;
}
public static void executeChrome(String urlSystem){
String driverpathChrome = System.getProperty("user.dir") + File.separator + "drivers" + File.separator + "chromedriver.exe";
System.setProperty("webdriver.chrome.driver", driverpathChrome);
ChromeOptions options = new ChromeOptions();
options.addArguments(
String.format("user-data-dir=C:/Users/William Soares/AppData/Local/Google/Chrome/User Data/Default"));
options.addArguments("--disable-extensions");
driver = new ChromeDriver(options);
getDriver().get(urlSystem);
}
public static void executeFirefox(String urlSystem){
String driverpathFirefox = System.getProperty("user.dir") + File.separator + "drivers" + File.separator + "geckodriver.exe";
System.setProperty("webdriver.gecko.driver", driverpathFirefox);
driver = new FirefoxDriver();
getDriver().get(urlSystem);
}
public static void executeIE(String urlSystem){
String driverpathIE = System.getProperty("user.dir") + File.separator + "drivers" + File.separator + "IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", driverpathIE);
driver = new InternetExplorerDriver();
getDriver().get(urlSystem);
}
public static void executeEgde(String urlSystem){
String driverpathEdge = System.getProperty("user.dir") + File.separator + "drivers" + File.separator + "MicrosoftWebDriver.exe";
System.setProperty("webdriver.edge.driver", driverpathEdge);
driver = new EdgeDriver();
getDriver().get(urlSystem);
}
public static void killDriver() {
if (driver != null) {
driver.quit();
driver = null;
}
}
}
Класс BaseTest:
Открытый класс BaseTest {
protected static ExtentReports extent;
public static String testName;
@Parameters({ "browser" })
@BeforeMethod
public void BeforeTest(Method method, Browsers browser) throws IOException, BiffException {
Propriedades.browser = browser;
String browserStr = browser.toString();
System.out.println("Before ........" + method.getName());
//Recuperar nome do Teste
testName = method.getName() + "-" + browserStr;
// Realizando Login
LoginPage.realizarLogin();
//Iniciar o relatorio
extent = ExtentReport.StartReport(testName);
}
@AfterMethod
public void finaliza(ITestResult result) throws IOException {
System.out.println("After ........");
//Validar Resultado dos Testes
ExtentReport.ResultTest(result, testName);
// Realizar Logout
LoginPage.realizarLogout();
// Fechando Browser
if (Propriedades.FECHAR_BROWSER) {
killDriver();
}
}
@AfterSuite
public static void finalizaTudo(){
DriverFactory.killDriver();
extent.flush();
System.out.println("AfterSuite........");
System.out.println(ExtentReport.diretorioReport);
}
}
Тест- Класс:
@ Test
публичный void CN01_CT02_IncluirConteudoMp4 () {
assertEquals("123", "123");
}
@ Test
публичный void CN01_CT01_IncluirConteudoMp3() выдает InterruptedException, AWTException {
assertEquals("123", "123456");
}
Pom.xml:
Файл Pom.Xml настроен нормально.