Search in sources :

Example 6 with BrowserType

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));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) TextFieldElement(com.seleniumtests.uipage.htmlelements.TextFieldElement) BrowserType(com.seleniumtests.driver.BrowserType) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) GenericDriverTest(com.seleniumtests.GenericDriverTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 7 with BrowserType

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;
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BrowserType(com.seleniumtests.driver.BrowserType) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) File(java.io.File) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 8 with BrowserType

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);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) BrowserType(com.seleniumtests.driver.BrowserType) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 9 with BrowserType

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"));
}
Also used : BrowserType(com.seleniumtests.driver.BrowserType) HashMap(java.util.HashMap) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ArrayList(java.util.ArrayList) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IECapabilitiesFactory(com.seleniumtests.browserfactory.IECapabilitiesFactory) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 10 with BrowserType

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();
}
Also used : BrowserType(com.seleniumtests.driver.BrowserType) HashMap(java.util.HashMap) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) ArrayList(java.util.ArrayList) List(java.util.List) EdgeCapabilitiesFactory(com.seleniumtests.browserfactory.EdgeCapabilitiesFactory) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

BrowserType (com.seleniumtests.driver.BrowserType)32 List (java.util.List)28 Test (org.testng.annotations.Test)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 MockitoTest (com.seleniumtests.MockitoTest)22 ArrayList (java.util.ArrayList)20 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)18 HashMap (java.util.HashMap)14 MutableCapabilities (org.openqa.selenium.MutableCapabilities)6 ChromeCapabilitiesFactory (com.seleniumtests.browserfactory.ChromeCapabilitiesFactory)5 EdgeCapabilitiesFactory (com.seleniumtests.browserfactory.EdgeCapabilitiesFactory)5 GenericDriverTest (com.seleniumtests.GenericDriverTest)4 OSUtilityUnix (com.seleniumtests.util.osutility.OSUtilityUnix)4 Path (java.nio.file.Path)4 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)3 ReporterTest (com.seleniumtests.it.reporter.ReporterTest)3 TextFieldElement (com.seleniumtests.uipage.htmlelements.TextFieldElement)3 EnumMap (java.util.EnumMap)3 Map (java.util.Map)3 WebDriver (org.openqa.selenium.WebDriver)3