Skip to content

Commit 7b5db4e

Browse files
committed
IFrame test
1 parent e846b8e commit 7b5db4e

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

webdriver_java/src/main/java/pages/HomePage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public FileUploadPage clickFileUpload(){
4141
return new FileUploadPage(driver);
4242
}
4343

44+
public WysiwygEditorPage clickWysiwygEditor(){
45+
clickLink("WYSIWYG Editor");
46+
return new WysiwygEditorPage(driver);
47+
}
48+
4449
private void clickLink(String linkText){
4550
driver.findElement(By.linkText(linkText)).click();
4651
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package pages;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
6+
public class WysiwygEditorPage {
7+
8+
private WebDriver driver;
9+
private String editorIframeId = "mce_0_ifr";
10+
private By textArea = By.id("tinymce");
11+
private By decreaseIndentButton = By.cssSelector("#mceu_12 button");
12+
13+
public WysiwygEditorPage(WebDriver driver){
14+
this.driver = driver;
15+
}
16+
17+
public void clearTextArea(){
18+
switchToEditArea();
19+
driver.findElement(textArea).clear();
20+
switchToMainArea();
21+
}
22+
23+
public void setTextArea(String text){
24+
switchToEditArea();
25+
driver.findElement(textArea).sendKeys(text);
26+
switchToMainArea();
27+
}
28+
29+
public String getTextFromEditor(){
30+
switchToEditArea();
31+
String text = driver.findElement(textArea).getText();
32+
switchToMainArea();
33+
return text;
34+
}
35+
36+
public void decreaseIndention(){
37+
driver.findElement(decreaseIndentButton).click();
38+
}
39+
40+
private void switchToEditArea(){
41+
driver.switchTo().frame(editorIframeId);
42+
}
43+
44+
private void switchToMainArea(){
45+
driver.switchTo().parentFrame();
46+
}
47+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package frames;
2+
3+
import base.BaseTests;
4+
import org.testng.annotations.Test;
5+
6+
import static org.testng.Assert.assertEquals;
7+
8+
public class FrameTests extends BaseTests {
9+
10+
@Test
11+
public void testWysiwyg(){
12+
var editorPage = homePage.clickWysiwygEditor();
13+
editorPage.clearTextArea();
14+
15+
String text1 = "hello ";
16+
String text2 = "world";
17+
18+
editorPage.setTextArea(text1);
19+
editorPage.decreaseIndention();
20+
editorPage.setTextArea(text2);
21+
22+
assertEquals(editorPage.getTextFromEditor(), text1+text2, "Text from editor is incorrect");
23+
}
24+
}

0 commit comments

Comments
 (0)