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

项目:marathonv5    文件:JavaDriverTest.java   
public void windowSetSize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Dimension actual = window.getSize();
    AssertJUnit.assertNotNull(actual);
    java.awt.Dimension expected = EventQueueWait.call(frame, "getSize");
    AssertJUnit.assertEquals(expected.width, actual.width);
    AssertJUnit.assertEquals(expected.height, actual.height);
    window.setSize(new Dimension(expected.width * 2, expected.height * 2));
    actual = window.getSize();
    AssertJUnit.assertEquals(expected.width * 2, actual.width);
    AssertJUnit.assertEquals(expected.height * 2, actual.height);
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowSetPosition() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Point actual = window.getPosition();
    AssertJUnit.assertNotNull(actual);
    java.awt.Point expected = EventQueueWait.call(frame, "getLocation");
    AssertJUnit.assertEquals(expected.x, actual.x);
    AssertJUnit.assertEquals(expected.y, actual.y);
    window.setPosition(new Point(expected.x + 10, expected.y + 10));
    actual = window.getPosition();
    AssertJUnit.assertEquals(expected.x + 10, actual.x);
    AssertJUnit.assertEquals(expected.y + 10, actual.y);
}
项目:marathonv5    文件:JavaDriverTest.java   
public void nonFrameDialogWindowUsesNameIfExistsAsTitle() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setVisible(true);
            window = new java.awt.Window(frame);
            window.setName("awt-window");
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JTextField(80));
            window.setLayout(new BorderLayout());
            window.add(panel, BorderLayout.CENTER);
            window.setSize(640, 480);
            window.setLocationRelativeTo(frame);
            window.requestFocus();
            window.setVisible(true);
        }
    });
    try {
        Thread.sleep(200);
        AssertJUnit.assertEquals("awt-window", driver.getTitle());
    } finally {
        window.dispose();
    }
}
项目:marathonv5    文件:JavaDriverTest.java   
public void nonFrameDialogWindowUsesClassNameAsTitleOnLastResort() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setVisible(true);
            window = new java.awt.Window(frame);
            window.setName(null);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JTextField(80));
            window.setLayout(new BorderLayout());
            window.add(panel, BorderLayout.CENTER);
            window.setSize(640, 480);
            window.setLocationRelativeTo(frame);
            window.requestFocus();
            window.setVisible(true);
        }
    });
    try {
        Thread.sleep(200);
        AssertJUnit.assertEquals("java.awt.Window", driver.getTitle());
    } finally {
        window.dispose();
    }
}
项目: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;
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowSize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Dimension actual = window.getSize();
    AssertJUnit.assertNotNull(actual);
    java.awt.Dimension expected = EventQueueWait.call(frame, "getSize");
    AssertJUnit.assertEquals(expected.width, actual.width);
    AssertJUnit.assertEquals(expected.height, actual.height);
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowPosition() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Point actual = window.getPosition();
    AssertJUnit.assertNotNull(actual);
    java.awt.Point expected = EventQueueWait.call(frame, "getLocation");
    AssertJUnit.assertEquals(expected.x, actual.x);
    AssertJUnit.assertEquals(expected.y, actual.y);
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowMaximize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    window.maximize();
}
项目:willtest    文件:DefaultFirefoxConfigurationParticipant.java   
/**
 * Moves window to the first display, and maximizes there.
 * This is practical in case of local testing.
 *
 * @see WebDriverConfigurationParticipant#postConstruct(WebDriver)
 */
@Override
public void postConstruct(D webDriver) {
    Window window = webDriver.manage().window();
    Dimension dimension = new Dimension(1920, 1080);
    Point thisPointIsAlwaysOnFirstDisplay = new Point(0, 0);
    window.setPosition(thisPointIsAlwaysOnFirstDisplay);
    window.setSize(dimension);
    window.maximize();
}
项目:aet    文件:ResolutionModifier.java   
private void setResolution(WebDriver webDriver) {
  Window window = webDriver.manage().window();
  if (maximize) {
    window.maximize();
    LOG.error("Trying to maximise window to  {}x{}!", window.getSize().getWidth(),
        window.getSize().getHeight());
  } else {
    LOG.info("Setting resolution to  {}x{}  ", width, height);
    window.setSize(new Dimension(width, height));
  }
}
项目: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;
}
项目: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));
}
项目:webtester-core    文件:WebDriverBrowserTest.java   
@Test
public void testThatMaximizingTheCurrentWindowInvokesCorrectWebDriverMethods() {
    Window window = mockWindow();
    cut.maximizeCurrentWindow();
    verify(window).maximize();
}
项目:fitnesse-selenium-slim    文件:SeleniumFixture.java   
/**
 * <p>
 * <code>
 * | window maximize |
 * </code>
 * </p>
 * Resize currently selected window to take up the entire screen
 *
 * @return the window size after maximizing
 */
public String windowMaximize() {
    return SeleniumFixture.WEB_DRIVER.getWhenAvailable(StringUtils.EMPTY, (driver, parsedLocator) -> {
        Window window = driver.manage().window();
        window.maximize();
        return this.fitnesseMarkup.formatWidthAndHeight(window.getSize().getWidth(), window.getSize().getHeight());
    });
}