private WebDriver getWebClient(int portForJSCoverProxy) { Proxy proxy = new Proxy().setHttpProxy("localhost:" + portForJSCoverProxy); DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(CapabilityType.PROXY, proxy); caps.setJavascriptEnabled(true); caps.setBrowserName(BrowserType.HTMLUNIT); return new HtmlUnitDriver(caps) { @Override protected WebClient modifyWebClient(WebClient client) { client.setScriptPreProcessor((htmlPage, sourceCode, sourceName, lineNumber, htmlElement) -> { if(removeJsSnippets != null && !removeJsSnippets.isEmpty()) { for(String toReplace : removeJsSnippets) { sourceCode = sourceCode.replace(toReplace, ""); } return sourceCode; } else { return sourceCode; } }); return client; } }; }
/** * 存在しない要素を除外する。 * * @ptl.expect エラーが発生せず、除外領域が保存されていないこと。 */ @Test public void noSuchElement() throws Exception { openBasicColorPage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().addExcludeById("noSuchElement").build(); if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) { expectedException.expect(NoSuchElementException.class); } assertionView.assertView(arg); // Check List<ScreenAreaResult> excludes = loadTargetResults("s").get(0).getExcludes(); assertThat(excludes, is(empty())); }
/** * 複数のスクリーンショット撮影時に、そのいずれかで存在しない要素を除外する。 * * @ptl.expect エラーが発生せず、存在する要素の除外領域が保存されていること。 */ @Test public void noSuchElementInMultiTargets() throws Exception { openBasicColorPage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().addExcludeById("container") .addNewTarget().addExcludeById("noSuchElement").build(); if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) { expectedException.expect(NoSuchElementException.class); } assertionView.assertView(arg); // Check List<TargetResult> results = loadTargetResults("s"); assertThat(results, hasSize(2)); assertThat(results.get(0).getExcludes(), hasSize(1)); assertThat(results.get(1).getExcludes(), is(empty())); }
/** * 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))); } } }
/** * 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))); } } }
/** * 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())); }
/** * 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())); }
/** * 存在しない要素を指定して撮影する。 * * @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(); }
/** * 存在しない要素を含む条件を指定して撮影する。 * * @ptl.expect AssertionErrorが発生すること。 */ @Test public void noSuchElementInMultiTarget() throws Exception { openBasicTextPage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetById("container") // exists .addNewTargetById("notExists") // not exists .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(); }
/** * 要素内スクロールの撮影において、存在しない要素を指定して除外する。 * * @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())); }
/** * 単体セレクタで複数の要素を指定して非表示にする。 * * @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))))); } } }
/** * 複数セレクタで複数の要素を指定して非表示にする。 * * @ptl.expect 非表示に指定した要素が写っていないこと。 */ @Test public void multiTargets() throws Exception { assumeFalse("Skip Safari hidden test.", BrowserType.SAFARI.equals(capabilities.getBrowserName())); openBasicColorPage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().addHiddenElementsById("colorColumn0") .addHiddenElementsById("colorColumn1").addHiddenElementsById("colorColumn2").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))))); } } }
/** * 複数セレクタで複数の要素を指定して非表示にするが、そのうちのいずれかは存在しない要素である。 * * @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))))); } } }
/** * 単体セレクタで単一要素を指定して非表示にする。 * * @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().addHiddenElementsById("colorColumn0") .build(); assertionView.assertView(arg); // Check // 特定の色のピクセルが存在しないこと BufferedImage image = loadTargetResults("s").get(0).getImage().get(); int width = image.getWidth(); int height = image.getHeight(); Color hiddenColor = Color.RED; 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))); } } }
/** * 比較時に対象の要素を削除して比較する。 * * @ptl.expect AssertionErrorが発生すること。 */ @Test public void compareElementNotExists() throws Exception { openBasicTextPage(); if (isRunTest()) { driver.executeJavaScript("" + "var parent = document.getElementById('textRow');" + "var child = document.getElementById('textColumn0');" + "parent.removeChild(child);"); } ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetById("textColumn0").build(); if (isRunTest()) { if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) { expectedException.expect(NoSuchElementException.class); } else { expectedException.expect(AssertionError.class); } assertionView.assertView(arg); fail(); return; } assertionView.assertView(arg); }
public static LocalRobotizedBrowserFactory createRobotizedWebDriverFactory(String browser) { if (BrowserType.FIREFOX.equalsIgnoreCase(browser)) { FirefoxProfile firefoxProfile = null; String firefoxProfileProperty = System.getProperty("webdriver.firefox.profile"); if (firefoxProfileProperty == null) { ProfilesIni allProfiles = new ProfilesIni(); // Use the default profile to make extensions available, // and especially to ease debugging with Firebug firefoxProfile = allProfiles.getProfile("default"); } return new LocalFirefox(firefoxProfile); } else if (BrowserType.SAFARI.equalsIgnoreCase(browser)) { return new LocalSafari(); } else if (BrowserType.CHROME.equalsIgnoreCase(browser)) { return new LocalBrowser<ChromeDriver>(ChromeDriver.class); } else if ("chrome-debug".equalsIgnoreCase(browser)) { return new LocalDebuggableChrome(); } else if (BrowserType.IE.equalsIgnoreCase(browser)) { return new LocalBrowser<InternetExplorerDriver>(InternetExplorerDriver.class); } else { throw new RuntimeException("Unknown browser value: " + browser); } }
/** * Tested method: isCurrentlyOnPage Test idea: Open a page, then call the * method. No assertion expected Parameters: Variations in the URL path * regarding slashes * * @throws IOException */ @Test public void testIsCurrentlyOnPage_sameWithSlashDifference() throws IOException { String browser = SenBotContext.getSenBotContext().getSeleniumManager().getAssociatedTestEnvironment().getBrowser(); if(BrowserType.PHANTOMJS.equals(browser)) { log.warn("PhantomJS webdrver GhostDriver does not seem to play well with fetching the current url"); } else { String testPagesFolder = "/test_pages"; String expected = SenBotContext.getSenBotContext().getRuntimeResources() + testPagesFolder; if (expected.contains("\\")) { expected = expected.replaceAll("\\\\", "/"); } if (expected.startsWith("/")) { expected = expected.replaceFirst("/", ""); } expected = "file:///" + expected; seleniumNavigationService.navigate_to_url(SenBotContext.RESOURCE_LOCATION_PREFIX + testPagesFolder + "/"); seleniumNavigationService.isCurrentlyOnPage(expected); seleniumNavigationService.navigate_to_url(SenBotContext.RESOURCE_LOCATION_PREFIX + testPagesFolder); seleniumNavigationService.isCurrentlyOnPage(expected + "/"); } }
public DesiredCapabilities getCapabilities(String name) { String browser = Configuration.get(Parameter.BROWSER); 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 { throw new RuntimeException("Unsupported browser: " + browser); } }
public DesiredCapabilities getCapability(String testName) { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities = initBaseCapabilities(capabilities, BrowserType.CHROME, testName); capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized", "--ignore-ssl-errors")); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, false); ChromeOptions options = new ChromeOptions(); options.addArguments("test-type"); if (Configuration.getBoolean(Configuration.Parameter.AUTO_DOWNLOAD)) { HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); chromePrefs.put("download.prompt_for_download", false); chromePrefs.put("download.default_directory", ReportContext.getArtifactsFolder().getAbsolutePath()); chromePrefs.put("plugins.always_open_pdf_externally", true); options.setExperimentalOption("prefs", chromePrefs); } capabilities.setCapability(ChromeOptions.CAPABILITY, options); return capabilities; }
public ChromeDesiredCapabilities() { super(BrowserType.ANDROID, "", Platform.ANDROID); prefs = new HashMap<String, Object>(); options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); setCapability(ChromeOptions.CAPABILITY, options); }
@Test public void returnsChromeLocatorIfSet() { initQueryObject(); Query query = new Query(DEFAULT_LOCATOR); query.addAlternateLocator(BrowserType.GOOGLECHROME, CHROME_LOCATOR); assertThat(query.locator()).isEqualTo(CHROME_LOCATOR); }
@Test public void returnsDefaultLocatorIfDifferentBrowserIsSet() { initQueryObject(); Query query = new Query(DEFAULT_LOCATOR); query.addAlternateLocator(BrowserType.FIREFOX, FIREFOX_LOCATOR); assertThat(query.locator()).isEqualTo(DEFAULT_LOCATOR); }
private void initQueryObject() { Capabilities mockedCapabilities = mock(Capabilities.class); when(mockedCapabilities.getBrowserName()).thenReturn(BrowserType.GOOGLECHROME); when(mockedCapabilities.getPlatform()).thenReturn(Platform.YOSEMITE); RemoteWebDriver mockedWebDriver = mock(RemoteWebDriver.class); when(mockedWebDriver.getCapabilities()).thenReturn(mockedCapabilities); when(mockedWebDriver.findElement(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_FOR_DEFAULT); when(mockedWebDriver.findElements(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_LIST_FOR_DEFAULT); Query.initQueryObjects(mockedWebDriver); }
private void initQueryWithGenericAutomationNameObject() { Capabilities mockedCapabilities = mock(Capabilities.class); when(mockedCapabilities.getBrowserName()).thenReturn(BrowserType.GOOGLECHROME); when(mockedCapabilities.getPlatform()).thenReturn(Platform.YOSEMITE); when(mockedCapabilities.getCapability("automationName")).thenReturn("Generic"); RemoteWebDriver mockedWebDriver = mock(RemoteWebDriver.class); when(mockedWebDriver.getCapabilities()).thenReturn(mockedCapabilities); when(mockedWebDriver.findElement(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_FOR_DEFAULT); when(mockedWebDriver.findElements(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_LIST_FOR_DEFAULT); Query.initQueryObjects(mockedWebDriver); }
@Override protected DeploymentUnit createDeploymentUnit() { String browserName = desiredCapabilities.getBrowserName(); logger.info("Selenium browser: {}", browserName); String image; switch (browserName) { case BrowserType.CHROME: image = CHROME_IMAGE; break; case BrowserType.FIREFOX: image = FIREFOX_IMAGE; break; case BrowserType.PHANTOMJS: image = PHANTOMJS_IMAGE; break; default: throw new UnsupportedOperationException("Provided browser type '" + browserName + "' is not supported"); } DeploymentUnit.Builder builder = new DockerDeploymentUnit.Builder("selenium", image) .withCpu(1) .withMem(1024) .withHealthProbe(new HttpProbe.Builder() .withPath(SERVER_PATH) .withPort(SELENIUM_PORT) .build()) .withPort(new DeploymentPort.Builder("selenium-server", SELENIUM_PORT) .build()) .withPort(new DeploymentPort.Builder("vnc-server", VNC_PORT) .build()); if (dimension != null) { builder.withEnvVar("SCREEN_WIDTH", String.valueOf(dimension.getWidth())) .withEnvVar("SCREEN_HEIGHT", String.valueOf(dimension.getHeight())); } return builder.build(); }
public void init() throws IOException { String target = System.getProperty("target", "local"); properties.load(new FileReader(new File(String.format("src/test/resources/%s.properties", target)))); dbHelper = new DbHelper(); if ("".equals(properties.getProperty("selenium.server"))) { if (browserType.equals(BrowserType.FIREFOX)) { wd = new FirefoxDriver(); } else if (browserType.equals(BrowserType.CHROME)) { wd = new ChromeDriver(); } } else { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName(browserType); capabilities.setPlatform(Platform.fromString(System.getProperty("platform", "Linux"))); wd = new RemoteWebDriver(new URL(properties.getProperty("selenium.server")), capabilities); } wd.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); wd.get(properties.getProperty("web.baseUri")); contactHelper = new ContactHelper(wd, this); groupHelper = new GroupHelper(wd, this); navigationHelper = new NavigationHelper(wd, this); sessionHelper = new SessionHelper(wd, this); sessionHelper.login(properties.getProperty("web.adminLogin"), properties.getProperty("web.adminPass")); if (Boolean.getBoolean("verifyUI")) { log().warn("verifyUI is set. Tests could run slow!"); } }
@Test public void testCanInstantiateAndDismissAStandardDriverByName() { WebDriver driver = factory.getDriver(BrowserType.HTMLUNIT); assertThat(driver, instanceOf(HtmlUnitDriver.class)); assertFalse(factory.isEmpty()); factory.dismissDriver(driver); assertTrue(factory.isEmpty()); }
public void init() throws IOException { String target = System.getProperty("target", "local"); properties.load(new FileReader(new File(String.format("src/test/resources/%s.properties", target)))); dbHelper = new DbHelper(); if ("".equals(properties.getProperty("selenium.server"))) { if (browser.equals(BrowserType.FIREFOX)) { wd = new FirefoxDriver(); } else if (browser.equals(BrowserType.CHROME)) { wd = new ChromeDriver(); } else if (browser.equals(BrowserType.IE)) { wd = new InternetExplorerDriver(); } } else { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName(browser); capabilities.setPlatform(Platform.fromString(System.getProperty("platform", "win7"))); wd = new RemoteWebDriver(new URL(properties.getProperty("selenium.server")), capabilities); } wd.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); wd.get(properties.getProperty("web.baseUrl")); groupHelper = new GroupHelper(wd); contactHelper = new ContactHelper(wd); navigationHelper = new NavigationHelper(wd); sessionHelper = new SessionHelper(wd); sessionHelper.login(properties.getProperty("web.adminLogin"), properties.getProperty("web.adminPassword")); }
public static String getImageForCapabilities(DesiredCapabilities desiredCapabilities) { String seleniumVersion = SeleniumUtils.determineClasspathSeleniumVersion(); String browserName = desiredCapabilities.getBrowserName(); switch (browserName) { case BrowserType.CHROME: return String.format(CHROME_IMAGE, seleniumVersion); case BrowserType.FIREFOX: return String.format(FIREFOX_IMAGE, seleniumVersion); default: throw new UnsupportedOperationException("Browser name must be 'chrome' or 'firefox'; provided '" + browserName + "' is not supported"); } }
/** * BODYを撮影する際に、IFRAME内の存在しない要素を非表示に設定する。 * * @ptl.expect エラーが発生しないこと。 */ @Test public void captureBody_hiddenNotExistElement() throws Exception { openIFramePage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().moveTarget(true).scrollTarget(false) .addHiddenElementsByClassName("not-exists").inFrameByClassName("content").build(); if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) { expectedException.expect(NoSuchElementException.class); } assertionView.assertView(arg); // エラーにならない assertTrue(true); }
/** * IFRAMEを撮影する際に、IFRAME内の存在しない要素を非表示に設定する。 * * @ptl.expect エラーが発生しないこと。 */ @Test public void captureIFrame_hiddenNotExistElement() throws Exception { openIFramePage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetByClassName("content").moveTarget(true) .scrollTarget(true).addHiddenElementsByClassName("not-exists").inFrameByClassName("content").build(); if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) { expectedException.expect(NoSuchElementException.class); } assertionView.assertView(arg); // エラーにならない assertTrue(true); }
/** * 要素内スクロールがある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++; } } }
/** * 要素内スクロール、マージンがあるTABLE要素を要素内スクロールオプションあり、移動オプションありを設定して撮影する。 * * @ptl.expect スクリーンショット撮影結果が正しいこと。 */ @Test public void marginTableElement() throws Exception { openScrollPage(); WebElement target = driver.findElementByCssSelector("#table-scroll > tbody"); setMarginTo(target); 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 - 200 * ratio)))); 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) { int color = cellCount * 16; Color expect = Color.rgb(color, color, color); 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++; } } }
/** * 単体セレクタで存在しない要素を指定して非表示にする。 * * @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); // エラーとならない }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> parameters() { return parameters(capabilities(BrowserType.IE, null, null), capabilities(BrowserType.EDGE, null, Platform.WIN10), capabilities(BrowserType.FIREFOX, null, Platform.WINDOWS), capabilities(BrowserType.SAFARI, null, Platform.MAC), capabilities(BrowserType.CHROME, null, Platform.ANDROID)); }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> parameters() { return parameters(capabilities(BrowserType.IE, null, null, null, null), capabilities(BrowserType.CHROME, null, null, "Nexus 6P", null), capabilities(BrowserType.CHROME, null, null, "Nexus 5X", null), capabilities(BrowserType.CHROME, null, null, "Xperia Z5", null)); }
@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")); }
@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); }