org.openqa.selenium.remote.BrowserType Java Examples

The following examples show how to use org.openqa.selenium.remote.BrowserType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HideMultiElementsTest.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * 複数セレクタで複数の要素を指定して非表示にするが、そのうちのいずれかは存在しない要素である。
 * 
 * @ptl.expect エラーが発生せず、非表示に指定した要素が写っていないこと。
 */
@Test
public void multiTargets_notExist() throws Exception {
	openBasicColorPage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().addHiddenElementsById("not-exists")
			.addHiddenElementsById("colorColumn1").addHiddenElementsById("colorColumn2").build();
	if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) {
		expectedException.expect(NoSuchElementException.class);
	}
	assertionView.assertView(arg);

	// Check
	// 特定の色のピクセルが存在しないこと
	BufferedImage image = loadTargetResults("s").get(0).getImage().get();
	int width = image.getWidth();
	int height = image.getHeight();
	for (int x = 0; x < width; x++) {
		for (int y = 0; y < height; y++) {
			Color actual = Color.valueOf(image.getRGB(x, y));
			assertThat(actual, is(not(anyOf(equalTo(Color.GREEN), equalTo(Color.BLUE)))));
		}
	}
}
 
Example #2
Source File: DesktopFactory.java    From carina with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public DesiredCapabilities getCapabilities(String name) {
    String browser = Configuration.getBrowser();

    if (BrowserType.FIREFOX.equalsIgnoreCase(browser)) {
        return new FirefoxCapabilities().getCapability(name);
    } else if (BrowserType.IEXPLORE.equalsIgnoreCase(browser) || BrowserType.IE.equalsIgnoreCase(browser) || browser.equalsIgnoreCase("ie")) {
        return new IECapabilities().getCapability(name);
    } else if (BrowserType.SAFARI.equalsIgnoreCase(browser)) {
        return new SafariCapabilities().getCapability(name);
    } else if (BrowserType.CHROME.equalsIgnoreCase(browser)) {
        return new ChromeCapabilities().getCapability(name);
    } else if (BrowserType.OPERA_BLINK.equalsIgnoreCase(browser) || BrowserType.OPERA.equalsIgnoreCase(browser)) {
        return new OperaCapabilities().getCapability(name);
    } else if (BrowserType.EDGE.toLowerCase().contains(browser.toLowerCase())) {
        return new EdgeCapabilities().getCapability(name);
    } else {
        throw new RuntimeException("Unsupported browser: " + browser);
    }
}
 
Example #3
Source File: WebDriverManagerTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
static Stream<Arguments> webDriverTypeChecks()
{
    return Stream.of(
        Arguments.of(BrowserType.FIREFOX,         WebDriverType.FIREFOX,      true   ),
        Arguments.of(BrowserType.FIREFOX_CHROME,  WebDriverType.FIREFOX,      false  ),
        Arguments.of(BrowserType.CHROME,          WebDriverType.CHROME,       true   ),
        Arguments.of(BrowserType.FIREFOX_CHROME,  WebDriverType.CHROME,       false  ),
        Arguments.of(BrowserType.EDGE,            WebDriverType.EDGE,         true   ),
        Arguments.of(BrowserType.IE,              WebDriverType.EDGE,         false  ),
        Arguments.of(BrowserType.IEXPLORE,        WebDriverType.IEXPLORE,     true   ),
        Arguments.of(BrowserType.IE_HTA,          WebDriverType.IEXPLORE,     false  ),
        Arguments.of(BrowserType.SAFARI,          WebDriverType.SAFARI,       true   ),
        Arguments.of(BrowserType.SAFARI_PROXY,    WebDriverType.SAFARI,       true   ),
        Arguments.of(BrowserType.IPHONE,          WebDriverType.SAFARI,       false  )
    );
}
 
