use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.
the class TestEdgeCapabilityFactory method testCreateEdgeCapabilitiesOverrideBinPath.
/**
* check the case where we have a beta browser. The last one is choosen
*/
@Test(groups = { "ut" })
public void testCreateEdgeCapabilitiesOverrideBinPath() {
when(config.getMode()).thenReturn(DriverMode.LOCAL);
// SeleniumTestsContext class adds a browserInfo when binary path is set
Map<BrowserType, List<BrowserInfo>> updatedBrowserInfos = new HashMap<>();
updatedBrowserInfos.put(BrowserType.EDGE, Arrays.asList(new BrowserInfo(BrowserType.EDGE, "92.0", "", false), new BrowserInfo(BrowserType.EDGE, "93.0", "/opt/edge/bin/edge", false)));
PowerMockito.when(OSUtility.getInstalledBrowsersWithVersion(false)).thenReturn(updatedBrowserInfos);
MutableCapabilities capa = new EdgeCapabilitiesFactory(config).createCapabilities();
Assert.assertEquals(((Map<?, ?>) (((EdgeOptions) capa).asMap().get(EdgeOptions.CAPABILITY))).get("binary").toString(), "/opt/edge/bin/edge");
}
use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.
the class WebUIDriver method createRemoteWebDriver.
/**
* prepare driver:
* - create it
* - add listeners
* - create and start video capture
* - create and start network capture proxy
* - record driver and browser pid so that they can be deleted at the end of test session
* @return
*/
public WebDriver createRemoteWebDriver() {
webDriverBuilder = getWebDriverBuilderFactory();
logger.info("driver mode: " + config.getMode());
synchronized (createDriverLock) {
// get browser info used to start this driver. It will be used then for managing pids
BrowserInfo browserInfo = webDriverBuilder.getSelectedBrowserInfo();
List<Long> existingPids = new ArrayList<>();
// get pid pre-existing the creation of this driver. This helps filtering drivers launched by other tests or users
if (browserInfo != null) {
existingPids.addAll(browserInfo.getDriverAndBrowserPid(new ArrayList<>()));
}
TestStep cuurrentTestStep = TestStepManager.getCurrentRootTestStep();
long start = new Date().getTime();
long duration;
try {
driver = webDriverBuilder.createWebDriver();
} finally {
duration = new Date().getTime() - start;
if (cuurrentTestStep != null) {
cuurrentTestStep.setDurationToExclude(duration);
}
scenarioLogger.info(String.format("driver creation took: %.1f secs", duration / 1000.0));
}
WaitHelper.waitForSeconds(2);
List<Long> driverPids = new ArrayList<>();
// get the created PIDs
if (browserInfo != null) {
driverPids = browserInfo.getDriverAndBrowserPid(existingPids);
}
// issue #280: we use 'webDriverBuilder.getSelectedBrowserInfo()' as 'browserInfo' variable is null for grid, whereas, 'webDriverBuilder.getSelectedBrowserInfo()'
// gets an updated version once the driver has been created on grid
driver = handleListeners(driver, webDriverBuilder.getSelectedBrowserInfo(), driverPids);
if (driver != null) {
MutableCapabilities caps = ((CustomEventFiringWebDriver) driver).getInternalCapabilities();
caps.setCapability(DriverUsage.STARTUP_DURATION, duration);
caps.setCapability(DriverUsage.START_TIME, start);
// capability from IDestkopCapabilitiesFactory is not available when we request capabilities from driver.
if (config.getTestContext() != null && config.getTestContext().getTestNGResult() != null) {
String testName = TestNGResultUtils.getTestName(config.getTestContext().getTestNGResult());
caps.setCapability(DriverUsage.TEST_NAME, testName);
}
}
if (config.getBrowserMobProxy() != null) {
config.getBrowserMobProxy().newHar(SeleniumTestsContextManager.getThreadContext().getRelativeOutputDir());
}
if (config.getVideoCapture() != VideoCaptureMode.FALSE && videoRecorder.get() == null) {
try {
VideoRecorder recorder = CustomEventFiringWebDriver.startVideoCapture(SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()), "videoCapture.avi");
videoRecorder.set(recorder);
TestStepManager.setVideoStartDate();
} catch (ScenarioException e) {
logger.warn("Video capture won't start: " + e.getMessage());
}
}
}
return driver;
}
use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.
the class TestSelectList2 method init.
@BeforeMethod(groups = { "ut" })
private void init() throws IOException {
SeleniumTestsContextManager.getGlobalContext().setCucumberImplementationPackage("com.seleniumtests.ut.core.runner.cucumber");
SeleniumTestsContextManager.getThreadContext().setBrowser("firefox");
SeleniumTestsContextManager.getThreadContext().setExplicitWaitTimeout(1);
SeleniumTestsContextManager.getThreadContext().setImplicitWaitTimeout(1);
SeleniumTestsContextManager.getThreadContext().setReplayTimeout(2);
eventDriver = spy(new CustomEventFiringWebDriver(driver));
when(eventDriver.switchTo()).thenReturn(target);
when(driver.findElement(By.id("select"))).thenReturn(element);
when(driver.navigate()).thenReturn(navigation);
when(driver.getCurrentUrl()).thenReturn("http://foo");
when(driver.manage()).thenReturn(driverOptions);
when(element.getTagName()).thenReturn("select");
when(driverOptions.timeouts()).thenReturn(timeouts);
when(element.getSize()).thenReturn(new Dimension(10, 10));
when(element.getLocation()).thenReturn(new Point(5, 5));
when(targetLocator.alert()).thenReturn(alert);
when(alert.getText()).thenReturn("alert text");
when(driver.switchTo()).thenReturn(targetLocator);
PowerMockito.mockStatic(WebUIDriver.class);
when(WebUIDriver.getCurrentWebUiDriverName()).thenReturn("main");
when(WebUIDriver.getWebDriver(anyBoolean(), eq(BrowserType.FIREFOX), eq("main"), isNull())).thenReturn(eventDriver);
when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(eventDriver);
when(eventDriver.executeScript("if (document.readyState === \"complete\") { return \"ok\"; }")).thenReturn("ok");
when(eventDriver.getBrowserInfo()).thenReturn(new BrowserInfo(BrowserType.FIREFOX, "78.0"));
when(screenshotUtil.capture(any(SnapshotTarget.class), ArgumentMatchers.<Class<ScreenShot>>any())).thenReturn(screenshot);
when(screenshot.getHtmlSourcePath()).thenReturn("foo");
}
use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.
the class TestIECapabilityFactory method testCreateDefaultEdgeIEModeCapabilitiesGrid.
/**
* Edge IE mode in grid
* Check ie.edgepath and ie.edgechromium capabilities are not set
*/
@Test(groups = { "ut" })
public void testCreateDefaultEdgeIEModeCapabilitiesGrid() {
Mockito.when(config.getIeMode()).thenReturn(true);
Mockito.when(config.getMode()).thenReturn(DriverMode.GRID);
Mockito.when(config.getInitialUrl()).thenReturn("http://mysite");
Map<BrowserType, List<BrowserInfo>> browserInfos = new HashMap<>();
browserInfos.put(BrowserType.INTERNET_EXPLORER, Arrays.asList(new BrowserInfo(BrowserType.INTERNET_EXPLORER, "11", "", false)));
browserInfos.put(BrowserType.EDGE, Arrays.asList(new BrowserInfo(BrowserType.EDGE, "97.0", "", false)));
PowerMockito.when(OSUtility.getInstalledBrowsersWithVersion(false)).thenReturn(browserInfos);
MutableCapabilities capa = new IECapabilitiesFactory(config).createCapabilities();
Assert.assertEquals(capa.getCapability(CapabilityType.BROWSER_NAME), "internet explorer");
Assert.assertTrue((Boolean) capa.getCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING));
Assert.assertTrue((Boolean) capa.getCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS));
Assert.assertTrue((Boolean) capa.getCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION));
Assert.assertEquals((String) capa.getCapability(InternetExplorerDriver.INITIAL_BROWSER_URL), "http://mysite");
Assert.assertNull((Boolean) capa.getCapability("ie.edgechromium"));
Assert.assertNull((String) capa.getCapability("ie.edgepath"), "");
Assert.assertNull(((Map<String, Object>) capa.getCapability(IECapabilitiesFactory.SE_IE_OPTIONS)).get("ie.edgepath"));
Assert.assertNull(((Map<String, Object>) capa.getCapability(IECapabilitiesFactory.SE_IE_OPTIONS)).get("ie.edgechromium"));
}
use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.
the class TestEdgeCapabilityFactory method testNonBetaVersionBrowserAbsent.
/**
* If beta is not requested, and non beta browser not installed, return null
*/
@Test(groups = { "ut" }, expectedExceptions = ConfigurationException.class, expectedExceptionsMessageRegExp = "Browser EDGE is not available")
public void testNonBetaVersionBrowserAbsent() {
when(config.getMode()).thenReturn(DriverMode.LOCAL);
Map<BrowserType, List<BrowserInfo>> browserInfos = new HashMap<>();
browserInfos.put(BrowserType.EDGE, Arrays.asList(new BrowserInfo(BrowserType.EDGE, "102.0", "", false, true)));
PowerMockito.when(OSUtility.getInstalledBrowsersWithVersion(false)).thenReturn(browserInfos);
EdgeCapabilitiesFactory capaFactory = new EdgeCapabilitiesFactory(config);
capaFactory.createCapabilities();
}
Aggregations