diff --git a/examples/jsf/login/src/ftest/java/org/jboss/weld/examples/login/test/selenium/CommonLoginTest.java b/examples/jsf/login/src/ftest/java/org/jboss/weld/examples/login/test/selenium/CommonLoginTest.java index 919e279c8c6..e26f5c50119 100755 --- a/examples/jsf/login/src/ftest/java/org/jboss/weld/examples/login/test/selenium/CommonLoginTest.java +++ b/examples/jsf/login/src/ftest/java/org/jboss/weld/examples/login/test/selenium/CommonLoginTest.java @@ -25,11 +25,15 @@ import static org.testng.Assert.assertTrue; import org.jboss.test.selenium.AbstractTestCase; -import org.jboss.test.selenium.locator.XpathLocator; import org.jboss.test.selenium.guard.request.RequestTypeGuardFactory; +import org.jboss.test.selenium.locator.IdLocator; +import org.jboss.test.selenium.locator.XpathLocator; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import static org.jboss.test.selenium.locator.LocatorFactory.id; +import static org.jboss.test.selenium.locator.LocatorFactory.xp; + /** * Tests login examples in Weld * @@ -38,37 +42,43 @@ */ public class CommonLoginTest extends AbstractTestCase { - protected String MAIN_PAGE = "/home.jsf"; - protected String LOGGED_IN = "xpath=//li[contains(text(),'Welcome')]"; - protected String LOGGED_OUT = "xpath=//li[contains(text(),'Goodbye')]"; - - protected String USERNAME_FIELD = "id=loginForm:username"; - protected String PASSWORD_FIELD = "id=loginForm:password"; - - protected String LOGIN_BUTTON = "id=loginForm:login"; - protected String LOGOUT_BUTTON = "id=loginForm:logout"; + protected XpathLocator LOGGED_IN = xp("//li[contains(text(),'Welcome')]"); + protected XpathLocator LOGGED_OUT = xp("//li[contains(text(),'Goodbye')]"); + + protected IdLocator USERNAME_FIELD = id("loginForm:username"); + protected IdLocator PASSWORD_FIELD = id("loginForm:password"); + + protected IdLocator LOGIN_BUTTON = id("loginForm:login"); + protected IdLocator LOGOUT_BUTTON = id("loginForm:logout"); + + @BeforeMethod + public void openStartUrl() + { + selenium.open(contextPath); + waitModel.until(elementPresent.locator(USERNAME_FIELD)); + } @Test public void loginTest() { - assertFalse(selenium.isElementPresent(new XpathLocator(LOGGED_IN)), "User should not be logged in!"); - selenium.type(new XpathLocator(USERNAME_FIELD), "demo"); - selenium.type(new XpathLocator(PASSWORD_FIELD), "demo"); - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(LOGIN_BUTTON)); - assertTrue(selenium.isElementPresent(new XpathLocator(LOGGED_IN)), "User should be logged in!"); + assertFalse(selenium.isElementPresent(LOGGED_IN), "User should not be logged in!"); + selenium.type(USERNAME_FIELD, "demo"); + selenium.type(PASSWORD_FIELD, "demo"); + RequestTypeGuardFactory.waitHttp(selenium).click(LOGIN_BUTTON); + assertTrue(selenium.isElementPresent(LOGGED_IN), "User should be logged in!"); } @Test public void logoutTest() { - assertFalse(selenium.isElementPresent(new XpathLocator(LOGGED_IN)), "User should not be logged in!"); - selenium.type(new XpathLocator(USERNAME_FIELD), "demo"); - selenium.type(new XpathLocator(PASSWORD_FIELD), "demo"); - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(LOGIN_BUTTON)); - assertTrue(selenium.isElementPresent(new XpathLocator(LOGGED_IN)), "User should be logged in!"); - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(LOGOUT_BUTTON)); - assertTrue(selenium.isElementPresent(new XpathLocator(LOGGED_OUT)), "User should not be logged in!"); + assertFalse(selenium.isElementPresent(LOGGED_IN), "User should not be logged in!"); + selenium.type(USERNAME_FIELD, "demo"); + selenium.type(PASSWORD_FIELD, "demo"); + RequestTypeGuardFactory.waitHttp(selenium).click(LOGIN_BUTTON); + assertTrue(selenium.isElementPresent(LOGGED_IN), "User should be logged in!"); + RequestTypeGuardFactory.waitHttp(selenium).click(LOGOUT_BUTTON); + assertTrue(selenium.isElementPresent(LOGGED_OUT), "User should not be logged in!"); } } diff --git a/examples/jsf/numberguess/src/ftest/java/org/jboss/weld/examples/numberguess/test/selenium/CommonNumberGuessTest.java b/examples/jsf/numberguess/src/ftest/java/org/jboss/weld/examples/numberguess/test/selenium/CommonNumberGuessTest.java index 4fffe15670b..334261ca910 100755 --- a/examples/jsf/numberguess/src/ftest/java/org/jboss/weld/examples/numberguess/test/selenium/CommonNumberGuessTest.java +++ b/examples/jsf/numberguess/src/ftest/java/org/jboss/weld/examples/numberguess/test/selenium/CommonNumberGuessTest.java @@ -25,11 +25,14 @@ import static org.testng.Assert.fail; import org.jboss.test.selenium.AbstractTestCase; -import org.jboss.test.selenium.locator.XpathLocator; import org.jboss.test.selenium.guard.request.RequestTypeGuardFactory; +import org.jboss.test.selenium.locator.IdLocator; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import static org.jboss.test.selenium.locator.LocatorFactory.id; + /** * Tests numberguess examples in Weld * @@ -41,17 +44,30 @@ public class CommonNumberGuessTest extends AbstractTestCase { protected String MAIN_PAGE = "/home.jsf"; - protected String GUESS_MESSAGES = "id=numberGuess:messages"; + protected IdLocator GUESS_MESSAGES = id("numberGuess:messages"); - protected String GUESS_FIELD = "id=numberGuess:inputGuess"; - protected String GUESS_SUBMIT = "id=numberGuess:guessButton"; - protected String GUESS_RESET = "id=numberGuess:resetButton"; - protected String GUESS_SMALLEST = "id=numberGuess:smallest"; - protected String GUESS_BIGGEST = "id=numberGuess:biggest"; + protected IdLocator GUESS_FIELD = id("numberGuess:inputGuess"); + protected IdLocator GUESS_SUBMIT = id("numberGuess:guessButton"); + protected IdLocator GUESS_RESET = id("numberGuess:resetButton"); + protected IdLocator GUESS_SMALLEST = id("numberGuess:smallest"); + protected IdLocator GUESS_BIGGEST = id("numberGuess:biggest"); protected String WIN_MSG = "Correct!"; protected String LOSE_MSG = "No guesses left!"; + @BeforeMethod + public void openStartUrl() + { + selenium.open(contextPath); + waitModel.until(elementPresent.locator(GUESS_FIELD)); + } + + @AfterMethod + public void resetSession() + { + selenium.deleteAllVisibleCookies(); + } + @Test public void smartTest() { @@ -68,11 +84,11 @@ public void smartTest() fail("Game should not be longer than 10 guesses"); } - assertTrue(selenium.isElementPresent(new XpathLocator(GUESS_SMALLEST)), "Expected smallest number on page"); - assertTrue(selenium.isElementPresent(new XpathLocator(GUESS_BIGGEST)), "Expected biggest number on page"); + assertTrue(selenium.isElementPresent(GUESS_SMALLEST), "Expected smallest number on page"); + assertTrue(selenium.isElementPresent(GUESS_BIGGEST), "Expected biggest number on page"); - min = Integer.parseInt(selenium.getText(new XpathLocator(GUESS_SMALLEST))); - max = Integer.parseInt(selenium.getText(new XpathLocator(GUESS_BIGGEST))); + min = Integer.parseInt(selenium.getText(GUESS_SMALLEST)); + max = Integer.parseInt(selenium.getText(GUESS_BIGGEST)); guess = min + ((max - min) / 2); enterGuess(guess); i++; @@ -103,8 +119,8 @@ public void linearTest() protected void enterGuess(int guess) { - selenium.type(new XpathLocator(GUESS_FIELD), String.valueOf(guess)); - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(GUESS_SUBMIT)); + selenium.type(GUESS_FIELD, String.valueOf(guess)); + RequestTypeGuardFactory.waitHttp(selenium).click(GUESS_SUBMIT); } protected boolean isOnGuessPage() @@ -114,13 +130,13 @@ protected boolean isOnGuessPage() protected boolean isOnWinPage() { - String text = selenium.getText(new XpathLocator(GUESS_MESSAGES)); + String text = selenium.getText(GUESS_MESSAGES); return WIN_MSG.equals(text); } protected boolean isOnLosePage() { - String text = selenium.getText(new XpathLocator(GUESS_MESSAGES)); + String text = selenium.getText(GUESS_MESSAGES); return LOSE_MSG.equals(text); } diff --git a/examples/jsf/permalink/src/ftest/java/org/jboss/weld/examples/permalink/test/selenium/PermalinkTest.java b/examples/jsf/permalink/src/ftest/java/org/jboss/weld/examples/permalink/test/selenium/PermalinkTest.java index a6721e9525f..347ea6f201d 100755 --- a/examples/jsf/permalink/src/ftest/java/org/jboss/weld/examples/permalink/test/selenium/PermalinkTest.java +++ b/examples/jsf/permalink/src/ftest/java/org/jboss/weld/examples/permalink/test/selenium/PermalinkTest.java @@ -24,11 +24,15 @@ import static org.testng.Assert.assertTrue; import org.jboss.test.selenium.AbstractTestCase; -import org.jboss.test.selenium.locator.XpathLocator; import org.jboss.test.selenium.guard.request.RequestTypeGuardFactory; +import org.jboss.test.selenium.locator.IdLocator; +import org.jboss.test.selenium.locator.XpathLocator; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import static org.jboss.test.selenium.locator.LocatorFactory.id; +import static org.jboss.test.selenium.locator.LocatorFactory.xp; + /** * Tests permalink example in Weld. The first test just adds comment on the first * topic and returns back. Second test tests permanent link from jsf2. @@ -40,35 +44,42 @@ public class PermalinkTest extends AbstractTestCase { protected String MAIN_PAGE = "/home.jsf"; protected String PAGE_TITLE = "Direct links to the news you crave"; - protected String VIEW_ENTRY_LINK = "xpath=//a[contains(text(),'View Entry')][1]"; + protected XpathLocator VIEW_ENTRY_LINK = xp("//a[contains(text(),'View Entry')][1]"); protected String TOPIC_TITLE = "Mojarra == RI"; - protected String PERMALINK_LINK = "xpath=//a[@title='A bookmarkable link for this entry.'][1]"; - protected String AUTHOR_INPUT = "id=author"; - protected String COMMENT_INPUT = "id=body"; - protected String SUBMIT_BUTTON = "id=post"; - protected String BACK_BUTTON = "xpath=//input[@type='button'][@value='Back to main page']"; + protected XpathLocator PERMALINK_LINK = xp("//a[@title='A bookmarkable link for this entry.'][1]"); + protected IdLocator AUTHOR_INPUT = id("author"); + protected IdLocator COMMENT_INPUT = id("body"); + protected IdLocator SUBMIT_BUTTON = id("post"); + protected XpathLocator BACK_BUTTON = xp("//input[@type='button'][@value='Back to main page']"); protected String COMMENT_TEXT = "This is my first comment on Mojarra project"; protected String AUTHOR_NAME = "Martin"; protected String TEXT_ON_HOME_PAGE = "Annotation nation"; + + @BeforeMethod + public void openStartUrl() + { + selenium.open(contextPath); + waitModel.until(elementPresent.locator(VIEW_ENTRY_LINK)); + } @Test public void addCommentOnTopicTest() { - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(VIEW_ENTRY_LINK)); + RequestTypeGuardFactory.waitHttp(selenium).click(VIEW_ENTRY_LINK); assertTrue(selenium.isTextPresent(TOPIC_TITLE), "Topic title expected on the page"); - selenium.type(new XpathLocator(AUTHOR_INPUT), AUTHOR_NAME); - selenium.type(new XpathLocator(COMMENT_INPUT), COMMENT_TEXT); - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(SUBMIT_BUTTON)); + selenium.type(AUTHOR_INPUT, AUTHOR_NAME); + selenium.type(COMMENT_INPUT, COMMENT_TEXT); + RequestTypeGuardFactory.waitHttp(selenium).click(SUBMIT_BUTTON); assertTrue(selenium.isTextPresent(AUTHOR_NAME), "A name of comment's author expected"); assertTrue(selenium.isTextPresent(COMMENT_TEXT), "A text of entered comment expected"); - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(BACK_BUTTON)); + RequestTypeGuardFactory.waitHttp(selenium).click(BACK_BUTTON); assertTrue(selenium.isTextPresent(TEXT_ON_HOME_PAGE), "Home page expected"); } @Test(dependsOnMethods="addCommentOnTopicTest") public void permanentLinkTest() { - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(PERMALINK_LINK)); + RequestTypeGuardFactory.waitHttp(selenium).click(PERMALINK_LINK); assertTrue(selenium.isTextPresent(AUTHOR_NAME), "A name of comment's author expected"); assertTrue(selenium.isTextPresent(COMMENT_TEXT), "A text of entered comment expected"); } diff --git a/examples/jsf/translator/ear/src/ftest/java/org/jboss/weld/examples/translator/test/selenium/TranslatorTest.java b/examples/jsf/translator/ear/src/ftest/java/org/jboss/weld/examples/translator/test/selenium/TranslatorTest.java index 800beba5490..7ad08044ce1 100755 --- a/examples/jsf/translator/ear/src/ftest/java/org/jboss/weld/examples/translator/test/selenium/TranslatorTest.java +++ b/examples/jsf/translator/ear/src/ftest/java/org/jboss/weld/examples/translator/test/selenium/TranslatorTest.java @@ -24,11 +24,13 @@ import static org.testng.Assert.assertTrue; import org.jboss.test.selenium.AbstractTestCase; -import org.jboss.test.selenium.locator.XpathLocator; import org.jboss.test.selenium.guard.request.RequestTypeGuardFactory; +import org.jboss.test.selenium.locator.IdLocator; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import static org.jboss.test.selenium.locator.LocatorFactory.id; + /** * Tests translator example in Weld * @@ -38,21 +40,28 @@ public class TranslatorTest extends AbstractTestCase { protected String MAIN_PAGE = "/home.jsf"; - protected String INPUT_AREA = "id=TranslatorMain:text"; - protected String TRANSLATE_BUTTON = "id=TranslatorMain:button"; + protected IdLocator INPUT_AREA = id("TranslatorMain:text"); + protected IdLocator TRANSLATE_BUTTON = id("TranslatorMain:button"); protected String ONE_SENTENCE = "This is only one sentence."; protected String MORE_SENTENCES = "First sentence. Second and last sentence."; protected String ONE_SENTENCE_TRANSLATED = "Lorem ipsum dolor sit amet."; protected String MORE_SENTENCES_TRANSLATED = "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet."; + @BeforeMethod + public void openStartUrl() + { + selenium.open(contextPath); + waitModel.until(elementPresent.locator(INPUT_AREA)); + } + @Test public void translateTest() { - browser.type(new XpathLocator(INPUT_AREA), ONE_SENTENCE); - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(TRANSLATE_BUTTON)); - assertTrue(browser.isTextPresent(ONE_SENTENCE_TRANSLATED), "One sentence translated into latin expected."); - browser.type(new XpathLocator(INPUT_AREA), MORE_SENTENCES); - RequestTypeGuardFactory.waitHttp(selenium).click(new XpathLocator(TRANSLATE_BUTTON)); - assertTrue(browser.isTextPresent(MORE_SENTENCES_TRANSLATED), "More sentences translated into latin expected."); + selenium.type(INPUT_AREA, ONE_SENTENCE); + RequestTypeGuardFactory.waitHttp(selenium).click(TRANSLATE_BUTTON); + assertTrue(selenium.isTextPresent(ONE_SENTENCE_TRANSLATED), "One sentence translated into latin expected."); + selenium.type(INPUT_AREA, MORE_SENTENCES); + RequestTypeGuardFactory.waitHttp(selenium).click(TRANSLATE_BUTTON); + assertTrue(selenium.isTextPresent(MORE_SENTENCES_TRANSLATED), "More sentences translated into latin expected."); } }