Example #4
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void testGetRemoteWebDriverIEDriver() throws Exception
{
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setBrowserName(BrowserType.IEXPLORE);
    when(remoteWebDriverFactory.getRemoteWebDriver(any(URL.class), any(DesiredCapabilities.class)))
            .thenReturn(remoteWebDriver);
    Timeouts timeouts = mockTimeouts(remoteWebDriver);
    desiredCapabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
    assertEquals(remoteWebDriver,
            ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #5
Source File: UploadFileTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldWriteABase64EncodedZippedFileToDiskAndKeepName() throws Exception {
  Session session = DefaultSession.createSession(
      driverFactory,
      tempFs,
      new DesiredCapabilities(BrowserType.FIREFOX, "10", Platform.ANY));

  File tempFile = touch(null, "foo");
  String encoded = Zip.zip(tempFile);

  UploadFile uploadFile = new UploadFile(session);
  Map<String, Object> args = ImmutableMap.of("file", encoded);
  uploadFile.setJsonParameters(args);
  String path = uploadFile.call();

  assertTrue(new File(path).exists());
  assertTrue(path.endsWith(tempFile.getName()));
}
 
Example #6
Source File: TestingBotPaasHandler.java    From KITE with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchConfig() throws IOException {
  
  List<JsonObject> availableConfigList = this.getAvailableConfigList(null, null);
  
  /* might be not necessary, depending on data format it DB */
  for (JsonObject jsonObject : availableConfigList) {
    Client client = new Client();
    client.getBrowserSpecs().setVersion(jsonObject.getString("version", ""));
    
    String browserName = jsonObject.getString("name", "");
    if (browserName.endsWith("edge"))
      browserName = BrowserType.EDGE;
    else if (browserName.equalsIgnoreCase(BrowserType.GOOGLECHROME))
      browserName = BrowserType.CHROME;
    client.getBrowserSpecs().setBrowserName(browserName);
    
    String platform = jsonObject.getString("platform", "");
    client.getBrowserSpecs().setPlatform(
      platform.equalsIgnoreCase("CAPITAN") ? Platform.EL_CAPITAN : Platform.fromString(platform));
    
    this.clientList.add(client);
  }
  
}
 
Example #7
Source File: BrowserSpecs.java    From KITE with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the driver string.
 *
 * @return the driver string
 */
@Transient
public String getDriverString() {
  String driverString = "";
  switch (this.getBrowserName()) {
    // Selenium
    case BrowserType.CHROME:
      if (this.getPathToDriver() != null && this.getPathToDriver() != "") {
        driverString = "-Dwebdriver.chrome.driver=" + this.getPathToDriver();
      } else {
        driverString = "-Dwebdriver.chrome.driver=./chromedriver";
      }

      break;
    case BrowserType.FIREFOX:
      if (this.getPathToDriver() != null && this.getPathToDriver() != "") {
        driverString = "-Dwebdriver.gecko.driver=" + this.getPathToDriver();
      } else {
        driverString = "-Dwebdriver.gecko.driver=./geckodriver";
      }
      break;
  }
  return driverString;
}
 
Example #8
Source File: DesktopFactory.java    From carina with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private String getBrowserVersion(WebDriver driver) {
    String browser_version = Configuration.get(Parameter.BROWSER_VERSION);
    try {
        Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
        browser_version = cap.getVersion().toString();
        if (browser_version != null) {
            if (browser_version.contains(".")) {
                browser_version = StringUtils.join(StringUtils.split(browser_version, "."), ".", 0, 2);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Unable to get actual browser version!", e);
    }
    
    // hotfix to https://github.com/qaprosoft/carina/issues/882
    String browser = Configuration.get(Parameter.BROWSER);
    if (BrowserType.OPERA.equalsIgnoreCase(browser) || BrowserType.OPERA_BLINK.equalsIgnoreCase(browser)) {
        browser_version = getOperaVersion(driver);
    }
    return browser_version;
}
 
Example #9
Source File: HiddenInFrameTest.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * BODYを撮影する際に、IFRAME内の要素を非表示に設定する。
 * 
 * @ptl.expect 非表示に設定した要素が写っていないこと。
 */
@Test
public void captureBody() throws Exception {
	assumeFalse("Skip Safari hidden test.", BrowserType.SAFARI.equals(capabilities.getBrowserName()));
	openIFramePage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().moveTarget(true).scrollTarget(false)
			.addHiddenElementsByClassName("content-left").inFrameByClassName("content").build();
	assertionView.assertView(arg);

	// Check
	// 指定した色のピクセルが存在しないこと
	BufferedImage image = loadTargetResults("s").get(0).getImage().get();
	int width = image.getWidth();
	int height = image.getHeight();
	Color hiddenColor = Color.valueOf("#795548");
	for (int x = 0; x < width; x++) {
		for (int y = 0; y < height; y++) {
			Color actual = Color.valueOf(image.getRGB(x, y));
			assertThat(actual, is(not(hiddenColor)));
		}
	}
}
 
Example #10
Source File: HiddenInFrameTest.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * IFRAMEを撮影する際に、IFRAME内の要素を非表示に設定する。
 * 
 * @ptl.expect 非表示に設定した要素が写っていないこと。
 */
@Test
public void captureIFrame() throws Exception {
	assumeFalse("Skip Safari hidden test.", BrowserType.SAFARI.equals(capabilities.getBrowserName()));
	openIFramePage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetByClassName("content").moveTarget(true)
			.scrollTarget(true).addHiddenElementsByClassName("content-left").inFrameByClassName("content").build();
	assertionView.assertView(arg);

	// Check
	// 指定した色のピクセルが存在しないこと
	BufferedImage image = loadTargetResults("s").get(0).getImage().get();
	int width = image.getWidth();
	int height = image.getHeight();
	Color hiddenColor = Color.valueOf("#795548");
	for (int x = 0; x < width; x++) {
		for (int y = 0; y < height; y++) {
			Color actual = Color.valueOf(image.getRGB(x, y));
			assertThat(actual, is(not(hiddenColor)));
		}
	}
}
 
Example #11
Source File: ExcludeInFrameTest.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * BODYを撮影する際にiframe内外のs存在しない要素を除外する。
 * 
 * @ptl.expect エラーが発生せず、除外領域が保存されていないこと。
 */
@Test
public void captureBody_excludeNotExistElementInsideAndOutsideFrame() throws Exception {
	openIFramePage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().moveTarget(true).scrollTarget(false)
			.addExcludeByClassName("not-exists").addExcludeByClassName("not-exists").inFrameByClassName("content")
			.build();
	if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) {
		expectedException.expect(NoSuchElementException.class);
	}
	assertionView.assertView(arg);

	// Check
	TargetResult result = loadTargetResults("s").get(0);
	assertThat(result.getExcludes(), is(empty()));
}
 
Example #12
Source File: ExcludeInFrameTest.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * iframeを撮影する際にiframe内の存在しない要素を除外する。
 * 
 * @ptl.expect エラーが発生せず、除外領域が保存されていないこと。
 */
@Test
public void captureIFrame_excludeNotExists() throws Exception {
	openIFramePage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetByClassName("content").moveTarget(true)
			.scrollTarget(true).addExcludeByClassName("not-exists").build();
	if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) {
		expectedException.expect(NoSuchElementException.class);
	}
	assertionView.assertView(arg);

	// Check
	TargetResult result = loadTargetResults("s").get(0);
	assertThat(result.getExcludes(), is(empty()));
}
 
Example #13
Source File: NoSuchElementTest.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * 存在しない要素を指定して撮影する。
 * 
 * @ptl.expect AssertionErrorが発生すること。
 */
@Test
public void noSuchElement() throws Exception {
	openBasicTextPage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetById("notExists").build();

	if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) {
		expectedException.expect(NoSuchElementException.class);
	} else {
		expectedException.expect(AssertionError.class);
		expectedException.expectMessage("Invalid selector found");
	}
	assertionView.assertView(arg);
	fail();
}
 
Example #14
Source File: ExcludeElementInScrollTest.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * 要素内スクロールの撮影において、存在しない要素を指定して除外する。
 *
 * @ptl.expect エラーが発生せず、除外領域が保存されていないこと。
 */
@Test
public void excludeNotExistElement() throws Exception {
	assumeFalse("Skip IE8 table test.", isInternetExplorer8());
	assumeFalse("Skip IE9 table test.", isInternetExplorer9());

	openScrollPage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetByCssSelector("#table-scroll > tbody")
			.addExcludeById("not-exists").build();
	if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) {
		expectedException.expect(NoSuchElementException.class);
	}
	assertionView.assertView(arg);

	// Check
	TargetResult result = loadTargetResults("s").get(0);
	assertThat(result.getExcludes(), is(empty()));
}
 
