Привет, у меня запущены многопоточные параллельные тесты и работают с отчетами о степени 3.1.5. Однако моя проблема в том, что в моем отчете об экстенте для test.assignCategory («Имя теста») я хочу включить имя браузера. Поэтому, когда мой тестовый прогон parrellel показывает имя теста «Имя браузера».
Я смог добавить имя браузера, выполнив что-то вроде этого:
test.assignCategory("Directory >> Message-User"+" "+((RemoteWebDriver) driver).getCapabilities().getBrowserName().toUpperCase());
Он работает, но только с первым Браузер запускается на основе моего xml файла
<test name="contact_User">
<parameter name="browser" value="ie"/>
<classes>
<class name="tests_directory.ContactUser"></class>
</classes>
</test>
<test name="message_users">
<parameter name="browser" value="chrome"/>
<classes>
<class name="tests_directory.MessageUsers"></class>
</classes>
</test>
Хотя chrome запускается и завершает его тест. Inte rnet explorer продолжает отображаться таким образом, и он никогда не меняется, показывая CHROME.
Directory>>Message-User INTERNET EXPLORER
Моя цель - после этого параллельного запуска теста отчет экстентов должен показывать что-то вроде
Directory>>Message-User INTERNET EXPLORE
or
Directory>>Message-User Chrome
Мой код ниже:
ublic class BaseTestDirectory {
// -------Reference Variables-------------
// ----- Regression Test Cases -----
LoginLogoutPage objBELogin;
HomeNavigationPage obj_navigation;
DirectoryPage obj_directory;
// -------------------------------
protected static WebDriver driver;
protected ExtentTest test;// --parent test
ExtentReports report;
ExtentTest childTest;
@BeforeClass
@Parameters(value={"browser"})
public void setup (String browser) throws IOException, InterruptedException {
report = ExtentManager.getInstance();
driver = BrowserFactory.createInstance(browser);
DriverFactory.getInstance().setDriver(driver);
driver = DriverFactory.getInstance().getDriver();
driver.get(HOME_PAGE);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@BeforeMethod
public void register(Method method) {
String testName = method.getName();
test = report.createTest(testName);
}
@AfterMethod
public void catureStatus(ITestResult result) throws IOException {
if (result.getStatus() == ITestResult.SUCCESS) {
test.log(Status.PASS, "Test Method named as : " + result.getName() + " is passed");
} else if (result.getStatus() == ITestResult.FAILURE) {
String temp=GetScreenShot.getScreenshot(driver);
test.log(Status.FAIL,"Test failure : " + (result.getThrowable().getMessage()), MediaEntityBuilder.createScreenCaptureFromPath(temp).build());
} else if (result.getStatus() == ITestResult.SKIP) {
test.log(Status.PASS, "Test Method named as : " + result.getName() + " is skipped");
}
}
@AfterClass
public void terminate() throws InterruptedException {
//driver.quit();
DriverFactory.getInstance().removeDriver();
report.flush();
}
}
public class BrowserFactory {
public static WebDriver createInstance(String browser) throws IOException, InterruptedException
{
WebDriver driver = null;
try
{
if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "C:\\GRID\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.addArguments("--disable-features=VizDisplayCompositor");
options.addArguments("--start-maximized");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capability.setCapability(ChromeOptions.CAPABILITY, options);
options.merge(capability);
driver = new RemoteWebDriver(new URL(COMPLETE_NODE_URL), capability);
}
if (browser.equalsIgnoreCase("ie"))
{
System.setProperty("webdriver.ie.driver", "C:\\GRID\\IEDriverServer.exe");
InternetExplorerOptions capabilities = new InternetExplorerOptions();
capabilities.ignoreZoomSettings();
capabilities.setCapability("browser.download.folderList", 2);
capabilities.setCapability("browser.download.manager.showWhenStarting", false);
capabilities.setCapability("browser.helperApps.neverAsk.saveToDisk","application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;");
capabilities.setCapability("browser.helperApps.alwaysAsk.force", false);
capabilities.setCapability("browser.download.manager.alertOnEXEOpen", false);
capabilities.setCapability("browser.download.manager.useWindow", false);
capabilities.setCapability("browser.download.manager.showAlertOnComplete", false);
capabilities.setCapability("browser.download.manager.closeWhenDone", false);
//capabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
capabilities.setCapability("requireWindowFocus", false);
driver = new RemoteWebDriver(new URL(COMPLETE_NODE_URL), capabilities);
}
if (browser.equalsIgnoreCase("firefox"))
{
System.setProperty("webdriver.gecko.driver", "C:\\GRID\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("default");
try
{
myprofile.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal());
}
catch(Exception e)
{
}
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability("marionette", true);
driver = new RemoteWebDriver(new URL(COMPLETE_NODE_URL), dc);
}
}
catch (Exception e)
{
e.printStackTrace();
return driver;
}
return driver;
}
}
public class DriverFactory {
private DriverFactory()
{
}
private static DriverFactory instance = new DriverFactory();
public static DriverFactory getInstance()
{
return instance;
}
ThreadLocal<WebDriver>driver = new ThreadLocal<WebDriver>();
public WebDriver getDriver()
{
return driver.get();
}
public void setDriver(WebDriver driverParam)
{
driver.set(driverParam);
}
public void removeDriver()
{
driver.get().quit();
driver.remove();
}
}
public class MessageUsers extends BaseTestDirectory {
@Test(priority = 1, description = "Login systemAdmin UserName Password.")
public void loginBE_SystemAdmin() throws InterruptedException {
test.assignCategory("Directory >> Message-User"+" "+((RemoteWebDriver) driver).getCapabilities().getBrowserName().toUpperCase());
WebDriver driver = DriverFactory.getInstance().getDriver();
objBELogin = new LoginLogoutPage(driver);
objBELogin.login_BE(systemAdmin,password); // autoUser Login
}
@Test(priority = 2, description = "message_Users")
public void message_Users() throws InterruptedException, AWTException {
test.assignCategory("Directory >> Message-User"+" "+((RemoteWebDriver) driver).getCapabilities().getBrowserName().toUpperCase());
WebDriver driver = DriverFactory.getInstance().getDriver();
obj_directory = new DirectoryPage(driver);
obj_directory.message_Users();
}
@Test(priority = 4, description = "verify_Message_Sent")
public void verify_Message_Sent() throws InterruptedException, AWTException {
test.assignCategory("Directory >> Message-User"+" "+((RemoteWebDriver) driver).getCapabilities().getBrowserName().toUpperCase());
WebDriver driver = DriverFactory.getInstance().getDriver();
obj_directory = new DirectoryPage(driver);
obj_directory.verify_Message_Sent_2();
}
}