) executor.executeScript("return jq('" + selector + "').get();");
+ return list;
+ }
}
}
diff --git a/idempiere.zk.selenium/src/test/AbstractTestCase.java b/idempiere.zk.selenium/src/test/AbstractTestCase.java
new file mode 100644
index 0000000000..7c7a4d986e
--- /dev/null
+++ b/idempiere.zk.selenium/src/test/AbstractTestCase.java
@@ -0,0 +1,142 @@
+package test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.concurrent.TimeUnit;
+
+import org.idempiere.ui.zk.selenium.Zk;
+import org.junit.After;
+import org.junit.Before;
+import org.openqa.selenium.By;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.firefox.FirefoxDriver;
+
+public class AbstractTestCase {
+
+ protected WebDriver driver;
+ protected StringBuffer verificationErrors = new StringBuffer();
+ private String baseUrl;
+
+ @Before
+ public void setUp() throws Exception {
+ driver = new FirefoxDriver();
+// driver = new ChromeDriver();
+ baseUrl = "http://localhost:8080/webui/";
+ driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
+ driver.manage().window().maximize();
+ }
+
+ protected void type(String locator, String value) {
+ WebElement element = driver.findElement(Zk.jq(locator));
+ element.clear();
+ element.sendKeys(value);
+ }
+
+ protected void select(String locator, String label) {
+ WebElement select = driver.findElement(Zk.jq(locator));
+ select(select, label);
+ }
+
+ protected void select(WebElement select, String label) {
+ select.findElement(Zk.jq(".z-combobox-btn")).click();
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {}
+ select.findElement(Zk.jq("$"+escape(label))).click();
+ }
+
+ protected void clickCheckbox(String locator) {
+ driver.findElement(Zk.jq("$"+locator+" ~ input")).click();
+ }
+
+ protected void clickButton(String locator) {
+ driver.findElement(Zk.jq(locator)).click();
+ }
+
+ protected void login() throws Exception {
+ driver.get(baseUrl);
+
+ Thread.sleep(500);
+
+ // enter user name
+ type("$loginPanel $txtUserId", "GardenAdmin");
+
+ // enter password
+ type("$loginPanel $txtPassword", "GardenAdmin");
+
+ //select language
+ select("$loginPanel $lstLanguage", "English");
+
+ // check select role
+ clickCheckbox("$loginPanel $chkSelectRole");
+ // click ok button
+ clickButton("$loginPanel $Ok");
+
+ selectRole("GardenWorld", "GardenWorld Admin", "HQ");
+
+ // wait for home page
+ WebElement loginUserElement = waitForElement("$loginUserAndRole");
+
+ // assert login user and role
+ assertEquals("GardenAdmin@GardenWorld.HQ/GardenWorld Admin", loginUserElement.getText());
+ }
+
+ protected WebElement waitForElement(String locator) throws InterruptedException {
+ By loginUserQuery = Zk.jq(locator);
+ for (int second = 0;; second++) {
+ if (second >= 60)
+ fail("timeout");
+ try {
+ if (isElementPresent(loginUserQuery))
+ break;
+ } catch (Exception e) {
+ }
+ Thread.sleep(1000);
+ }
+ return driver.findElement(loginUserQuery);
+ }
+
+ protected void selectRole(String client, String role, String org) throws InterruptedException {
+ // wait for role panel
+ WebElement lstClient = waitForElement("$rolePanel $lstClient");
+
+ // select client
+ if (lstClient != null && lstClient.isDisplayed()) {
+ select(lstClient, client);
+ }
+
+ // select role
+ select("$rolePanel $lstRole", role);
+
+ // select organization
+ select("$rolePanel $lstOrganisation", org);
+
+ // click ok button
+ clickButton("$rolePanel $Ok");
+ }
+
+ protected boolean isElementPresent(By by) {
+ try {
+ driver.findElement(by);
+ return true;
+ } catch (NoSuchElementException e) {
+ return false;
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ driver.quit();
+ String verificationErrorString = verificationErrors.toString();
+ if (!"".equals(verificationErrorString)) {
+ fail(verificationErrorString);
+ }
+ }
+
+ protected String escape(String role) {
+ return role.replace(" ", "\\\\ ");
+ }
+}
diff --git a/idempiere.zk.selenium/src/test/ChangeRoleTest.java b/idempiere.zk.selenium/src/test/ChangeRoleTest.java
new file mode 100644
index 0000000000..b2bc6eba5e
--- /dev/null
+++ b/idempiere.zk.selenium/src/test/ChangeRoleTest.java
@@ -0,0 +1,30 @@
+package test;
+
+import org.idempiere.ui.zk.selenium.Zk;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import static org.junit.Assert.*;
+
+public class ChangeRoleTest extends AbstractTestCase {
+
+ @Test
+ public void testLogin() throws Exception {
+ login();
+
+ Thread.sleep(2000);
+
+ driver.findElement(Zk.jq("$changeRole")).click();
+
+ Thread.sleep(1000);
+
+ // wait for home page
+ selectRole("GardenWorld", "GardenWorld User", "HQ");
+
+ WebElement element = waitForElement("$loginUserAndRole");
+
+ // assert login user and role
+ assertEquals("GardenAdmin@GardenWorld.HQ/GardenWorld User", element.getText());
+ }
+
+}
diff --git a/idempiere.zk.selenium/src/test/LoginTest.java b/idempiere.zk.selenium/src/test/LoginTest.java
new file mode 100644
index 0000000000..cd28280df6
--- /dev/null
+++ b/idempiere.zk.selenium/src/test/LoginTest.java
@@ -0,0 +1,15 @@
+package test;
+
+import org.junit.*;
+
+/**
+ * Web Driver + zk jq selector, doesn't required AdempiereIdGenerator
+ * @author hengsin
+ *
+ */
+public class LoginTest extends AbstractTestCase {
+ @Test
+ public void testLogin() throws Exception {
+ login();
+ }
+}
diff --git a/idempiere.zk.selenium/src/test/LogoutTest.java b/idempiere.zk.selenium/src/test/LogoutTest.java
new file mode 100644
index 0000000000..afaca9cc6a
--- /dev/null
+++ b/idempiere.zk.selenium/src/test/LogoutTest.java
@@ -0,0 +1,21 @@
+package test;
+
+import org.idempiere.ui.zk.selenium.Zk;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import static org.junit.Assert.*;
+
+public class LogoutTest extends AbstractTestCase {
+
+ @Test
+ public void testLogin() throws Exception {
+ login();
+ WebElement logout = driver.findElement(Zk.jq("$logout"));
+ logout.click();
+
+ Thread.sleep(2000);
+ WebElement loginWindow = driver.findElement(Zk.jq("$loginPanel"));
+ assertTrue(loginWindow != null && loginWindow.isDisplayed());
+ }
+}
diff --git a/idempiere.zk.selenium/src/zk/jq/test/LoginTest.java b/idempiere.zk.selenium/src/zk/jq/test/LoginTest.java
deleted file mode 100644
index 1f4d27a7ff..0000000000
--- a/idempiere.zk.selenium/src/zk/jq/test/LoginTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package zk.jq.test;
-
-import java.util.concurrent.TimeUnit;
-
-import org.idempiere.ui.zk.selenium.Zk;
-import org.junit.*;
-import static org.junit.Assert.*;
-import org.openqa.selenium.*;
-import org.openqa.selenium.firefox.FirefoxDriver;
-
-/**
- * Web Driver + zk jq selector, doesn't required AdempiereIdGenerator
- * @author hengsin
- *
- */
-public class LoginTest {
- private WebDriver driver;
- private String baseUrl;
- private StringBuffer verificationErrors = new StringBuffer();
- @Before
- public void setUp() throws Exception {
- driver = new FirefoxDriver();
- baseUrl = "http://127.0.0.1:8080/";
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- }
-
- @Test
- public void testLogin() throws Exception {
- // open | /webui/ |
- driver.get(baseUrl + "/webui/");
- // enter user name
- driver.findElement(Zk.jq("$loginPanel $txtUserId")).clear();
- driver.findElement(Zk.jq("$loginPanel $txtUserId")).sendKeys("SuperUser");
-
- // enter password
- driver.findElement(Zk.jq("$loginPanel $txtPassword")).clear();
- driver.findElement(Zk.jq("$loginPanel $txtPassword")).sendKeys("System");
-
- // check select role
- driver.findElement(Zk.jq("$loginPanel $chkSelectRole ~ input")).click();
- // click ok button
- driver.findElement(Zk.jq("$loginPanel $Ok")).click();
- // wait for role panel
- for (int second = 0;; second++) {
- if (second >= 60) fail("timeout");
- try { if (isElementPresent(Zk.jq("$rolePanel $lstClient"))) break; } catch (Exception e) {}
- Thread.sleep(1000);
- }
-
- // select GardenWorld client
- driver.findElement(Zk.jq("$rolePanel $lstClient ~ .z-combobox-btn")).click();
- driver.findElement(Zk.jq("$rolePanel $lstClient $GardenWorld")).click();
-
- // select GardenWorld admin role
- driver.findElement(Zk.jq("$rolePanel $lstRole ~ .z-combobox-btn")).click();
- //note the 4 \\\\ needed to escape the space character. ugly but it works
- driver.findElement(Zk.jq("$rolePanel $lstRole $GardenWorld\\\\ Admin")).click();
-
- // select HQ organization
- driver.findElement(Zk.jq("$rolePanel $lstOrganisation ~ .z-combobox-btn")).click();
- driver.findElement(Zk.jq("$rolePanel $lstOrganisation $HQ")).click();
-
- // click ok button
- driver.findElement(Zk.jq("$rolePanel $Ok")).click();
-
- // wait for home page
- for (int second = 0;; second++) {
- if (second >= 60) fail("timeout");
- try { if (isElementPresent(Zk.jq("$loginUserAndRole"))) break; } catch (Exception e) {}
- Thread.sleep(1000);
- }
-
- // assert login user and role
- assertEquals("SuperUser@GardenWorld.HQ/GardenWorld Admin", driver.findElement(Zk.jq("$loginUserAndRole")).getText());
- }
-
- @After
- public void tearDown() throws Exception {
- driver.quit();
- String verificationErrorString = verificationErrors.toString();
- if (!"".equals(verificationErrorString)) {
- fail(verificationErrorString);
- }
- }
-
- private boolean isElementPresent(By by) {
- try {
- driver.findElement(by);
- return true;
- } catch (NoSuchElementException e) {
- return false;
- }
- }
-}
diff --git a/selenese/.classpath b/selenese/.classpath
new file mode 100644
index 0000000000..f33efe0132
--- /dev/null
+++ b/selenese/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/selenese/.project b/selenese/.project
new file mode 100644
index 0000000000..1d131caae9
--- /dev/null
+++ b/selenese/.project
@@ -0,0 +1,17 @@
+
+
+ selenese
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/selenese/.settings/org.eclipse.jdt.core.prefs b/selenese/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..8000cd6ca6
--- /dev/null
+++ b/selenese/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/selenese/Readme.txt b/selenese/Readme.txt
new file mode 100644
index 0000000000..ef2e6b224a
--- /dev/null
+++ b/selenese/Readme.txt
@@ -0,0 +1,20 @@
+test
+- Example test cases exported from Selenium IDE ( JUnit4 + WebDriver )
+
+resource/selenese
+- selenese test script recorded by Selenium IDE
+
+Notes
+======
+* The mapping between selenese ( the native format created from Selenium IDE recording ) and
+ web driver export is not one to one. For e.g, the fireEvent command is not needed in
+ web driver test script.
+
+* While both "id=loginPanel_Ok" and "loginPanel_Ok" work the same when you execute selenese test with Selenium IDE,
+you must use the id= syntax for the web driver export to work.
+
+* The selenese script recorded by Selenium IDE required changes ( most of the time, you need to add insert fireEvent and sleep command )
+before you can run it with Selenium IDE. However, it mostly work if you export it to the Java WebDriver format and run it from Eclipse.
+
+* AdempiereIDGenerator is required for the recording and execution of selenese test cases.
+
diff --git a/idempiere.zk.selenium/resource/selenese/ChangeRole.selenese b/selenese/resource/selenese/ChangeRole.selenese
similarity index 54%
rename from idempiere.zk.selenium/resource/selenese/ChangeRole.selenese
rename to selenese/resource/selenese/ChangeRole.selenese
index 83ce8d2a60..8df5b1eab1 100644
--- a/idempiere.zk.selenium/resource/selenese/ChangeRole.selenese
+++ b/selenese/resource/selenese/ChangeRole.selenese
@@ -18,47 +18,32 @@
type |
- id=loginPanel_grdLogin_rowUser_txtUserId |
- SuperUser |
+ id=loginPanel_txtUserId |
+ GardenAdmin |
fireEvent |
- id=loginPanel_grdLogin_rowUser_txtUserId |
+ id=loginPanel_txtUserId |
blur |
type |
- id=loginPanel_grdLogin_rowPassword_txtPassword |
- System |
+ id=loginPanel_txtPassword |
+ GardenAdmin |
fireEvent |
- id=loginPanel_grdLogin_rowPassword_txtPassword |
+ id=loginPanel_txtPassword |
blur |
click |
- id=loginPanel_grdLogin_rowSelectRole_chkSelectRole-real |
+ id=loginPanel_lstLanguage-btn |
|
click |
- id=loginPanel_Ok |
- 10 |
-
-
- waitForElementPresent |
- id=rolePanel_grdChooseRole_rowclient_lstClient-btn |
- |
-
-
- click |
- id=rolePanel_grdChooseRole_rowclient_lstClient-btn |
- |
-
-
- click |
- css=#rolePanel_grdChooseRole_rowclient_lstClient_zk_GardenWorld > td.z-comboitem-text |
+ css=#loginPanel_lstLanguage_English > td.z-comboitem-text |
|
@@ -68,12 +53,57 @@
click |
- id=rolePanel_grdChooseRole_rowOrganisation_lstOrganisation-btn |
+ id=loginPanel_chkSelectRole-real |
|
click |
- css=#rolePanel_grdChooseRole_rowOrganisation_lstOrganisation_HQ > td.z-comboitem-text |
+ id=loginPanel_Ok |
+ 10 |
+
+
+ waitForElementPresent |
+ id=rolePanel_lstClient-btn |
+ |
+
+
+ click |
+ id=rolePanel_lstClient-btn |
+ |
+
+
+ click |
+ css=#rolePanel_lstClient_GardenWorld > td.z-comboitem-text |
+ |
+
+
+ pause |
+ 1000 |
+ |
+
+
+ click |
+ id=rolePanel_lstRole-btn |
+ |
+
+
+ click |
+ css=#rolePanel_lstRole_GardenWorld_Admin > td.z-comboitem-text |
+ |
+
+
+ pause |
+ 1000 |
+ |
+
+
+ click |
+ id=rolePanel_lstOrganisation-btn |
+ |
+
+
+ click |
+ css=#rolePanel_lstOrganisation_HQ > td.z-comboitem-text |
|
@@ -89,7 +119,7 @@
assertText |
id=loginUserAndRole |
- SuperUser@GardenWorld.HQ/GardenWorld Admin |
+ GardenAdmin@GardenWorld.HQ/GardenWorld Admin |
click |
@@ -98,17 +128,32 @@
waitForElementPresent |
- id=rolePanel_grdChooseRole_rowclient_lstClient |
+ id=rolePanel_lstClient |
|
click |
- id=rolePanel_grdChooseRole_rowclient_lstClient-btn |
+ id=rolePanel_lstRole-btn |
|
click |
- css=#rolePanel_grdChooseRole_rowclient_lstClient_System_ > td.z-comboitem-text |
+ css=#rolePanel_lstRole_GardenWorld_User > td.z-comboitem-text |
+ |
+
+
+ pause |
+ 1000 |
+ |
+
+
+ click |
+ id=rolePanel_lstOrganisation-btn |
+ |
+
+
+ click |
+ css=#rolePanel_lstOrganisation_HQ > td.z-comboitem-text |
|
@@ -124,7 +169,7 @@
assertText |
id=loginUserAndRole |
- SuperUser@System.*/System Administrator |
+ GardenAdmin@GardenWorld.HQ/GardenWorld User |