use of com.seleniumtests.driver.BrowserType in project seleniumRobot by bhecquet.
the class TestWebUiDriver method testAttachExternalChromeBrowser.
/**
* Check we can attach Selenium to a chrome process if it's launched with '--remote-debugging-port' option
*/
@Test(groups = { "it" })
public void testAttachExternalChromeBrowser() {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
Map<BrowserType, List<BrowserInfo>> browsers = OSUtility.getInstalledBrowsersWithVersion();
String path = browsers.get(BrowserType.CHROME).get(0).getPath();
int port = GenericDriverTest.findFreePort();
// create chrome browser with the right option
new BrowserLauncher(BrowserType.CHROME, port, path, 0, null).run();
// creates the driver
WebDriver driver1 = WebUIDriver.getWebDriver(true, BrowserType.CHROME, "main", port);
driver1.get("chrome://settings/");
Assert.assertTrue(new TextFieldElement("search", By.id("search")).isElementPresent(3));
}
use of com.seleniumtests.driver.BrowserType in project seleniumRobot by bhecquet.
the class SeleniumRobotSnapshotServerConnector method checkSnapshotHasNoDifferences.
/**
* Send snapshot to server, for comparison, and check there is no difference with the reference picture
* This method will return true if
* - comparison is OK
* It returns null if:
* - server is inactive
* - computing error occurred
* - server side error ( e.g: if the server is not up to date)
*/
public SnapshotComparisonResult checkSnapshotHasNoDifferences(Snapshot snapshot, String testName, String stepName) {
if (!active) {
return SnapshotComparisonResult.NOT_DONE;
}
if (testName == null) {
throw new ConfigurationException("testName must not be null");
}
if (stepName == null) {
throw new ConfigurationException("stepName must not be null");
}
if (snapshot == null || snapshot.getScreenshot() == null || snapshot.getScreenshot().getFullImagePath() == null) {
throw new SeleniumRobotServerException("Provided snapshot does not exist");
}
String snapshotName = snapshot.getName().length() > MAX_SNAPSHOT_NAME_LENGHT ? snapshot.getName().substring(0, MAX_SNAPSHOT_NAME_LENGHT) : snapshot.getName();
try {
File pictureFile = new File(snapshot.getScreenshot().getFullImagePath());
BrowserType browser = SeleniumTestsContextManager.getGlobalContext().getBrowser();
browser = browser == null ? BrowserType.NONE : browser;
String strippedTestName = getTestName(testName);
String strippedStepName = getTestStepName(stepName);
JSONObject snapshotJson = getJSonResponse(buildPutRequest(url + SNAPSHOT_API_URL).socketTimeout(5000).field(FIELD_IMAGE, pictureFile).field(FIELD_NAME, snapshotName).field("compare", snapshot.getCheckSnapshot().getName()).field("diffTolerance", String.valueOf(snapshot.getCheckSnapshot().getErrorThreshold())).field("versionId", versionId.toString()).field("environmentId", environmentId.toString()).field("browser", browser.getBrowserType()).field("testCaseName", strippedTestName).field("stepName", strippedStepName));
if (snapshotJson != null) {
String computingError = snapshotJson.getString(FIELD_COMPUTING_ERROR);
Float diffPixelPercentage = snapshotJson.getFloat("diffPixelPercentage");
Boolean tooManyDiffs = snapshotJson.getBoolean("tooManyDiffs");
if (!computingError.isEmpty()) {
return SnapshotComparisonResult.NOT_DONE;
} else if (Boolean.TRUE.equals(tooManyDiffs)) {
logger.error(String.format("Snapshot comparison for %s has a difference of %.2f%% with reference", snapshot.getName(), diffPixelPercentage));
return SnapshotComparisonResult.KO;
} else {
return SnapshotComparisonResult.OK;
}
} else {
return SnapshotComparisonResult.NOT_DONE;
}
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
// in case selenium server is not up to date, we shall not raise an error / retry
logger.error("cannot send snapshot to server", e);
return SnapshotComparisonResult.NOT_DONE;
}
}
use of com.seleniumtests.driver.BrowserType in project seleniumRobot by bhecquet.
the class SeleniumRobotSnapshotServerConnector method createSession.
/**
* Create a test session
* @return
*/
public Integer createSession(String sessionName) {
if (!active) {
return null;
}
if (applicationId == null) {
throw new SeleniumRobotServerException(String.format("Application %s has not been created", SeleniumTestsContextManager.getApplicationName()));
}
if (environmentId == null) {
throw new SeleniumRobotServerException(String.format("Environment %s has not been created", SeleniumTestsContextManager.getGlobalContext().getTestEnv()));
}
if (versionId == null) {
createVersion();
}
String strippedSessionName = sessionName.length() > MAX_TESTSESSION_NAME_LENGHT ? sessionName.substring(0, MAX_TESTSESSION_NAME_LENGHT) : sessionName;
try {
BrowserType browser = SeleniumTestsContextManager.getGlobalContext().getBrowser();
browser = browser == null ? BrowserType.NONE : browser;
// for uniqueness of the session
sessionUUID = UUID.randomUUID().toString();
JSONObject sessionJson = getJSonResponse(buildPostRequest(url + SESSION_API_URL).field("sessionId", sessionUUID).field("date", LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)).field("browser", browser.getBrowserType()).field("environment", SeleniumTestsContextManager.getGlobalContext().getTestEnv()).field("version", versionId.toString()).field(FIELD_NAME, strippedSessionName).field("compareSnapshot", String.valueOf(SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshot())).field("ttl", // format is 'x days' as this is the way Django expect a duration in days
String.format("%d days", SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotTtl())));
return sessionJson.getInt("id");
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
throw new SeleniumRobotServerException("cannot create session", e);
}
}
use of com.seleniumtests.driver.BrowserType 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.driver.BrowserType 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