Author: dsvyatobatsko
Date: 2008-04-14 13:35:02 -0400 (Mon, 14 Apr 2008)
New Revision: 7828
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
Log:
just formatting
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-04-14
17:34:15 UTC (rev 7827)
+++
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-04-14
17:35:02 UTC (rev 7828)
@@ -9,236 +9,253 @@
/**
* The base java class for selenium tests implementation.
+ *
* @author Andrey Markavtsov
- *
+ *
*/
public class SeleniumTestBase {
- /** Specifies the time to wait for page rendering */
- private static final Integer pageRenderTime = 5000;
+ /** Specifies the time to wait for page rendering */
+ private static final Integer pageRenderTime = 5000;
- /** The default selenium instance */
- protected DefaultSelenium selenium;
-
- /** Host */
- public String host;
-
- /** Port */
- public String port;
-
- /** Protocol */
- public String protocol;
-
- /** Defines the name of current j2ee application name*/
- public static final String APPLICATION_NAME = "seleniumTest";
-
- public static final String COMPONENT_PREFIX_INSIDE_TABLE =
"_Selenium_Test_Form1:_Selenium_Test_DataTable:0:";
-
- public static final String COMPONENT_PREFIX_INSIDE_PANEL =
"_Selenium_Test_Form2:";
-
- public SeleniumTestBase() {
- /* Default constructor */
- }
-
- public SeleniumTestBase(String protocol, String host, String port) {
- this.host = host;
- this.port = port;
- this.protocol = protocol;
- }
-
- /**
- * @param url
- * @param browser
- * @return
- */
- public DefaultSelenium createSeleniumClient(String url, String browser) {
- return new DefaultSelenium(host, 4444, browser, url);
- }
+ /** The default selenium instance */
+ protected DefaultSelenium selenium;
- /**
- * This method are invoking before selenium tests started
- */
- @BeforeTest
- @Parameters( { "browser" })
- public void startSelenium(String browser) {
- selenium = createSeleniumClient(protocol + "://" + host + ":" +
port + "/", browser);
- selenium.start();
- }
-
- /**
- * Renders page
- */
- protected void renderPage (String homePage) {
- selenium.open(protocol + "://" + host + ":" + port + "/"
+ APPLICATION_NAME + homePage);
- selenium.waitForPageToLoad(String.valueOf(pageRenderTime));
-
- checkPageRendering(); // At the first we check if page has been rendered
- checkJSError(); // At the second we check if JS errors occurred
-
- reRenderForm(); // ReRender component
-
- checkPageRendering(); // Check all again
- checkJSError();
-
- }
-
- /**
- * Return component id inside Data table
- * @param id
- * @return
- */
- public String getComponentIdInsideTable(String id) {
- return COMPONENT_PREFIX_INSIDE_TABLE + id;
- }
-
-
- /**
- * Return component id inside Panel
- * @param id
- * @return
- */
- public String getComponentIdInsidePanel(String id) {
- return COMPONENT_PREFIX_INSIDE_PANEL + id;
- }
-
-
- /**
- * ReRenders the component
- */
- public void reRenderForm () {
- selenium.getEval("selenium.browserbot.getCurrentWindow().reRenderAll();");
- //clickById("_Selenium_Test_ReRender_Form:_reRender");
- waitForAjaxCompletion(3000);
- }
+ /** Host */
+ public String host;
- /**
- * This method are invoking after selenium tests completed
- */
- @AfterTest
- public void stopSelenium() {
- selenium.stop();
- selenium = null;
- }
-
- /**
- * Checks if JS error occurred.
- * Fails test if yes.
- * This method should be invoked after each event or any thing which can be a cause of
JS error.
- */
- public void checkJSError () {
- String error =
selenium.getEval("selenium.browserbot.getCurrentWindow().checkError();");
- if (error != null && !("null".equals(error)) &&
!("".equals(error))) {
- Assert.fail("Failure by the following Javascript error: " + error);
- }
- }
-
- /**
- * Checks if page containing component test has been rendered completely
- */
- public void checkPageRendering() {
- String t1 = getTextById("_Selenium_Test_ControlPoint1");
- String t2 = getTextById("_Selenium_Test_ControlPoint2");
- if (t1 == null || t2 == null || !"Control1".equals(t1) ||
!"Control2".equals(t2)) {
- Assert.fail("The page has been not rendered properlly");
- }
- }
-
- /**
- * Waits while AJAX request will be completed
- * @param miliseconds - time to wait
- */
- public void waitForAjaxCompletion (int miliseconds) {
- selenium.waitForCondition(
- "selenium.browserbot.getCurrentWindow().done==true",
String.valueOf(miliseconds));
- }
-
-
- /**
- * Asserts DOM node value equals to value defined
- * @param id - DOM element id
- * @param value - value defined
- */
- public void AssertValueEquals(String id, String value) {
- String _v = getValueById(id);
- Assert.assertEquals(_v, value);
- }
-
- /**
- * Asserts DOM node value does not equal to value defined
- * @param id - DOM element id
- * @param value - value defined
- */
- public void AssertValueNotEquals(String id, String value) {
- String _v = getValueById(id);
- Assert.assertNotSame(_v, value);
- }
-
-
- /**
- * Asserts DOM node text equals to text defined
- * @param id - DOM element id
- * @param value - text defined
- */
- public void AssertTextEquals(String id, String value) {
- String _v = getTextById(id);
- Assert.assertEquals(_v, value);
- }
-
- /**
- * Asserts DOM node text does not equal to text defined
- * @param id - DOM element id
- * @param value - text defined
- */
- public void AssertTextNotEquals(String id, String value) {
- String _v = getTextById(id);
- Assert.assertNotSame(_v, value);
- }
-
- /**
- * Returns element's text
- * @param id - DOM element id
- * @return
- */
- public String getTextById(String id) {
- return selenium.getText(id);
- }
-
- /**
- * Returns element's value
- * @param id - DOM element id
- * @return
- */
- public String getValueById(String id) {
- return selenium.getValue(id);
- }
-
- /**
- * Clicks on element
- * @param id - DOM element id
- * @return
- */
- public void clickById(String id) {
- selenium.click(id);
- checkJSError();
- }
-
-
- /**
- * Return true if element is visible
- * @param id - DOM element id
- * @return
- */
- public boolean isVisibleById(String id) {
- return selenium.isVisible(id);
- }
-
- /**
- * Creates delay
- * @param miliSeconds
- * @throws InterruptedException
- */
- public void delay (int miliSeconds) throws InterruptedException {
- Thread.sleep(miliSeconds);
- }
+ /** Port */
+ public String port;
+ /** Protocol */
+ public String protocol;
+
+ /** Defines the name of current j2ee application name */
+ public static final String APPLICATION_NAME = "seleniumTest";
+
+ public static final String COMPONENT_PREFIX_INSIDE_TABLE =
"_Selenium_Test_Form1:_Selenium_Test_DataTable:0:";
+
+ public static final String COMPONENT_PREFIX_INSIDE_PANEL =
"_Selenium_Test_Form2:";
+
+ public SeleniumTestBase() {
+ /* Default constructor */
+ }
+
+ public SeleniumTestBase(String protocol, String host, String port) {
+ this.host = host;
+ this.port = port;
+ this.protocol = protocol;
+ }
+
+ /**
+ * @param url
+ * @param browser
+ * @return
+ */
+ public DefaultSelenium createSeleniumClient(String url, String browser) {
+ return new DefaultSelenium(host, 4444, browser, url);
+ }
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeTest
+ @Parameters( { "browser" })
+ public void startSelenium(String browser) {
+ selenium = createSeleniumClient(protocol + "://" + host + ":"
+ port + "/", browser);
+ selenium.start();
+ }
+
+ /**
+ * Renders page
+ */
+ protected void renderPage(String homePage) {
+ selenium.open(protocol + "://" + host + ":" + port +
"/" + APPLICATION_NAME + homePage);
+ selenium.waitForPageToLoad(String.valueOf(pageRenderTime));
+
+ checkPageRendering(); // At the first we check if page has been
+ // rendered
+ checkJSError(); // At the second we check if JS errors occurred
+
+ reRenderForm(); // ReRender component
+
+ checkPageRendering(); // Check all again
+ checkJSError();
+
+ }
+
+ /**
+ * Return component id inside Data table
+ *
+ * @param id
+ * @return
+ */
+ public String getComponentIdInsideTable(String id) {
+ return COMPONENT_PREFIX_INSIDE_TABLE + id;
+ }
+
+ /**
+ * Return component id inside Panel
+ *
+ * @param id
+ * @return
+ */
+ public String getComponentIdInsidePanel(String id) {
+ return COMPONENT_PREFIX_INSIDE_PANEL + id;
+ }
+
+ /**
+ * ReRenders the component
+ */
+ public void reRenderForm() {
+
selenium.getEval("selenium.browserbot.getCurrentWindow().reRenderAll();");
+ // clickById("_Selenium_Test_ReRender_Form:_reRender");
+ waitForAjaxCompletion(3000);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ selenium.stop();
+ selenium = null;
+ }
+
+ /**
+ * Checks if JS error occurred. Fails test if yes. This method should be
+ * invoked after each event or any thing which can be a cause of JS error.
+ */
+ public void checkJSError() {
+ String error =
selenium.getEval("selenium.browserbot.getCurrentWindow().checkError();");
+ if (error != null && !("null".equals(error)) &&
!("".equals(error))) {
+ Assert.fail("Failure by the following Javascript error: " +
error);
+ }
+ }
+
+ /**
+ * Checks if page containing component test has been rendered completely
+ */
+ public void checkPageRendering() {
+ String t1 = getTextById("_Selenium_Test_ControlPoint1");
+ String t2 = getTextById("_Selenium_Test_ControlPoint2");
+ if (t1 == null || t2 == null || !"Control1".equals(t1) ||
!"Control2".equals(t2)) {
+ Assert.fail("The page has been not rendered properlly");
+ }
+ }
+
+ /**
+ * Waits while AJAX request will be completed
+ *
+ * @param miliseconds -
+ * time to wait
+ */
+ public void waitForAjaxCompletion(int miliseconds) {
+
selenium.waitForCondition("selenium.browserbot.getCurrentWindow().done==true",
String.valueOf(miliseconds));
+ }
+
+ /**
+ * Asserts DOM node value equals to value defined
+ *
+ * @param id -
+ * DOM element id
+ * @param value -
+ * value defined
+ */
+ public void AssertValueEquals(String id, String value) {
+ String _v = getValueById(id);
+ Assert.assertEquals(_v, value);
+ }
+
+ /**
+ * Asserts DOM node value does not equal to value defined
+ *
+ * @param id -
+ * DOM element id
+ * @param value -
+ * value defined
+ */
+ public void AssertValueNotEquals(String id, String value) {
+ String _v = getValueById(id);
+ Assert.assertNotSame(_v, value);
+ }
+
+ /**
+ * Asserts DOM node text equals to text defined
+ *
+ * @param id -
+ * DOM element id
+ * @param value -
+ * text defined
+ */
+ public void AssertTextEquals(String id, String value) {
+ String _v = getTextById(id);
+ Assert.assertEquals(_v, value);
+ }
+
+ /**
+ * Asserts DOM node text does not equal to text defined
+ *
+ * @param id -
+ * DOM element id
+ * @param value -
+ * text defined
+ */
+ public void AssertTextNotEquals(String id, String value) {
+ String _v = getTextById(id);
+ Assert.assertNotSame(_v, value);
+ }
+
+ /**
+ * Returns element's text
+ *
+ * @param id -
+ * DOM element id
+ * @return
+ */
+ public String getTextById(String id) {
+ return selenium.getText(id);
+ }
+
+ /**
+ * Returns element's value
+ *
+ * @param id -
+ * DOM element id
+ * @return
+ */
+ public String getValueById(String id) {
+ return selenium.getValue(id);
+ }
+
+ /**
+ * Clicks on element
+ *
+ * @param id -
+ * DOM element id
+ * @return
+ */
+ public void clickById(String id) {
+ selenium.click(id);
+ checkJSError();
+ }
+
+ /**
+ * Return true if element is visible
+ * @param id - DOM element id
+ * @return
+ */
+ public boolean isVisibleById(String id) {
+ return selenium.isVisible(id);
+ }
+
+ /**
+ * Creates delay
+ * @param miliSeconds
+ * @throws InterruptedException
+ */
+ public void delay(int miliSeconds) throws InterruptedException {
+ Thread.sleep(miliSeconds);
+ }
+
}
Show replies by date