|
| 1 | +package dev.selenium.bidirectional.webdriver_bidi.user_context; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.AfterEach; |
| 4 | +import org.junit.jupiter.api.Assertions; |
| 5 | +import org.junit.jupiter.api.BeforeEach; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | +import org.openqa.selenium.By; |
| 8 | +import org.openqa.selenium.WebDriver; |
| 9 | +import org.openqa.selenium.WebElement; |
| 10 | +import org.openqa.selenium.firefox.FirefoxDriver; |
| 11 | +import org.openqa.selenium.firefox.FirefoxOptions; |
| 12 | + |
| 13 | +class MultipleInstanceParallelTest { |
| 14 | + |
| 15 | + private WebDriver driver; |
| 16 | + |
| 17 | + @BeforeEach |
| 18 | + public void setup() { |
| 19 | + FirefoxOptions options = new FirefoxOptions(); |
| 20 | + options.setCapability("webSocketUrl", true); |
| 21 | + options.addArguments("-private"); |
| 22 | + driver = new FirefoxDriver(options); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + void canSwitchToBlue() { |
| 27 | + driver.get("https://www.selenium.dev/selenium/web/cookie-background.html"); |
| 28 | + |
| 29 | + WebElement body = driver.findElement(By.tagName("body")); |
| 30 | + String bgColor = body.getCssValue("background-color"); |
| 31 | + |
| 32 | + String expectedColor = "rgb(255, 255, 255)"; |
| 33 | + // Background color is white |
| 34 | + Assertions.assertEquals(bgColor, expectedColor); |
| 35 | + |
| 36 | + driver.get("https://www.selenium.dev/selenium/web/cookie-background.html"); |
| 37 | + |
| 38 | + driver.findElement(By.id("blue-btn")).click(); |
| 39 | + body = driver.findElement(By.tagName("body")); |
| 40 | + bgColor = body.getCssValue("background-color"); |
| 41 | + |
| 42 | + expectedColor = "rgb(173, 216, 230)"; |
| 43 | + // Background color is blue |
| 44 | + Assertions.assertEquals(bgColor, expectedColor); |
| 45 | + |
| 46 | + System.out.println( |
| 47 | + Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1] |
| 48 | + .getMethodName() + " => executed successfully"); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + void canSwitchToGreen() { |
| 53 | + driver.get("https://www.selenium.dev/selenium/web/cookie-background.html"); |
| 54 | + |
| 55 | + WebElement body = driver.findElement(By.tagName("body")); |
| 56 | + String bgColor = body.getCssValue("background-color"); |
| 57 | + |
| 58 | + String expectedColor = "rgb(255, 255, 255)"; |
| 59 | + Assertions.assertEquals(bgColor, expectedColor); |
| 60 | + |
| 61 | + driver.findElement(By.id("green-btn")).click(); |
| 62 | + body = driver.findElement(By.tagName("body")); |
| 63 | + bgColor = body.getCssValue("background-color"); |
| 64 | + |
| 65 | + expectedColor = "rgb(144, 238, 144)"; |
| 66 | + Assertions.assertEquals(bgColor, expectedColor); |
| 67 | + |
| 68 | + System.out.println( |
| 69 | + Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1] |
| 70 | + .getMethodName() + " => executed successfully"); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + void canHaveTheDefaultBackgroundColor() { |
| 75 | + driver.get("https://www.selenium.dev/selenium/web/cookie-background.html"); |
| 76 | + |
| 77 | + WebElement body = driver.findElement(By.tagName("body")); |
| 78 | + String bgColor = body.getCssValue("background-color"); |
| 79 | + |
| 80 | + String expectedColor = "rgb(255, 255, 255)"; |
| 81 | + Assertions.assertEquals(bgColor, expectedColor); |
| 82 | + |
| 83 | + System.out.println( |
| 84 | + Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1] |
| 85 | + .getMethodName() + " => executed successfully"); |
| 86 | + } |
| 87 | + |
| 88 | + @AfterEach |
| 89 | + public void cleanup() { |
| 90 | + driver.quit(); |
| 91 | + } |
| 92 | +} |
0 commit comments