Skip to content

Commit 4fe9a8d

Browse files
authored
Merge branch 'trunk' into update_plc
2 parents fcdd0c0 + 310245c commit 4fe9a8d

File tree

14 files changed

+541
-133
lines changed

14 files changed

+541
-133
lines changed

examples/java/src/test/java/dev/selenium/interactions/AlertsTest.java

Lines changed: 167 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
package dev.selenium.interactions;
19+
1820
import dev.selenium.BaseTest;
21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.BeforeEach;
1924
import org.junit.jupiter.api.Test;
20-
import org.openqa.selenium.*;
25+
import org.openqa.selenium.Alert;
26+
import org.openqa.selenium.By;
27+
import org.openqa.selenium.JavascriptExecutor;
28+
import org.openqa.selenium.WebDriver;
29+
import org.openqa.selenium.WebElement;
2130
import org.openqa.selenium.chrome.ChromeDriver;
2231
import org.openqa.selenium.chrome.ChromeOptions;
2332
import org.openqa.selenium.support.ui.ExpectedConditions;
@@ -29,6 +38,163 @@
2938

3039
public class AlertsTest extends BaseTest {
3140

41+
@BeforeEach
42+
public void createSession() {
43+
driver = new ChromeDriver();
44+
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
45+
}
46+
47+
@AfterEach
48+
public void endSession() {
49+
driver.quit();
50+
}
51+
52+
@Test
53+
public void alertInformationTest() {
54+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
55+
56+
driver.findElement(By.id("alert")).click();
57+
58+
wait.until(ExpectedConditions.alertIsPresent());
59+
Alert alert = driver.switchTo().alert();
60+
Assertions.assertEquals("cheese", alert.getText());
61+
alert.accept();
62+
63+
}
64+
65+
@Test
66+
public void alertEmptyInformationTest() {
67+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
68+
driver.findElement(By.id("empty-alert")).click();
69+
70+
71+
wait.until(ExpectedConditions.alertIsPresent());
72+
73+
Alert alert = driver.switchTo().alert();
74+
Assertions.assertEquals("", alert.getText());
75+
alert.accept();
76+
77+
}
78+
79+
@Test
80+
public void promptDisplayAndInputTest() {
81+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
82+
driver.findElement(By.id("prompt")).click();
83+
84+
//Wait for the alert to be displayed and store it in a variable
85+
wait.until(ExpectedConditions.alertIsPresent());
86+
87+
Alert alert = driver.switchTo().alert();
88+
Assertions.assertEquals("Enter something", alert.getText());
89+
90+
alert.sendKeys("Selenium");
91+
alert.accept();
92+
93+
}
94+
95+
@Test
96+
public void promptDefaultInputTest() {
97+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
98+
99+
driver.findElement(By.id("prompt-with-default")).click();
100+
101+
wait.until(ExpectedConditions.alertIsPresent());
102+
Alert alert = driver.switchTo().alert();
103+
Assertions.assertEquals("Enter something", alert.getText());
104+
alert.accept();
105+
}
106+
107+
@Test
108+
public void multiplePromptInputsTest() {
109+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
110+
driver.findElement(By.id("double-prompt")).click();
111+
112+
wait.until(ExpectedConditions.alertIsPresent());
113+
114+
Alert alert1 = driver.switchTo().alert();
115+
Assertions.assertEquals("First", alert1.getText());
116+
117+
alert1.sendKeys("first");
118+
alert1.accept();
119+
120+
121+
Alert alert2 = driver.switchTo().alert();
122+
Assertions.assertEquals("Second", alert2.getText());
123+
alert2.sendKeys("second");
124+
alert2.accept();
125+
126+
}
127+
128+
@Test
129+
public void slowAlertTest() {
130+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
131+
driver.findElement(By.id("slow-alert")).click();
132+
133+
wait.until(ExpectedConditions.alertIsPresent());
134+
135+
Alert alert = driver.switchTo().alert();
136+
Assertions.assertEquals("Slow", alert.getText());
137+
138+
alert.accept();
139+
140+
}
141+
142+
143+
@Test
144+
public void confirmationAlertTest() {
145+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
146+
147+
driver.findElement(By.id("confirm")).click();
148+
149+
wait.until(ExpectedConditions.alertIsPresent());
150+
Alert alert = driver.switchTo().alert();
151+
Assertions.assertEquals("Are you sure?", alert.getText());
152+
153+
alert.accept();
154+
Assertions.assertTrue(driver.getCurrentUrl().endsWith("simpleTest.html"));
155+
156+
}
157+
158+
159+
@Test
160+
public void iframeAlertTest() {
161+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
162+
WebElement iframe = driver.findElement(By.name("iframeWithAlert"));
163+
driver.switchTo().frame(iframe);
164+
165+
driver.findElement(By.id("alertInFrame")).click();
166+
167+
168+
wait.until(ExpectedConditions.alertIsPresent());
169+
170+
Alert alert = driver.switchTo().alert();
171+
Assertions.assertEquals("framed cheese", alert.getText());
172+
173+
alert.accept();
174+
175+
}
176+
177+
@Test
178+
public void nestedIframeAlertTest() {
179+
driver.get("https://www.selenium.dev/selenium/web/alerts.html#");
180+
WebElement iframe1 = driver.findElement(By.name("iframeWithIframe"));
181+
driver.switchTo().frame(iframe1);
182+
183+
WebElement iframe2 = driver.findElement(By.name("iframeWithAlert"));
184+
driver.switchTo().frame(iframe2);
185+
186+
driver.findElement(By.id("alertInFrame")).click();
187+
188+
189+
wait.until(ExpectedConditions.alertIsPresent());
190+
191+
Alert alert = driver.switchTo().alert();
192+
Assertions.assertEquals("framed cheese", alert.getText());
193+
194+
alert.accept();
195+
196+
}
197+
32198
@Test
33199
public void testForAlerts() {
34200

examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
package dev.selenium.interactions;
19+
1820
import org.junit.jupiter.api.Test;
1921
import org.junit.jupiter.api.Assertions;
2022
import org.openqa.selenium.Cookie;
@@ -34,21 +36,21 @@ public void addCookie() {
3436
}
3537
@Test
3638
public void getNamedCookie() {
37-
39+
3840
driver.get("https://www.selenium.dev/selenium/web/blank.html");
3941
// Add cookie into current browser context
4042
driver.manage().addCookie(new Cookie("foo", "bar"));
4143
// Get cookie details with named cookie 'foo'
4244
Cookie cookie = driver.manage().getCookieNamed("foo");
4345
Assertions.assertEquals(cookie.getValue(), "bar");
44-
46+
4547
driver.quit();
4648
}
47-
49+
4850

4951
@Test
5052
public void getAllCookies() {
51-
53+
5254
driver.get("https://www.selenium.dev/selenium/web/blank.html");
5355
// Add cookies into current browser context
5456
driver.manage().addCookie(new Cookie("test1", "cookie1"));
@@ -66,11 +68,11 @@ public void getAllCookies() {
6668
}
6769
driver.quit();
6870
}
69-
71+
7072

7173
@Test
7274
public void deleteCookieNamed() {
73-
75+
7476
driver.get("https://www.selenium.dev/selenium/web/blank.html");
7577
driver.manage().addCookie(new Cookie("test1", "cookie1"));
7678
// delete cookie named
@@ -80,7 +82,7 @@ public void deleteCookieNamed() {
8082

8183
@Test
8284
public void deleteCookieObject() {
83-
85+
8486
driver.get("https://www.selenium.dev/selenium/web/blank.html");
8587
Cookie cookie = new Cookie("test2", "cookie2");
8688
driver.manage().addCookie(cookie);
@@ -89,21 +91,21 @@ public void deleteCookieObject() {
8991
cookie by passing cookie object of current browsing context
9092
*/
9193
driver.manage().deleteCookie(cookie);
92-
94+
9395
driver.quit();
9496
}
95-
97+
9698

9799
@Test
98100
public void deleteAllCookies() {
99-
101+
100102
driver.get("https://www.selenium.dev/selenium/web/blank.html");
101103
// Add cookies into current browser context
102104
driver.manage().addCookie(new Cookie("test1", "cookie1"));
103105
driver.manage().addCookie(new Cookie("test2", "cookie2"));
104106
// Delete All cookies
105107
driver.manage().deleteAllCookies();
106-
108+
107109
driver.quit();
108110
}
109111

0 commit comments

Comments
 (0)