forked from SeleniumHQ/seleniumhq.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example code to windows and modified text (SeleniumHQ#1754)[dep…
…loy site] * added example code for windows and switched text order. modified some text also * fixed tab pane hugo error --------- Co-authored-by: Sri Harsha <[email protected]>
- Loading branch information
1 parent
2bd31eb
commit 8ea6e02
Showing
5 changed files
with
299 additions
and
352 deletions.
There are no files selected for viewing
47 changes: 44 additions & 3 deletions
47
examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,48 @@ | ||
package dev.selenium.interactions; | ||
|
||
import dev.selenium.BaseTest; | ||
import org.openqa.selenium.*; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import java.time.Duration; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class WindowsTest extends BaseTest { | ||
public class WindowsTest { | ||
|
||
} | ||
@Test | ||
public void windowsExampleCode() { | ||
|
||
WebDriver driver = new ChromeDriver(); | ||
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500)); | ||
// Navigate to Url | ||
driver.get("https://www.selenium.dev/selenium/web/window_switching_tests/page_with_frame.html"); | ||
//fetch handle of this | ||
String currHandle=driver.getWindowHandle(); | ||
assertNotNull(currHandle); | ||
|
||
//click on link to open a new window | ||
driver.findElement(By.linkText("Open new window")).click(); | ||
//fetch handles of all windows, there will be two, [0]- default, [1] - new window | ||
Object[] windowHandles=driver.getWindowHandles().toArray(); | ||
driver.switchTo().window((String) windowHandles[1]); | ||
//assert on title of new window | ||
String title=driver.getTitle(); | ||
assertEquals("Simple Page",title); | ||
|
||
//closing current window | ||
driver.close(); | ||
//Switch back to the old tab or window | ||
driver.switchTo().window((String) windowHandles[0]); | ||
|
||
//Opens a new tab and switches to new tab | ||
driver.switchTo().newWindow(WindowType.TAB); | ||
assertEquals("",driver.getTitle()); | ||
|
||
//Opens a new window and switches to new window | ||
driver.switchTo().newWindow(WindowType.WINDOW); | ||
assertEquals("",driver.getTitle()); | ||
|
||
//quitting driver | ||
driver.quit(); //close all windows | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.