Skip to content

Instantly share code, notes, and snippets.

@batmi02
Created November 22, 2019 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batmi02/68aaa1ea8569c8c0b005f127f4aaad9f to your computer and use it in GitHub Desktop.
Save batmi02/68aaa1ea8569c8c0b005f127f4aaad9f to your computer and use it in GitHub Desktop.
@Test
public void iFrameTest() {
// Navigate to the app
driver.get("http://localhost:8000/iFrameExample.html");
//----------------- FRAME 1 ------------------------------
// Grab the outermost frame
driver.switchTo().defaultContent();
//switch context to outer frameset
driver.switchTo().frame("Top");
//switch context to inner iFrame 1
driver.switchTom().frame("1");
//test if the text "One" exists
assertEquals("One",driver.findElement(By.id("label")).getText());
//test if the background is green
assertThat(driver.findElement(By.tagName("body")).getAttribute("style"), containsString("green"));
//----------------- FRAME 2 ------------------------------
// Grab the outermost frame
driver.switchTo().defaultContent();
//switch context to outer frameset
driver.switchTo().frame("Top");
//switch context to inner iFrame 2
driver.switchTom().frame("2");
//test if the text "Two" exists
assertEquals("Two",driver.findElement(By.id("label")).getText());
//test if the background is orange
assertThat(driver.findElement(By.tagName("body")).getAttribute("style"), containsString("orange"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment