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); }
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); }
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(); } }
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(); } }
@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; }
@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; }
@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; }
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); }
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); }
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(); }
/** * 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(); }
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)); } }
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; }
@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)); }
@Test public void testThatMaximizingTheCurrentWindowInvokesCorrectWebDriverMethods() { Window window = mockWindow(); cut.maximizeCurrentWindow(); verify(window).maximize(); }
/** * <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()); }); }