Example #15
Source File: HideMultiElementsTest.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * 単体セレクタで複数の要素を指定して非表示にする。
 * 
 * @ptl.expect 非表示に指定した要素が写っていないこと。
 */
@Test
public void singleTarget() throws Exception {
	assumeFalse("Skip Safari hidden test.", BrowserType.SAFARI.equals(capabilities.getBrowserName()));
	openBasicColorPage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget()
			.addHiddenElementsByClassName("color-column").build();
	assertionView.assertView(arg);

	// Check
	// 特定の色のピクセルが存在しないこと
	BufferedImage image = loadTargetResults("s").get(0).getImage().get();
	int width = image.getWidth();
	int height = image.getHeight();
	for (int x = 0; x < width; x++) {
		for (int y = 0; y < height; y++) {
			Color actual = Color.valueOf(image.getRGB(x, y));
			assertThat(actual, is(not(anyOf(equalTo(Color.RED), equalTo(Color.GREEN), equalTo(Color.BLUE)))));
		}
	}
}
 
Example #16
Source File: AssumeCapabilityTest.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> parameters() {
	return parameters(capabilities(BrowserType.IE, "11.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.IE, "10.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.EDGE, null, Platform.WIN10, null, "pc"),
			capabilities(BrowserType.FIREFOX, "45.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.CHROME, "49.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.SAFARI, "9.1", Platform.EL_CAPITAN, null, "pc"),
			capabilities(BrowserType.CHROME, "49.0", Platform.ANDROID, "Nexus 6P", "mobile"),
			capabilities(BrowserType.SAFARI, "9.1", null, "iPhone6S", "mobile"),
			capabilities(BrowserType.SAFARI, "9.1", null, "iPad Air", "mobile"));
}
 
