...5import com.testpros.fast.reporter.Step;6import com.testpros.fast.reporter.Step.Status;7import io.github.bonigarcia.wdm.WebDriverManager;8import org.openqa.selenium.Dimension;9import org.openqa.selenium.NoSuchSessionException;10import org.openqa.selenium.Point;11import org.openqa.selenium.chrome.ChromeOptions;12import org.testng.annotations.BeforeMethod;13import org.testng.annotations.Test;14import static org.testng.Assert.*;15public class RemoteWindowIT extends FastTestBase {16 private final Dimension screenSize = new Dimension(600, 400);17 private final String dimensionSize = "(600, 400)";18 private final Point screenPosition = new Point(100, 100);19 private final String pointPosition = "(100, 100)";20 @Override21 @BeforeMethod22 public void setupDevice() {23 WebDriverManager.chromedriver().forceCache().setup();24 ChromeOptions chromeOptions = new ChromeOptions();25 drivers.set(new ChromeDriver(chromeOptions));26 }27 @Test28 public void setSizeTest() {29 WebDriver driver = drivers.get();30 Reporter reporter = driver.getReporter();31 driver.manage().window().setSize(screenSize);32 //assert window size is changed33 assertEquals(driver.manage().window().getSize(), screenSize);34 //assert reporter has proper information on screen size35 Step sizeStep = reporter.getSteps().get(1);36 assertEquals(sizeStep.getNumber(), 2);37 assertNotEquals(sizeStep.getTime(), 0.0);38 assertEquals(sizeStep.getAction(), "Setting window size to '" + dimensionSize + "'");39 assertEquals(sizeStep.getExpected(), "Window size changed");40 assertEquals(sizeStep.getActual(), "Window resized to '" + dimensionSize + "'");41 assertEquals(sizeStep.getStatus(), Status.PASS);42 assertNull(sizeStep.getRequest());43 assertNull(sizeStep.getResponse());44 assertNotNull(sizeStep.getScreenshot());45 }46 @Test(expectedExceptions = NoSuchSessionException.class)47 public void setSizeNoDriverTest() {48 WebDriver driver = drivers.get();49 Reporter reporter = driver.getReporter();50 driver.quit();51 try {52 driver.manage().window().setSize(screenSize);53 } finally {54 Step sizeStep = reporter.getSteps().get(2);55 assertEquals(sizeStep.getNumber(), 3);56 assertNotEquals(sizeStep.getTime(), 0.0);57 assertEquals(sizeStep.getAction(), "Setting window size to '" + dimensionSize + "'");58 assertEquals(sizeStep.getExpected(), "Window size changed");59 assertTrue(sizeStep.getActual().startsWith("Unable to resize the window: " +60 "org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?"));61 assertEquals(sizeStep.getStatus(), Status.FAIL);62 assertNull(sizeStep.getRequest());63 assertNull(sizeStep.getResponse());64 assertNull(sizeStep.getScreenshot());65 }66 }67 @Test68 public void setPositionTest() {69 WebDriver driver = drivers.get();70 Reporter reporter = driver.getReporter();71 driver.manage().window().setPosition(screenPosition);72 //assert window size is changed73 assertEquals(driver.manage().window().getPosition(), screenPosition);74 //assert reporter has proper information on screen size75 Step sizeStep = reporter.getSteps().get(1);76 assertEquals(sizeStep.getNumber(), 2);77 assertNotEquals(sizeStep.getTime(), 0.0);78 assertEquals(sizeStep.getAction(), "Setting window position to '" + pointPosition + "'");79 assertEquals(sizeStep.getExpected(), "Window position changed");80 assertEquals(sizeStep.getActual(), "Window moved to '" + pointPosition + "'");81 assertEquals(sizeStep.getStatus(), Status.PASS);82 assertNull(sizeStep.getRequest());83 assertNull(sizeStep.getResponse());84 assertNotNull(sizeStep.getScreenshot());85 }86 @Test(expectedExceptions = NoSuchSessionException.class)87 public void setPositionNoDriverTest() {88 WebDriver driver = drivers.get();89 Reporter reporter = driver.getReporter();90 driver.quit();91 driver.manage().window().setPosition(screenPosition);92 //assert window size is changed93 assertEquals(driver.manage().window().getPosition(), screenPosition);94 //assert reporter has proper information on screen size95 Step sizeStep = reporter.getSteps().get(2);96 assertEquals(sizeStep.getNumber(), 3);97 assertNotEquals(sizeStep.getTime(), 0.0);98 assertEquals(sizeStep.getAction(), "Setting window position to '" + pointPosition + "'");99 assertEquals(sizeStep.getExpected(), "Window position changed");100 assertTrue(sizeStep.getActual().startsWith("Unable to moved the window: " +101 "org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?"));102 assertEquals(sizeStep.getStatus(), Status.FAIL);103 assertNull(sizeStep.getRequest());104 assertNull(sizeStep.getResponse());105 assertNull(sizeStep.getScreenshot());106 }107 @Test108 public void getSizeTest() {109 WebDriver driver = drivers.get();110 Reporter reporter = driver.getReporter();111 driver.manage().window().setSize(screenSize);112 assertEquals(driver.manage().window().getSize(), screenSize);113 //assert reporter doesn't show getter information114 assertEquals(reporter.getSteps().size(), 2);115 }116 @Test117 public void getPositionTest() {118 WebDriver driver = drivers.get();119 Reporter reporter = driver.getReporter();120 driver.manage().window().setPosition(screenPosition);121 assertEquals(driver.manage().window().getPosition(), screenPosition);122 //assert reporter doesn't show getter information123 assertEquals(reporter.getSteps().size(), 2);124 }125 @Test126 public void maximizeTest() {127 WebDriver driver = drivers.get();128 Reporter reporter = driver.getReporter();129 Dimension originalSize = driver.manage().window().getSize();130 driver.manage().window().maximize();131 //assert window size is changed132 assertNotEquals(driver.manage().window().getSize(), originalSize);133 //assert reporter has proper information on screen size134 Step sizeStep = reporter.getSteps().get(1);135 assertEquals(sizeStep.getNumber(), 2);136 assertNotEquals(sizeStep.getTime(), 0.0);137 assertEquals(sizeStep.getAction(), "Maximizing the window");138 assertEquals(sizeStep.getExpected(), "Window maximized");139 assertTrue(sizeStep.getActual().startsWith("Window maximized with new size of '"));140 assertEquals(sizeStep.getStatus(), Status.PASS);141 assertNull(sizeStep.getRequest());142 assertNull(sizeStep.getResponse());143 assertNotNull(sizeStep.getScreenshot());144 }145 @Test(expectedExceptions = NoSuchSessionException.class)146 public void maximizeNoDriverTest() {147 WebDriver driver = drivers.get();148 Reporter reporter = driver.getReporter();149 driver.quit();150 try {151 driver.manage().window().maximize();152 } finally {153 Step sizeStep = reporter.getSteps().get(2);154 assertEquals(sizeStep.getNumber(), 3);155 assertNotEquals(sizeStep.getTime(), 0.0);156 assertEquals(sizeStep.getAction(), "Maximizing the window");157 assertEquals(sizeStep.getExpected(), "Window maximized");158 assertTrue(sizeStep.getActual().startsWith("Unable to maximize the window: " +159 "org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?"));160 assertEquals(sizeStep.getStatus(), Status.FAIL);161 assertNull(sizeStep.getRequest());162 assertNull(sizeStep.getResponse());163 assertNull(sizeStep.getScreenshot());164 }165 }166 @Test167 public void fullscreenTest() {168 WebDriver driver = drivers.get();169 Reporter reporter = driver.getReporter();170 Dimension originalSize = driver.manage().window().getSize();171 driver.manage().window().fullscreen();172 //assert window size is changed173 assertNotEquals(driver.manage().window().getSize(), originalSize);174 //assert reporter has proper information on screen size175 Step sizeStep = reporter.getSteps().get(1);176 assertEquals(sizeStep.getNumber(), 2);177 assertNotEquals(sizeStep.getTime(), 0.0);178 assertEquals(sizeStep.getAction(), "Setting the window to fullscreen");179 assertEquals(sizeStep.getExpected(), "Window set to fullscreen");180 assertTrue(sizeStep.getActual().startsWith("Window at fullscreen with new size of '"));181 assertEquals(sizeStep.getStatus(), Status.PASS);182 assertNull(sizeStep.getRequest());183 assertNull(sizeStep.getResponse());184 assertNotNull(sizeStep.getScreenshot());185 }186 @Test(expectedExceptions = NoSuchSessionException.class)187 public void fullscreenNoDriverTest() {188 WebDriver driver = drivers.get();189 Reporter reporter = driver.getReporter();190 driver.quit();191 try {192 driver.manage().window().fullscreen();193 } finally {194 Step sizeStep = reporter.getSteps().get(2);195 assertEquals(sizeStep.getNumber(), 3);196 assertNotEquals(sizeStep.getTime(), 0.0);197 assertEquals(sizeStep.getAction(), "Setting the window to fullscreen");198 assertEquals(sizeStep.getExpected(), "Window set to fullscreen");199 assertTrue(sizeStep.getActual().startsWith("Unable to set the window to fullscreen: " +200 "org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?"));201 assertEquals(sizeStep.getStatus(), Status.FAIL);202 assertNull(sizeStep.getRequest());203 assertNull(sizeStep.getResponse());204 assertNull(sizeStep.getScreenshot());205 }206 }207}...