Permalink
Browse files

Kitchensink: mobile tests finshed

  • Loading branch information...
1 parent 30175d8 commit a68c7f38d2e8855a7c458ce2d972113eaf1be050 Juraj Huska committed Jul 4, 2012
View
11 ...test/java/org/richfaces/tests/archetypes/kitchensink/ftest/common/page/MemberDetails.java
@@ -16,6 +16,9 @@
@FindBy(xpath="//*[@class='rf-pp-hdr-cntrls ']/a")
private WebElement backToFormDesktop;
+
+ @FindBy(id="back-button")
+ private WebElement backToMenuMobile;
public void waitMemberDetailsAreAvailableOnDesktop(int timeoutInSeconds, WebDriver webDriver) {
(new WebDriverWait(webDriver, timeoutInSeconds)).until(new ExpectedCondition<Boolean>() {
@@ -26,6 +29,14 @@ public Boolean apply(WebDriver d) {
});
}
+ public WebElement getBackToMenuMobile() {
+ return backToMenuMobile;
+ }
+
+ public void setBackToMenuMobile(WebElement backToMenuMobile) {
+ this.backToMenuMobile = backToMenuMobile;
+ }
+
public WebElement getBackToFormDesktop() {
return backToFormDesktop;
}
View
18 .../test/java/org/richfaces/tests/archetypes/kitchensink/ftest/common/page/MembersTable.java
@@ -8,18 +8,30 @@
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
+import org.testng.annotations.Factory;
public class MembersTable {
@FindBy(xpath = "//*[@class='rf-dt-b']")
private WebElement table;
-
+
@FindBy(xpath = "//*[@class='rf-dt-b']/tr")
private WebElement tableRow;
-
+
@FindBy(xpath = "//*[@class='rf-dt-b']/tr")
private List<WebElement> tableRows;
-
+
+ @FindBy(xpath = "//*[@class='rf-dt-ftr-c']/a")
+ private WebElement urlAllMembersRestData;
+
+ public WebElement getUrlAllMembersRestData() {
+ return urlAllMembersRestData;
+ }
+
+ public void setUrlAllMembersRestData(WebElement urlAllMembersRestData) {
+ this.urlAllMembersRestData = urlAllMembersRestData;
+ }
+
public List<WebElement> getTableRows() {
return tableRows;
}
View
35 .../test/java/org/richfaces/tests/archetypes/kitchensink/ftest/common/page/RegisterForm.java
@@ -68,34 +68,49 @@
private String INCORRECT_PHONE_PATTERN = "wrong";
private String INCORRECT_NAME_TOO_SHORT = "";
-
+
public void clickOnRegisterButton() {
registerButton.click();
}
-
+
public void switchOffAutocompleteOnInputs(WebDriver webDriver) {
JavascriptExecutor js = (JavascriptExecutor) webDriver;
js.executeScript("document.getElementsByName('mobileForm:memberForm:name')[0].setAttribute('autocomplete','off');");
js.executeScript("document.getElementsByName('mobileForm:memberForm:email')[0].setAttribute('autocomplete','off');");
js.executeScript("document.getElementsByName('mobileForm:memberForm:phoneNumber')[0].setAttribute('autocomplete','off');");
}
-
- public void isErrorMessageRendered(String... ERR_MSG) {
- List<WebElement> errorMsgs = getErrorMessages();
+
+ public void areAllErrorMessagesRendered(String... errMsgs) {
+ List<WebElement> errorMsgsElements = getErrorMessages();
boolean flag = false;
-
- for(String i : ERR_MSG) {
+
+ for (String i : errMsgs) {
flag = false;
-
- for(WebElement j : errorMsgs) {
- if(i.equals(j.getText())) {
+
+ for (WebElement j : errorMsgsElements) {
+ if (i.equals(j.getText())) {
flag = true;
}
}
assertTrue(flag, "Error message: (" + i + ") was not rendered!");
}
}
+ public void isAnyErrorMessageRendered(String... errMsgs) {
+ List<WebElement> errorMsgsElements = getErrorMessages();
+ boolean flag = false;
+
+ for (String i : errMsgs) {
+
+ for (WebElement j : errorMsgsElements) {
+ if (i.equals(j.getText().trim())) {
+ flag = true;
+ }
+ }
+ }
+ assertTrue(flag, "None of messages: (" + errMsgs.toString() + ") were rendered!");
+ }
+
public void waitForErrorMessages(int timeoutInSec, WebDriver webDriver, final int numberOfErrorMessagesBefore) {
(new WebDriverWait(webDriver, timeoutInSec)).until(new ExpectedCondition<Boolean>() {
View
2 ...test/src/test/java/org/richfaces/tests/archetypes/kitchensink/ftest/desktop/TestForm.java
@@ -53,7 +53,7 @@
@BeforeMethod(groups = "arquillian")
public void initialiseWebElements() {
- FieldDecorator fd = new StaleReferenceAwareFieldDecorator(new DefaultElementLocatorFactory(webDriver), 2);
+ FieldDecorator fd = new StaleReferenceAwareFieldDecorator(new DefaultElementLocatorFactory(webDriver), 2);
PageFactory.initElements(fd, registerForm);
PageFactory.initElements(fd, membersTable);
PageFactory.initElements(fd, memberDetails);
View
78 ...ftest/src/test/java/org/richfaces/tests/archetypes/kitchensink/ftest/mobile/TestForm.java
@@ -25,6 +25,7 @@
import static org.testng.Assert.assertTrue;
import org.jboss.test.selenium.support.pagefactory.StaleReferenceAwareFieldDecorator;
+import org.openqa.selenium.By;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory;
import org.openqa.selenium.support.pagefactory.FieldDecorator;
@@ -59,11 +60,13 @@ public void initialiseWebElements() {
@Test
public void testAddCorrectMember() {
menuPage.gotoAddMemberPage();
- registerForm.switchOffAutocompleteOnInputs(webDriver);
-
+ // registerForm.switchOffAutocompleteOnInputs(webDriver);
+
// set twice as workaround for first time filling in input
String nameSet = registerForm.setCorrectName();
- registerForm.setCorrectName();
+ if (registerForm.getNameInput().getAttribute("value").isEmpty()) {
+ registerForm.setCorrectName();
+ }
registerForm.setCorrectEmail();
registerForm.setCorrectPhone();
@@ -77,8 +80,8 @@ public void testAddCorrectMember() {
@Test
public void testCSVEmailPattern() {
menuPage.gotoAddMemberPage();
- registerForm.switchOffAutocompleteOnInputs(webDriver);
-
+ // registerForm.switchOffAutocompleteOnInputs(webDriver);
+
final int numberOfErrorMessagesBefore = registerForm.getErrorMessages().size();
registerForm.setIncorrectEmailPatternViolation();
@@ -87,14 +90,14 @@ public void testCSVEmailPattern() {
registerForm.waitForErrorMessages(3, webDriver, numberOfErrorMessagesBefore);
assertEquals(registerForm.getErrorMessages().size(), 1, ERROR_MSG_CSV);
- registerForm.isErrorMessageRendered(CSV_EMAIL);
+ registerForm.areAllErrorMessagesRendered(CSV_EMAIL);
}
@Test(groups = "4.Future")
public void testCSVNamePattern() {
menuPage.gotoAddMemberPage();
- registerForm.switchOffAutocompleteOnInputs(webDriver);
-
+ // registerForm.switchOffAutocompleteOnInputs(webDriver);
+
final int numberOfErrorMessagesBefore = registerForm.getErrorMessages().size();
registerForm.setIncorrectNamePatternViolation();
@@ -107,8 +110,8 @@ public void testCSVNamePattern() {
@Test
public void testCSVPhonePattern() {
menuPage.gotoAddMemberPage();
- registerForm.switchOffAutocompleteOnInputs(webDriver);
-
+ // registerForm.switchOffAutocompleteOnInputs(webDriver);
+
final int numberOfErrorMessagesBefore = registerForm.getErrorMessages().size();
registerForm.setIncorrectPhonePatternViolation();
@@ -117,43 +120,68 @@ public void testCSVPhonePattern() {
registerForm.waitForErrorMessages(WAIT_FOR_ERR_MSG_RENDER, webDriver, numberOfErrorMessagesBefore);
assertEquals(registerForm.getErrorMessages().size(), 1, ERROR_MSG_CSV);
- registerForm.isErrorMessageRendered(CSV_PHONE);
+ registerForm.areAllErrorMessagesRendered(CSV_PHONE);
}
@Test
public void testSSVInputsEmpty() {
menuPage.gotoAddMemberPage();
- registerForm.switchOffAutocompleteOnInputs(webDriver);
-
+ // registerForm.switchOffAutocompleteOnInputs(webDriver);
+
final int numberOfErrorMessagesBefore = registerForm.getErrorMessages().size();
registerForm.clickOnRegisterButton();
registerForm.waitForErrorMessages(WAIT_FOR_ERR_MSG_RENDER, webDriver, numberOfErrorMessagesBefore);
assertEquals(registerForm.getErrorMessages().size(), 3, ERROR_MSG_CSV);
}
-
+
@Test
public void testSSVWrongInputs() {
menuPage.gotoAddMemberPage();
- registerForm.switchOffAutocompleteOnInputs(webDriver);
-
+ // registerForm.switchOffAutocompleteOnInputs(webDriver);
+
final int numberOfErrorMessagesBefore = registerForm.getErrorMessages().size();
-
+
registerForm.setIncorrectNameTooShort();
registerForm.setIncorrectEmailPatternViolation();
registerForm.setIncorrectPhonePatternViolation();
-
+
registerForm.clickOnRegisterButton();
-
+
registerForm.waitForErrorMessages(WAIT_FOR_ERR_MSG_RENDER, webDriver, numberOfErrorMessagesBefore);
assertEquals(registerForm.getErrorMessages().size(), 3, ERROR_MSG_CSV);
- registerForm.isErrorMessageRendered(SSV_NAME_SIZE, SSV_PHONE_SIZE, CSV_EMAIL);
+ registerForm.areAllErrorMessagesRendered(SSV_NAME_SIZE, CSV_EMAIL);
+ registerForm.isAnyErrorMessageRendered(CSV_PHONE, SSV_PHONE_SIZE);
}
-
-// @Test
-// public void testViewMemberDetails() {
-//
-// }
+ @Test
+ public void testViewMemberDetails() {
+ menuPage.gotoAddMemberPage();
+
+ registerForm.setCorrectName();
+ registerForm.setEmail("wonderland@provider.org");
+ registerForm.setCorrectPhone();
+
+ registerForm.clickOnRegisterButton();
+ menuPage.waitFor(MenuPage.PAGE_TRANSITION_WAIT);
+
+ int numberOfRows = membersTable.getNumberOfRows();
+ for (int i = 1; i <= numberOfRows; i++) {
+
+ String expectedEmail = membersTable.getTable().findElement(By.xpath("(//*[@class='rf-dt-b']/tr)[" + i + "]/td[4]"))
+ .getText();
+
+ membersTable.getTable().findElement(By.xpath("(//*[@class='rf-dt-b']/tr)[" + i + "]/td/a")).click();
+ menuPage.waitFor(MenuPage.PAGE_TRANSITION_WAIT);
+
+ String actualEmail = memberDetails.getEmailOnMobile().getText().trim();
+ assertEquals(actualEmail, expectedEmail, "Email from the table is not equal to email from the user details!");
+
+ if (i == numberOfRows)
+ break;
+ memberDetails.getBackToMenuMobile().click();
+ menuPage.gotoListMembersPage();
+ }
+ }
}
View
19 .../src/test/java/org/richfaces/tests/archetypes/kitchensink/ftest/mobile/page/MenuPage.java
@@ -5,16 +5,13 @@
public class MenuPage {
- @FindBy(xpath = "//*[contains(.,'Application Menu')]")
- private WebElement applicationMenu;
-
- @FindBy(xpath = "//*[contains(.,'Add Member')]")
+ @FindBy(xpath = "(//*[@class='rf-pm-itm-lbl'])[1]")
private WebElement addMember;
- @FindBy(xpath = "//*[contains(.,'List Members')]")
+ @FindBy(xpath = "(//*[@class='rf-pm-itm-lbl'])[2]")
private WebElement listMembers;
- public static final int PAGE_TRANSITION_WAIT = 3;
+ public static final int PAGE_TRANSITION_WAIT = 2;
public void gotoAddMemberPage() {
addMember.click();
@@ -25,15 +22,7 @@ public void gotoListMembersPage() {
listMembers.click();
waitFor(PAGE_TRANSITION_WAIT);
}
-
- public WebElement getApplicationMenu() {
- return applicationMenu;
- }
-
- public void setApplicationMenu(WebElement applicationMenuCollapsiblePanel) {
- this.applicationMenu = applicationMenuCollapsiblePanel;
- }
-
+
public WebElement getAddMember() {
return addMember;
}

0 comments on commit a68c7f3

Please sign in to comment.