Example #17
Source File: AssumeCapabilityTest.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> parameters() {
	return parameters(capabilities(BrowserType.IE, "11.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.IE, "10.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.EDGE, null, Platform.WIN10, null, "pc"),
			capabilities(BrowserType.FIREFOX, "45.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.CHROME, "49.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.SAFARI, "9.1", Platform.EL_CAPITAN, null, "pc"),
			capabilities(BrowserType.CHROME, "49.0", Platform.ANDROID, "Nexus 6P", "mobile"),
			capabilities(BrowserType.SAFARI, "9.1", null, "iPhone6S", "mobile"),
			capabilities(BrowserType.SAFARI, "9.1", null, "iPad Air", "mobile"));
}
 
Example #18
Source File: AssumeCapabilityTest.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
@CapabilityFilters({
		@CapabilityFilter(filterGroup = "pc", browserName = BrowserType.IE),
		@CapabilityFilter(platform = Platform.WINDOWS, browserName = { BrowserType.FIREFOX, BrowserType.CHROME }) })
@Test
public void multipleFilters() throws Exception {
	assertAssumed(2, 5, 6, 7, 8);
}
 
Example #19
Source File: AbstractCapabilities.java    From carina with Apache License 2.0 5 votes vote down vote up
protected DesiredCapabilities initCapabilities(DesiredCapabilities capabilities) {
    // read all properties which starts from "capabilities.*" prefix and add them into desired capabilities.
    final String prefix = SpecialKeywords.CAPABILITIES + ".";
    @SuppressWarnings({ "unchecked", "rawtypes" })
    Map<String, String> capabilitiesMap = new HashMap(R.CONFIG.getProperties());
    for (Map.Entry<String, String> entry : capabilitiesMap.entrySet()) {
        if (entry.getKey().toLowerCase().startsWith(prefix)) {
            String value = R.CONFIG.get(entry.getKey());
            if (!value.isEmpty()) {
                String cap = entry.getKey().replaceAll(prefix, "");
                if ("false".equalsIgnoreCase(value)) {
                    LOGGER.debug("Set capabilities value as boolean: false");
                    capabilities.setCapability(cap, false);
                } else if ("true".equalsIgnoreCase(value)) {
                    LOGGER.debug("Set capabilities value as boolean: true");
                    capabilities.setCapability(cap, true);
                } else {
                    LOGGER.debug("Set capabilities value as string: " + value);
                    capabilities.setCapability(cap, value);
                }
            }
        }
    }
    capabilities.setCapability("carinaTestRunId", SpecialKeywords.TEST_RUN_ID);
    
    //TODO: [VD] reorganize in the same way Firefox profiles args/options if any and review other browsers
    // support customization for Chrome args and options
    String browser = Configuration.getBrowser();


    if (BrowserType.FIREFOX.equalsIgnoreCase(browser)) {
        capabilities = addFirefoxOptions(capabilities);
    } else if (BrowserType.CHROME.equalsIgnoreCase(browser)) {
        capabilities = addChromeOptions(capabilities);
    }
    
    return capabilities;
}
 
