org.openqa.selenium.WebDriver.Options Java Examples
The following examples show how to use
org.openqa.selenium.WebDriver.Options.
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: WebDriverManagerTests.java From vividus with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource("nativeApplicationViewportProvider") void testGetScreenSizeForPortraitOrientation(ScreenOrientation orientation, Dimension dimension, Dimension viewport) { lenient().when(webDriverProvider.getUnwrapped(MobileDriver.class)).thenReturn(mobileDriver); lenient().when(webDriverProvider.getUnwrapped(Rotatable.class)).thenReturn(mobileDriver); when(mobileDriver.getOrientation()).thenReturn(orientation); when(mobileDriver.getContext()).thenReturn(NATIVE_APP_CONTEXT); WebDriverManager spy = spyIsMobile(true); Options options = mock(Options.class); when(mobileDriver.manage()).thenReturn(options); Window window = mock(Window.class); when(options.window()).thenReturn(window); when(window.getSize()).thenReturn(dimension); assertEquals(viewport, spy.getSize()); verify(webDriverManagerContext).putParameter(WebDriverManagerParameter.SCREEN_SIZE, dimension); }
Example #2
Source File: VividusWebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
private void runCreateTest(boolean remoteExecution, String browserName) throws Exception { vividusWebDriverFactory.setRemoteExecution(remoteExecution); vividusWebDriverFactory.setWebDriverEventListeners(List.of(webDriverEventListener)); when(bddRunContext.getRunningStory()).thenReturn(createRunningStory(browserName)); EventFiringWebDriver eventFiringWebDriver = mock(EventFiringWebDriver.class); PowerMockito.whenNew(EventFiringWebDriver.class).withArguments(driver).thenReturn(eventFiringWebDriver); Options options = mock(Options.class); when(eventFiringWebDriver.manage()).thenReturn(options); Window window = mock(Window.class); when(options.window()).thenReturn(window); when(eventFiringWebDriver.getCapabilities()).thenReturn(mock(Capabilities.class)); BrowserWindowSize windowSize = new BrowserWindowSize("1920x1080"); when(browserWindowSizeProvider.getBrowserWindowSize(remoteExecution)) .thenReturn(windowSize); VividusWebDriver vividusWebDriver = vividusWebDriverFactory.create(); assertEquals(eventFiringWebDriver, vividusWebDriver.getWrappedDriver()); verify(eventFiringWebDriver).register(webDriverEventListener); assertEquals(remoteExecution, vividusWebDriver.isRemote()); verify(webDriverManagerContext).reset(WebDriverManagerParameter.DESIRED_CAPABILITIES); verify(webDriverManager).resize(eventFiringWebDriver, windowSize); }
Example #3
Source File: WindowsActionsTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void testCloseAllWindowsExceptOneNotMobile() { when(webDriverProvider.get()).thenReturn(webDriver); Set<String> windows = new LinkedHashSet<>(List.of(WINDOW1, WINDOW2)); TargetLocator targetLocator = mock(TargetLocator.class); when(webDriver.getWindowHandles()).thenReturn(windows); when(webDriver.switchTo()).thenReturn(targetLocator); Options options = mock(Options.class); Window window = mock(Window.class); when(webDriver.manage()).thenReturn(options); when(options.window()).thenReturn(window); when(window.getSize()).thenAnswer(i -> new Dimension(DIMENSION_SIZE, DIMENSION_SIZE)); when(webDriverManager.isAndroid()).thenReturn(false); windowsActions.closeAllWindowsExceptOne(); verify(webDriver, times(1)).close(); }
Example #4
Source File: BrowserLogCleanningListenerTests.java From vividus with Apache License 2.0 | 6 votes |
@TestFactory Stream<DynamicTest> testCleanBeforeNavigate() { WebDriver driver = mock(WebDriver.class, withSettings().extraInterfaces(HasCapabilities.class)); Consumer<Runnable> test = methodUnderTest -> { Options options = mock(Options.class); when(driver.manage()).thenReturn(options); Logs logs = mock(Logs.class); when(options.logs()).thenReturn(logs); when(logs.get(LogType.BROWSER)).thenReturn(mock(LogEntries.class)); methodUnderTest.run(); }; return Stream.of( dynamicTest("beforeNavigateBack", () -> test.accept(() -> listener.beforeNavigateBack(driver))), dynamicTest("beforeNavigateForward", () -> test.accept(() -> listener.beforeNavigateForward(driver))), dynamicTest("beforeNavigateRefresh", () -> test.accept(() -> listener.beforeNavigateRefresh(driver))), dynamicTest("beforeNavigateTo", () -> test.accept(() -> listener.beforeNavigateTo("url", driver)))); }
Example #5
Source File: SeleniumEngine.java From phoenix.webui.framework with Apache License 2.0 | 6 votes |
/** * 关闭浏览器引擎 */ public void close() { if(driver != null) { Options manage = driver.manage(); boolean cookieSave = Boolean.parseBoolean(enginePro.getProperty("cookie.save", "false")); File root = PathUtil.getRootDir(); File cookieFile = new File(root, enginePro.getProperty("cookie.save.path", "phoenix.autotest.cookie")); if(cookieSave) { Set<Cookie> cookies = manage.getCookies(); try(ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(cookieFile))) { output.writeObject(cookies); } catch (IOException e) { logger.error("", e); } } driver.quit(); } }
Example #6
Source File: JsValidationStepsTests.java From vividus with Apache License 2.0 | 5 votes |
private LogEntry mockGetLogEntry(String logErrorMessage) { WebDriver webDriver = mock(WebDriver.class, withSettings().extraInterfaces(HasCapabilities.class)); when(webDriverProvider.get()).thenReturn(webDriver); when(webDriver.getCurrentUrl()).thenReturn(URL); Options options = mock(Options.class); when(webDriver.manage()).thenReturn(options); Logs logs = mock(Logs.class); when(options.logs()).thenReturn(logs); LogEntry severeEntry = new LogEntry(Level.SEVERE, 1L, logErrorMessage); LogEntry infoEntry = new LogEntry(Level.INFO, 1L, logErrorMessage); LogEntries logEntries = new LogEntries(Arrays.asList(severeEntry, infoEntry)); when(logs.get(LogType.BROWSER)).thenReturn(logEntries); return severeEntry; }
Example #7
Source File: AbstractJavascriptTest.java From keycloak with Apache License 2.0 | 5 votes |
public void assertLocaleCookie(String locale, WebDriver driver1, Object output, WebElement events) { waitForPageToLoad(); Options ops = driver1.manage(); Cookie cookie = ops.getCookieNamed("KEYCLOAK_LOCALE"); Assert.assertNotNull(cookie); Assert.assertEquals(locale, cookie.getValue()); }
Example #8
Source File: HasCookieMatcherTest.java From matchers-java with Apache License 2.0 | 5 votes |
@Test public void shouldNotFindUnexistingCookie() { final WebDriver driver = mock(WebDriver.class); Options options = mock(Options.class); when(driver.manage()).thenReturn(options); when(options.getCookieNamed(eq(cookieName))).thenReturn(null); assertThat("Cook should not be found", driver, not(hasCookie(cookieName))); }
Example #9
Source File: HasCookieMatcherTest.java From matchers-java with Apache License 2.0 | 5 votes |
@Test public void shouldFindExistingCookie() { WebDriver driver = mock(WebDriver.class); Options options = mock(Options.class); Cookie cookie = new Cookie(cookieName, "oki-doki"); when(driver.manage()).thenReturn(options); when(options.getCookieNamed(eq(cookieName))).thenReturn(cookie); assertThat("Cookie not found!", driver, hasCookie(cookieName)); }
Example #10
Source File: WebDriverBrowserTest.java From webtester-core with Apache License 2.0 | 5 votes |
private Window mockWindow() { Options options = mock(Options.class); doReturn(options).when(webDriver).manage(); Window window = mock(Window.class); doReturn(window).when(options).window(); return window; }
Example #11
Source File: KaptchaInvoker.java From phoenix.webui.framework with Apache License 2.0 | 5 votes |
/** * 获取验证码 * @param engine 引擎 * @param param 例如:data,http://localhost:8080/G2/captcha!getLastCode.do * @return 验证码 */ public static String execute(SeleniumEngine engine, String param) { WebDriver driver = engine.getDriver(); Options manage = driver.manage(); String[] paramArray = param.split(",", 2); if(paramArray.length != 2) { throw new RuntimeException("Param format is error, should be 'data,url'"); } String key = paramArray[0]; String url = paramArray[1]; Set<Cookie> cookies = manage.getCookies(); List<AtCookie> atCookieList = new ArrayList<AtCookie>(); for(Cookie cookie : cookies) { String name = cookie.getName(); String value = cookie.getValue(); AtCookie atCookie = new AtCookie(); atCookie.setName(name); atCookie.setValue(value); atCookie.setPath(cookie.getPath()); atCookie.setDomain(cookie.getDomain()); atCookieList.add(atCookie); } String code = HttpApiUtil.getJsonValue(url, atCookieList, key); return code; }
Example #12
Source File: AbstractDriver.java From coteafs-selenium with Apache License 2.0 | 5 votes |
protected void setupDriverOptions() { final PlaybackSetting playback = appSetting().getPlayback(); final DelaySetting delays = playback.getDelays(); manageTimeouts(t -> t.pageLoadTimeout(delays.getPageLoad(), SECONDS)); manageTimeouts(t -> t.setScriptTimeout(delays.getScriptLoad(), SECONDS)); manageTimeouts(t -> t.implicitlyWait(delays.getImplicit(), SECONDS)); manageOptions(Options::deleteAllCookies); setScreen(playback); }
Example #13
Source File: DelegatingWebDriverTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testManage() { Options options = Mockito.mock(Options.class); when(wrappedDriver.manage()).thenReturn(options); assertEquals(options, delegatingWebDriver.manage()); }
Example #14
Source File: BrowserLogManagerTests.java From vividus with Apache License 2.0 | 5 votes |
private static LogEntries mockLogRetrieval(WebDriver webDriver) { Options options = mock(Options.class); when(webDriver.manage()).thenReturn(options); Logs logs = mock(Logs.class); when(options.logs()).thenReturn(logs); when(options.logs()).thenReturn(logs); LogEntry severeEntry = new LogEntry(Level.SEVERE, 1L, ERROR_MESSAGE); LogEntry infoEntry = new LogEntry(Level.INFO, 1L, ERROR_MESSAGE); LogEntries logEntries = new LogEntries(Arrays.asList(severeEntry, infoEntry)); when(logs.get(LogType.BROWSER)).thenReturn(logEntries); return logEntries; }
Example #15
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 5 votes |
private static Timeouts mockTimeouts(WebDriver webDriver) { Options options = mock(Options.class); when(webDriver.manage()).thenReturn(options); Timeouts timeouts = mock(Timeouts.class); when(options.timeouts()).thenReturn(timeouts); return timeouts; }
Example #16
Source File: AbstractDriver.java From coteafs-selenium with Apache License 2.0 | 4 votes |
private void manageOptions(final Consumer<Options> options) { options.accept(getDriver().manage()); }
Example #17
Source File: CookieManager.java From vividus with Apache License 2.0 | 4 votes |
private Options getOptions() { return webDriverProvider.get().manage(); }
Example #18
Source File: AllureSelenideTest.java From allure-java with Apache License 2.0 | 4 votes |
@AllureFeatures.Attachments @Test void shouldSaveLogs() { final LogEntry logEntry = new LogEntry(Level.ALL, 10, "SIMPLE LOG"); final LogEntries logEntries = new LogEntries(Collections.singletonList(logEntry)); final ChromeDriver wdMock = mock(ChromeDriver.class); final Logs logsMock = mock(Logs.class); final Options optionsMock = mock(Options.class); WebDriverRunner.setWebDriver(wdMock); doReturn(optionsMock).when(wdMock).manage(); doReturn(logsMock).when(optionsMock).logs(); doReturn(logEntries).when(logsMock).get(LogType.BROWSER.toString()); final AllureResults results = runWithinTestContext(() -> { final AllureSelenide selenide = new AllureSelenide() .enableLogs(LogType.BROWSER, Level.ALL) .savePageSource(false) .screenshots(false); SelenideLogger.addListener(UUID.randomUUID().toString(), selenide); final SelenideLog log = SelenideLogger.beginStep( "dummy source", "dummyMethod()", "param1", "param2"); SelenideLogger.commitStep(log, new Exception("something went wrong")); }); final StepResult selenideStep = extractStepFromResults(results); final Attachment attachment = selenideStep.getAttachments().iterator().next(); final String attachmentContent = new String( results.getAttachments().get(attachment.getSource()), StandardCharsets.UTF_8 ); assertThat(selenideStep.getAttachments()).hasSize(1); assertThat(results.getAttachments()).containsKey(attachment.getSource()); assertThat(attachmentContent).isEqualTo(logEntry.toString()); }
Example #19
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 4 votes |
private Options mockOptions(WebDriver webDriver) { Options options = mock(Options.class); when(webDriver.manage()).thenReturn(options); return options; }