Skip to content

Commit

Permalink
IFrame test
Browse files Browse the repository at this point in the history
  • Loading branch information
angiejones committed Jul 9, 2019
1 parent e846b8e commit 7b5db4e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions webdriver_java/src/main/java/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public FileUploadPage clickFileUpload(){
return new FileUploadPage(driver);
}

public WysiwygEditorPage clickWysiwygEditor(){
clickLink("WYSIWYG Editor");
return new WysiwygEditorPage(driver);
}

private void clickLink(String linkText){
driver.findElement(By.linkText(linkText)).click();
}
Expand Down
47 changes: 47 additions & 0 deletions webdriver_java/src/main/java/pages/WysiwygEditorPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class WysiwygEditorPage {

private WebDriver driver;
private String editorIframeId = "mce_0_ifr";
private By textArea = By.id("tinymce");
private By decreaseIndentButton = By.cssSelector("#mceu_12 button");

public WysiwygEditorPage(WebDriver driver){
this.driver = driver;
}

public void clearTextArea(){
switchToEditArea();
driver.findElement(textArea).clear();
switchToMainArea();
}

public void setTextArea(String text){
switchToEditArea();
driver.findElement(textArea).sendKeys(text);
switchToMainArea();
}

public String getTextFromEditor(){
switchToEditArea();
String text = driver.findElement(textArea).getText();
switchToMainArea();
return text;
}

public void decreaseIndention(){
driver.findElement(decreaseIndentButton).click();
}

private void switchToEditArea(){
driver.switchTo().frame(editorIframeId);
}

private void switchToMainArea(){
driver.switchTo().parentFrame();
}
}
24 changes: 24 additions & 0 deletions webdriver_java/src/test/java/frames/FrameTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package frames;

import base.BaseTests;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class FrameTests extends BaseTests {

@Test
public void testWysiwyg(){
var editorPage = homePage.clickWysiwygEditor();
editorPage.clearTextArea();

String text1 = "hello ";
String text2 = "world";

editorPage.setTextArea(text1);
editorPage.decreaseIndention();
editorPage.setTextArea(text2);

assertEquals(editorPage.getTextFromEditor(), text1+text2, "Text from editor is incorrect");
}
}

0 comments on commit 7b5db4e

Please sign in to comment.