Java 类org.openqa.selenium.WebDriver.Options 实例源码

项目:phoenix.webui.framework    文件:SeleniumEngine.java   
/**
 * 关闭浏览器引擎
 */
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();
    }
}
项目:bootstrap    文件:TAbstractSeleniumTest.java   
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
    System.clearProperty("test.selenium.remote");
    localDriverClass = WebDriverMock.class.getName();
    remoteDriverClass = WebDriverMock.class.getName();
    scenario = "sc";
    super.prepareDriver();
    mockDriver = Mockito.mock(WebDriverMock.class);
    Mockito.when(mockDriver.getScreenshotAs(ArgumentMatchers.any(OutputType.class)))
            .thenReturn(new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
    final Options options = Mockito.mock(Options.class);
    Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
    Mockito.when(mockDriver.manage()).thenReturn(options);
    final WebElement webElement = Mockito.mock(WebElement.class);
    Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
    Mockito.when(webElement.isDisplayed()).thenReturn(true);
    this.driver = mockDriver;
}
项目:bootstrap    文件:TAbstractParallelSeleniumTest.java   
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
    testName = Mockito.mock(TestName.class);
    Mockito.when(testName.getMethodName()).thenReturn("mockTest");
    System.clearProperty("test.selenium.remote");
    localDriverClass = WebDriverMock.class.getName();
    remoteDriverClass = WebDriverMock.class.getName();
    scenario = "sc";
    super.prepareDriver();
    mockDriver = Mockito.mock(WebDriverMock.class);
    Mockito.when(((WebDriverMock) mockDriver).getScreenshotAs(ArgumentMatchers.any(OutputType.class))).thenReturn(
            new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
    final Options options = Mockito.mock(Options.class);
    Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
    Mockito.when(mockDriver.manage()).thenReturn(options);
    final WebElement webElement = Mockito.mock(WebElement.class);
    Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
    Mockito.when(webElement.isDisplayed()).thenReturn(true);
    this.driver = mockDriver;
}
项目:bootstrap    文件:TAbstractSequentialSeleniumTest.java   
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
    testName = Mockito.mock(TestName.class);
    Mockito.when(testName.getMethodName()).thenReturn("mockTest");
    System.clearProperty("test.selenium.remote");
    localDriverClass = WebDriverMock.class.getName();
    remoteDriverClass = WebDriverMock.class.getName();
    scenario = "sc";
    super.prepareDriver();
    mockDriver = Mockito.mock(WebDriverMock.class);
    Mockito.when(((WebDriverMock) mockDriver).getScreenshotAs(ArgumentMatchers.any(OutputType.class))).thenReturn(
            new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
    final Options options = Mockito.mock(Options.class);
    Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
    Mockito.when(mockDriver.manage()).thenReturn(options);
    final WebElement webElement = Mockito.mock(WebElement.class);
    Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
    Mockito.when(webElement.isDisplayed()).thenReturn(true);
    this.driver = mockDriver;
}
项目:bootstrap    文件:TAbstractRepeatableSeleniumTest.java   
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
    System.clearProperty("test.selenium.remote");
    localDriverClass = WebDriverMock.class.getName();
    remoteDriverClass = WebDriverMock.class.getName();
    scenario = "sc";
    super.prepareDriver();
    mockDriver = Mockito.mock(WebDriverMock.class);
    Mockito.when(mockDriver.getScreenshotAs(ArgumentMatchers.any(OutputType.class))).thenReturn(
            new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
    final Options options = Mockito.mock(Options.class);
    Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
    Mockito.when(mockDriver.manage()).thenReturn(options);
    final WebElement webElement = Mockito.mock(WebElement.class);
    Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
    Mockito.when(webElement.isDisplayed()).thenReturn(true);
    this.driver = mockDriver;
}
项目:phoenix.webui.framework    文件:KaptchaInvoker.java   
/**
 * 获取验证码
 * @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;
}
项目:webtester-core    文件:WebDriverBrowserTest.java   
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;
}
项目:automation-test-engine    文件:BaseATETest.java   
/**
 * Instantiates a new base ate test.
 */
public BaseATETest() {
    super();
    mockedDriver = ateMock(WebDriver.class);
    myMockedDriver = ateMock(IMyWebDriver.class);
    options = ateMock(Options.class);
    TestProjectRunner.registerXsdNameSpaceParsers();
    TestProjectRunner.registerProblemHandlers();
}
项目:qir    文件:AbstractWebITCase.java   
@Before
public void initData() {
    dataInitService.clear();
    dataInitService.init();
    webDriver = new PhantomJSDriver();
    final Options options = webDriver.manage();
    final Window window = options.window();
    window.setSize(new Dimension(1280, 800));
}
项目:matchers-java    文件:HasCookieMatcherTest.java   
@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));
}
项目:matchers-java    文件:HasCookieMatcherTest.java   
@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)));
}
项目:bootstrap    文件:TAbstractSeleniumTest.java   
@Test
public void testWaitFixedTime() {
    final Options options = mockDriver.manage();
    Mockito.when(options.timeouts()).thenReturn(Mockito.mock(Timeouts.class));
    waitFixedTime();
}
项目:jelenium    文件:CustomizeWebDriverOptions.java   
/**
 * Override this method to change {@link WebDriver} options before the test is run.
 */
@Override
public void manage( Options options ) {
   options.window().setSize( new Dimension( 640, 480 ) );
}
项目:automation-test-engine    文件:BaseATETest.java   
/**
 * @return the options
 */
public Options getOptions() {
    return options;
}
项目:liferay-blade-samples    文件:BladeSampleFunctionalActionUtil.java   
public static WebDriver implicitWait(WebDriver webDriver) {
    Options webDriverOptions = webDriver.manage();

    Timeouts timeouts = webDriverOptions.timeouts();

    timeouts.implicitlyWait(30, TimeUnit.SECONDS);

    return webDriver;
}
项目:jelenium    文件:JeleniumTest.java   
/**
 * This life-cycle callback gives you a chance to modify {@link WebDriver} {@link Options} before
 * the test starts.
 * 
 * @param options {@link WebDriver} options.
 */
default void manage( Options options ) {}
项目:easyium-java    文件:WebDriver.java   
/**
 * Gets the Option interface
 *
 * @return An option interface
 * @see Options
 */
public Options manage() {
    return seleniumWebDriver().manage();
}
项目:automation-test-engine    文件:BaseATETest.java   
/**
 * Gets the web driver manage.
 *
 * @return the web driver manage
 */
public Options getWebDriverManage() {
    return getOptions();
}