Example #20
Source File: EdgeCapabilities.java    From carina with Apache License 2.0 5 votes vote down vote up
public DesiredCapabilities getCapability(String testName) {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities = initBaseCapabilities(capabilities, BrowserType.EDGE, testName);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, false);
    
    //update browser language
    String browserLang = Configuration.get(Parameter.BROWSER_LANGUAGE); 
    if (!browserLang.isEmpty()) {
    	Assert.fail("Unable to change Edge locale via selenium! (" + browserLang + ")");
    }
    return capabilities;
}
 
Example #21
Source File: AssumeCapabilityTest.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> parameters() {
	return parameters(capabilities(BrowserType.IE, "11.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.IE, "10.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.EDGE, null, Platform.WIN10, null, "pc"),
			capabilities(BrowserType.FIREFOX, "45.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.CHROME, "49.0", Platform.VISTA, null, "pc"),
			capabilities(BrowserType.SAFARI, "9.1", Platform.EL_CAPITAN, null, "pc"),
			capabilities(BrowserType.CHROME, "49.0", Platform.ANDROID, "Nexus 6P", "mobile"),
			capabilities(BrowserType.SAFARI, "9.1", null, "iPhone6S", "mobile"),
			capabilities(BrowserType.SAFARI, "9.1", null, "iPad Air", "mobile"));
}
 
Example #22
Source File: CapabilitiesComparatorTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void matchesWithPreferenceToCurrentPlatform() {
  Capabilities chromeUnix = capabilities(BrowserType.CHROME, "", Platform.UNIX, true);
  Capabilities chromeVista = capabilities(BrowserType.CHROME, "", Platform.VISTA, true);
  Capabilities anyChrome = new DesiredCapabilities(BrowserType.CHROME, "", Platform.ANY);

  List<Capabilities> allCaps = asList(anyChrome, chromeVista, chromeUnix,
      // This last option should never match.
      new DesiredCapabilities(BrowserType.FIREFOX, "10", Platform.ANY));

  // Should match to corresponding platform.
  assertThat(getBestMatch(anyChrome, allCaps, Platform.UNIX)).isEqualTo(chromeUnix);
  assertThat(getBestMatch(chromeUnix, allCaps, Platform.UNIX)).isEqualTo(chromeUnix);

  assertThat(getBestMatch(anyChrome, allCaps, Platform.LINUX)).isEqualTo(chromeUnix);
  assertThat(getBestMatch(chromeUnix, allCaps, Platform.LINUX)).isEqualTo(chromeUnix);

  assertThat(getBestMatch(anyChrome, allCaps, Platform.VISTA)).isEqualTo(chromeVista);
  assertThat(getBestMatch(chromeVista, allCaps, Platform.VISTA)).isEqualTo(chromeVista);

  assertThat(getBestMatch(anyChrome, allCaps, Platform.WINDOWS)).isEqualTo(chromeVista);
  assertThat(getBestMatch(chromeVista, allCaps, Platform.WINDOWS)).isEqualTo(chromeVista);

  // No configs registered to current platform, should fallback to normal matching rules.
  assertThat(getBestMatch(anyChrome, allCaps, Platform.MAC)).isEqualTo(anyChrome);
  assertThat(getBestMatch(anyChrome, allCaps, Platform.XP)).isEqualTo(anyChrome);
}
 
Example #23
Source File: CapabilitiesComparatorTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void pickingWindowsFromVariousLists() {
  Capabilities any = capabilities(BrowserType.IE, "", Platform.ANY, true);
  Capabilities windows = capabilities(BrowserType.IE, "", Platform.WINDOWS, true);
  Capabilities xp = capabilities(BrowserType.IE, "", Platform.XP, true);
  Capabilities vista = capabilities(BrowserType.IE, "", Platform.VISTA, true);

  assertThat(getBestMatch(windows, singletonList(any))).isEqualTo(any);
  assertThat(getBestMatch(windows, asList(any, windows))).isEqualTo(windows);
  assertThat(getBestMatch(windows, asList(windows, xp, vista))).isEqualTo(windows);
  assertThat(getBestMatch(windows, asList(xp, vista))).isIn(xp, vista);
  assertThat(getBestMatch(windows, singletonList(xp))).isEqualTo(xp);
  assertThat(getBestMatch(windows, singletonList(vista))).isEqualTo(vista);
}
 
Example #24
Source File: WebDriverFactoryTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
private void testGetRemoteWebDriverIsChrome(ChromeOptions chromeOptions) throws Exception
{
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setBrowserName(BrowserType.CHROME);
    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    when(remoteWebDriverFactory.getRemoteWebDriver(URL.toURL(), desiredCapabilities)).thenReturn(remoteWebDriver);
    Timeouts timeouts = mockTimeouts(remoteWebDriver);
    assertEquals(remoteWebDriver,
            ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example #25
Source File: SingleScrollElementTest.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
/**
 * 要素内スクロールがあるTABLE要素を要素内スクロールオプションあり、移動オプションありを設定して撮影する。
 *
 * @ptl.expect スクリーンショット撮影結果が正しいこと。
 */
@Test
public void takeTableScreenshot_scroll_move() throws Exception {
	assumeFalse("Skip IE8 table test.", isInternetExplorer8());
	assumeFalse("Skip IE9 table test.", isInternetExplorer9());

	openScrollPage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetByCssSelector("#table-scroll > tbody")
			.scrollTarget(true).moveTarget(true).build();
	assertionView.assertView(arg);

	// Check
	double ratio = getPixelRatio();
	Rect rect = getPixelRectById("table-scroll");
	BufferedImage image = loadTargetResults("s").get(0).getImage().get();
	assertThat(image.getHeight(), is(greaterThan((int) rect.height)));

	int x = image.getWidth() / 2;
	int y = 0;
	int cellCount = 0;
	float cellHeight = 20;
	if (BrowserType.FIREFOX.equals(capabilities.getBrowserName())
			&& Platform.MAC.equals(capabilities.getPlatform())) {
		cellHeight = 20.45f;
	}
	while (cellCount <= 15) {
		Color expect = Color.valueOf(image.getRGB(0, (int) Math.round(cellCount * cellHeight * ratio)));
		cellCount++;
		int maxY = (int) Math.round(cellCount * cellHeight * ratio);
		while (y < maxY) {
			Color actual = Color.valueOf(image.getRGB(x, y));
			assertThat(String.format("Point (%d, %d) is not match.", x, y), actual, is(expect));
			y++;
		}
	}
}
 
Example #26
Source File: WebDriverManagerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testIsIpadIOSDevice()
{
    Map<String, Object> capabilities = Map.of(
            CapabilityType.PLATFORM_NAME, Platform.MAC.toString(),
            BROWSER_TYPE, BrowserType.IPAD
    );
    mockWebDriverHavingCapabilities(capabilities);
    assertTrue(webDriverManager.isIOS());
}
 
Example #27
Source File: CapabilitiesComparatorTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMatchByPlatform_assumingAllOtherPropertiesAreTheSame() {
  comparator = compareBy(capabilities(BrowserType.FIREFOX, "6", Platform.ANY, true));

  Capabilities c1 = capabilities(BrowserType.FIREFOX, "6", Platform.ANY, true);
  Capabilities c2 = capabilities(BrowserType.FIREFOX, "6", Platform.LINUX, true);

  assertGreaterThan(c1, c2);
}
 
Example #28
Source File: WebDriverManagerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testIsIOSDeviceFromInnerCapabilities()
{
    Map<String, String> map = Map.of(SauceLabsCapabilityType.DEVICE, BrowserType.IPHONE);
    mockWebDriverHavingCapabilities(Map.of(SauceLabsCapabilityType.CAPABILITIES, map));
    assertTrue(webDriverManager.isIOS());
}
 
Example #29
Source File: EdgeHtmlOptionsTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultOptions() {
  EdgeHtmlOptions options = new EdgeHtmlOptions();
  assertThat(options.asMap())
      .containsEntry(CapabilityType.BROWSER_NAME, BrowserType.EDGE)
      .containsEntry(EdgeHtmlOptions.USE_CHROMIUM, false);
}
 
Example #30
Source File: HideSingleElementTest.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
/**
 * 単体セレクタで存在しない要素を指定して非表示にする。
 * 
 * @ptl.expect エラーが発生しないこと。
 */
@Test
public void notExists() throws Exception {
	openBasicColorPage();

	ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().addHiddenElementsById("not-exists")
			.build();
	if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) {
		expectedException.expect(NoSuchElementException.class);
	}
	assertionView.assertView(arg);

	// エラーとならない
}