diff --git a/idempiere.zk.selenium/.classpath b/idempiere.zk.selenium/.classpath index 74c51989b7..87f030c8d4 100644 --- a/idempiere.zk.selenium/.classpath +++ b/idempiere.zk.selenium/.classpath @@ -2,19 +2,6 @@ - - - - - - - - - - - - - - + diff --git a/idempiere.zk.selenium/Readme.txt b/idempiere.zk.selenium/Readme.txt index 184224dbeb..0079ea32b3 100644 --- a/idempiere.zk.selenium/Readme.txt +++ b/idempiere.zk.selenium/Readme.txt @@ -1,28 +1,10 @@ -config.properties -- configuration file for running Ztl generator and Ztl test - -ZtlGenerator.launch -- Eclipse launch configuration for Ztl generator - -zk.jq.test +test - Example test cases written using Selenium Web Driver and Zk JQ selector -zk.selenese.test -- Example test cases exported from Selenium IDE ( JUnit4 + WebDriver ) - -zk.ztl.test -- Example test cases generated by Ztl generator - -resource/selenese -- selenese test script recorded by Selenium IDE - -resource/ztl/zk/ztl/test -- ztl test script - Notes ====== -* Mapping between selenese ( the native format created by 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. +* Use the AdempiereIDGenerator and your browser's inspect element tool to find out the selector for the element that you need to access. Alternatively, +you can use the script created from Selenium IDE recording as a guide. + +* For execution of test cases, you don't need AdempiereIDGenerator if you only use zk id instead of uuid(html id) -* You must change the "target" instance variable value to "" in the generated ztl java source diff --git a/idempiere.zk.selenium/src/org/idempiere/ui/zk/selenium/Zk.java b/idempiere.zk.selenium/src/org/idempiere/ui/zk/selenium/Zk.java index 86f0c723cd..2bce963221 100644 --- a/idempiere.zk.selenium/src/org/idempiere/ui/zk/selenium/Zk.java +++ b/idempiere.zk.selenium/src/org/idempiere/ui/zk/selenium/Zk.java @@ -5,28 +5,45 @@ import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.SearchContext; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.RemoteWebElement; /** * utility class to find elements using zk jq selector * @author hengsin * */ -public class Zk extends By { +public class Zk { - private String selector; - - private Zk(String selector) { - this.selector = selector; + private Zk() { } - @Override - public List findElements(SearchContext context) { - List list = (List) ((JavascriptExecutor)context).executeScript("return jq('" + selector + "').get();"); - return list; + public static By jq(String selector) { + return new ByJqSelector(selector); } + + public static class ByJqSelector extends By { + private String selector; - public static Zk jq(String selector) { - return new Zk(selector); + private ByJqSelector(String selector) { + this.selector = selector; + } + + @Override + public List findElements(SearchContext context) { + JavascriptExecutor executor = null; + String selector = this.selector; + if (context instanceof WebDriver) { + executor = (JavascriptExecutor) context; + } else { + RemoteWebElement element = (RemoteWebElement) context; + String id = element.getAttribute("id"); + selector = "#"+id+" "+selector; + executor = (JavascriptExecutor) element.getWrappedDriver(); + } + List list = (List) 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 diff --git a/idempiere.zk.selenium/resource/selenese/CreateNewProduct.selenese b/selenese/resource/selenese/CreateNewProduct.selenese similarity index 100% rename from idempiere.zk.selenium/resource/selenese/CreateNewProduct.selenese rename to selenese/resource/selenese/CreateNewProduct.selenese diff --git a/idempiere.zk.selenium/resource/selenese/Login.selenese b/selenese/resource/selenese/Login.selenese similarity index 62% rename from idempiere.zk.selenium/resource/selenese/Login.selenese rename to selenese/resource/selenese/Login.selenese index 12f38d9648..6e4cc68f44 100644 --- a/idempiere.zk.selenium/resource/selenese/Login.selenese +++ b/selenese/resource/selenese/Login.selenese @@ -18,27 +18,42 @@ 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 + css=#loginPanel_lstLanguage_English > td.z-comboitem-text + + + + pause + 1000 + + + + click + id=loginPanel_chkSelectRole-real @@ -48,17 +63,17 @@ waitForElementPresent - id=rolePanel_grdChooseRole_rowclient_lstClient-btn + id=rolePanel_lstClient-btn click - id=rolePanel_grdChooseRole_rowclient_lstClient-btn + id=rolePanel_lstClient-btn click - css=#rolePanel_grdChooseRole_rowclient_lstClient_GardenWorld > td.z-comboitem-text + css=#rolePanel_lstClient_GardenWorld > td.z-comboitem-text @@ -68,12 +83,12 @@ click - id=rolePanel_grdChooseRole_rowRole_lstRole-btn + id=rolePanel_lstRole-btn click - css=#rolePanel_grdChooseRole_rowRole_lstRole_GardenWorld_Admin > td.z-comboitem-text + css=#rolePanel_lstRole_GardenWorld_Admin > td.z-comboitem-text @@ -83,12 +98,12 @@ click - id=rolePanel_grdChooseRole_rowOrganisation_lstOrganisation-btn + id=rolePanel_lstOrganisation-btn click - css=#rolePanel_grdChooseRole_rowOrganisation_lstOrganisation_HQ > td.z-comboitem-text + css=#rolePanel_lstOrganisation_HQ > td.z-comboitem-text @@ -104,7 +119,7 @@ assertText id=loginUserAndRole - SuperUser@GardenWorld.HQ/GardenWorld Admin + GardenAdmin@GardenWorld.HQ/GardenWorld Admin diff --git a/idempiere.zk.selenium/src/zk/selenese/test/LoginTest.java b/selenese/src/test/LoginTest.java similarity index 54% rename from idempiere.zk.selenium/src/zk/selenese/test/LoginTest.java rename to selenese/src/test/LoginTest.java index 3c22648117..7cd050b063 100644 --- a/idempiere.zk.selenium/src/zk/selenese/test/LoginTest.java +++ b/selenese/src/test/LoginTest.java @@ -1,4 +1,4 @@ -package zk.selenese.test; +package test; import java.util.concurrent.TimeUnit; import org.junit.*; @@ -19,49 +19,52 @@ public class LoginTest { public void setUp() throws Exception { driver = new FirefoxDriver(); baseUrl = "http://127.0.0.1:8080/"; - driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } @Test public void testLogin() throws Exception { // open | /webui/ | - driver.get(baseUrl + "/webui/"); - // type | id=loginPanel_grdLogin_rowUser_txtUserId | SuperUser - driver.findElement(By.id("loginPanel_grdLogin_rowUser_txtUserId")).clear(); - driver.findElement(By.id("loginPanel_grdLogin_rowUser_txtUserId")).sendKeys("SuperUser"); + driver.get(baseUrl + "webui/"); + // type | id=loginPanel_grdLogin_rowUser_txtUserId | GardenAdmin + driver.findElement(By.id("loginPanel_txtUserId")).clear(); + driver.findElement(By.id("loginPanel_txtUserId")).sendKeys("GardenAdmin"); // fireEvent | id=loginPanel_grdLogin_rowUser_txtUserId | blur // not needed for webdriver - // type | id=loginPanel_grdLogin_rowPassword_txtPassword | System - driver.findElement(By.id("loginPanel_grdLogin_rowPassword_txtPassword")).clear(); - driver.findElement(By.id("loginPanel_grdLogin_rowPassword_txtPassword")).sendKeys("System"); + // type | id=loginPanel_grdLogin_rowPassword_txtPassword | GardenAdmin + driver.findElement(By.id("loginPanel_txtPassword")).clear(); + driver.findElement(By.id("loginPanel_txtPassword")).sendKeys("GardenAdmin"); // fireEvent | id=loginPanel_grdLogin_rowPassword_txtPassword | blur // not needed for webdriver // click | id=loginPanel_grdLogin_rowSelectRole_chkSelectRole-real | - driver.findElement(By.id("loginPanel_grdLogin_rowSelectRole_chkSelectRole-real")).click(); + driver.findElement(By.id("loginPanel_chkSelectRole-real")).click(); // click | loginPanel_Ok | 10 driver.findElement(By.id("loginPanel_Ok")).click(); // waitForElementPresent | id=rolePanel_grdChooseRole_rowclient_lstClient-btn | for (int second = 0;; second++) { if (second >= 60) fail("timeout"); - try { if (isElementPresent(By.id("rolePanel_grdChooseRole_rowclient_lstClient-btn"))) break; } catch (Exception e) {} + try { if (isElementPresent(By.id("rolePanel_lstClient-btn"))) break; } catch (Exception e) {} Thread.sleep(1000); } - // click | id=rolePanel_grdChooseRole_rowclient_lstClient-btn | - driver.findElement(By.id("rolePanel_grdChooseRole_rowclient_lstClient-btn")).click(); - // click | css=#rolePanel_grdChooseRole_rowclient_lstClient_GardenWorld > td.z-comboitem-text | - driver.findElement(By.cssSelector("#rolePanel_grdChooseRole_rowclient_lstClient_GardenWorld > td.z-comboitem-text")).click(); - Thread.sleep(1000); + WebElement lstClient = driver.findElement(By.id("rolePanel_lstClient")); + if (lstClient != null && lstClient.isDisplayed()) { + // click | id=rolePanel_grdChooseRole_rowclient_lstClient-btn | + driver.findElement(By.id("rolePanel_lstClient-btn")).click(); + // click | css=#rolePanel_grdChooseRole_rowclient_lstClient_GardenWorld > td.z-comboitem-text | + driver.findElement(By.cssSelector("#rolePanel_lstClient_GardenWorld > td.z-comboitem-text")).click(); + Thread.sleep(1000); + } // click | id=rolePanel_grdChooseRole_rowRole_lstRole-btn | - driver.findElement(By.id("rolePanel_grdChooseRole_rowRole_lstRole-btn")).click(); + driver.findElement(By.id("rolePanel_lstRole-btn")).click(); // click | css=#rolePanel_grdChooseRole_rowRole_lstRole_GardenWorld_Admin > td.z-comboitem-text | - driver.findElement(By.cssSelector("#rolePanel_grdChooseRole_rowRole_lstRole_GardenWorld_Admin > td.z-comboitem-text")).click(); + driver.findElement(By.cssSelector("#rolePanel_lstRole_GardenWorld_Admin > td.z-comboitem-text")).click(); Thread.sleep(1000); // click | id=rolePanel_grdChooseRole_rowOrganisation_lstOrganisation-btn | - driver.findElement(By.id("rolePanel_grdChooseRole_rowOrganisation_lstOrganisation-btn")).click(); + driver.findElement(By.id("rolePanel_lstOrganisation-btn")).click(); // click | css=#rolePanel_grdChooseRole_rowOrganisation_lstOrganisation_HQ > td.z-comboitem-text | - driver.findElement(By.cssSelector("#rolePanel_grdChooseRole_rowOrganisation_lstOrganisation_HQ > td.z-comboitem-text")).click(); + driver.findElement(By.cssSelector("#rolePanel_lstOrganisation_HQ > td.z-comboitem-text")).click(); // click | rolePanel_Ok | driver.findElement(By.id("rolePanel_Ok")).click(); // waitForElementPresent | loginUserAndRole | @@ -70,8 +73,8 @@ public class LoginTest { try { if (isElementPresent(By.id("loginUserAndRole"))) break; } catch (Exception e) {} Thread.sleep(1000); } - // assertText | loginUserAndRole | SuperUser@GardenWorld.HQ/GardenWorld Admin - assertEquals("SuperUser@GardenWorld.HQ/GardenWorld Admin", driver.findElement(By.id("loginUserAndRole")).getText()); + // assertText | loginUserAndRole | GardenAdmin@GardenWorld.HQ/GardenWorld Admin + assertEquals("GardenAdmin@GardenWorld.HQ/GardenWorld Admin", driver.findElement(By.id("loginUserAndRole")).getText()); } @After diff --git a/ztl/.classpath b/ztl/.classpath new file mode 100644 index 0000000000..2c1f6f13af --- /dev/null +++ b/ztl/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/ztl/.project b/ztl/.project new file mode 100644 index 0000000000..096b11b5eb --- /dev/null +++ b/ztl/.project @@ -0,0 +1,17 @@ + + + ztl + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ztl/.settings/org.eclipse.jdt.core.prefs b/ztl/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..8000cd6ca6 --- /dev/null +++ b/ztl/.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/ztl/Readme.txt b/ztl/Readme.txt new file mode 100644 index 0000000000..aeba42bb26 --- /dev/null +++ b/ztl/Readme.txt @@ -0,0 +1,18 @@ +config.properties +- configuration file for running Ztl generator and Ztl test + +ZtlGenerator.launch +- Eclipse launch configuration for Ztl generator + +test +- Example test cases generated by Ztl generator + +resource/test +- ztl test script + +Notes +====== +* You must change the "target" instance variable value to "" in the generated ztl java source + +* Use the AdempiereIDGenerator and your browser's inspect element tool to find out the selector for the element that you need to access. Alternatively, +you can use the script created from Selenium IDE recording as a guide. \ No newline at end of file diff --git a/idempiere.zk.selenium/ZtlGenerator.launch b/ztl/ZtlGenerator.launch similarity index 63% rename from idempiere.zk.selenium/ZtlGenerator.launch rename to ztl/ZtlGenerator.launch index 0f11ed8cac..0d25bbd6d1 100644 --- a/idempiere.zk.selenium/ZtlGenerator.launch +++ b/ztl/ZtlGenerator.launch @@ -1,20 +1,19 @@ - + - - - - - + + + + - - + + diff --git a/idempiere.zk.selenium/config.properties b/ztl/config.properties similarity index 91% rename from idempiere.zk.selenium/config.properties rename to ztl/config.properties index 5b668703d0..f319b6b2fa 100644 --- a/idempiere.zk.selenium/config.properties +++ b/ztl/config.properties @@ -2,7 +2,7 @@ server=http://127.0.0.1:8080 context-path=/webui delay=500 action= -timeout=20000 +timeout=10000 browser=firefox granularity=1 leniency=1 diff --git a/idempiere.zk.selenium/lib/ztl/Readme.txt b/ztl/lib/Readme.txt similarity index 61% rename from idempiere.zk.selenium/lib/ztl/Readme.txt rename to ztl/lib/Readme.txt index 0c9ef8e10f..bf37370867 100644 --- a/idempiere.zk.selenium/lib/ztl/Readme.txt +++ b/ztl/lib/Readme.txt @@ -1,8 +1,5 @@ ztl-2.0.0-SNAPSHOT.jar - for execution of ztl generator and ztl test cases -selenium-server-standalone-2.25.0.jar -- for execution of ztl test cases - others - for execution of ztl generator diff --git a/idempiere.zk.selenium/resource/ztl/zk/ztl/test/LoginTest.ztl b/ztl/resource/test/LoginTest.ztl similarity index 52% rename from idempiere.zk.selenium/resource/ztl/zk/ztl/test/LoginTest.ztl rename to ztl/resource/test/LoginTest.ztl index b7c29a894a..a6790cd269 100644 --- a/idempiere.zk.selenium/resource/ztl/zk/ztl/test/LoginTest.ztl +++ b/ztl/resource/test/LoginTest.ztl @@ -2,13 +2,17 @@ diff --git a/idempiere.zk.selenium/src/zk/ztl/test/LoginTest.java b/ztl/src/test/LoginTest.java similarity index 80% rename from idempiere.zk.selenium/src/zk/ztl/test/LoginTest.java rename to ztl/src/test/LoginTest.java index 0ea68e8a42..dbb0f855e6 100644 --- a/idempiere.zk.selenium/src/zk/ztl/test/LoginTest.java +++ b/ztl/src/test/LoginTest.java @@ -5,14 +5,14 @@ Description: History: - Dec, 6, 2012 17:09:52 PM + Dec, 11, 2012 00:52:22 AM Copyright (C) 2012 Potix Corporation. All Rights Reserved. This program is distributed under Apache License Version 2.0 in the hope that it will be useful, but WITHOUT ANY WARRANTY. */ -package zk.ztl.test; +package test; import org.junit.Test; import org.zkoss.ztl.Element; import org.zkoss.ztl.JQuery; @@ -32,7 +32,7 @@ public class LoginTest extends ZKClientTestCase { public LoginTest() { target = ""; browsers = getBrowsers("firefox"); - _timeout = 20000; + _timeout = 10000; caseID = getClass().getSimpleName(); } @@ -53,13 +53,17 @@ public class LoginTest extends ZKClientTestCase { /** start **/ /** client code **/ - type(jq("$loginPanel $txtUserId"), "SuperUser"); - type(jq("$loginPanel $txtPassword"), "System"); + type(jq("$loginPanel $txtUserId"), "GardenAdmin"); + type(jq("$loginPanel $txtPassword"), "GardenAdmin"); click(widget(jq("$loginPanel $chkSelectRole")).$n("real")); click(jq("$loginPanel $Ok")); waitResponse(); + JQuery lstClient = jq("$rolePanel $lstClient"); + if (lstClient.exists() && lstClient.isVisible()) { click(jq("$rolePanel $lstClient ~ .z-combobox-btn")); click(jq("$rolePanel $lstClient $GardenWorld")); + waitResponse(); + } click(jq("$rolePanel $lstRole ~ .z-combobox-btn")); click(jq("$rolePanel $lstRole $GardenWorld\\\\ Admin")); waitResponse(); @@ -67,7 +71,7 @@ public class LoginTest extends ZKClientTestCase { click(jq("$rolePanel $lstOrganisation $HQ")); click(jq("$rolePanel $Ok")); waitResponse(); - verifyEquals("SuperUser@GardenWorld.HQ/GardenWorld Admin", jq("$loginUserAndRole").text()); + verifyEquals("GardenAdmin@GardenWorld.HQ/GardenWorld Admin", jq("$loginUserAndRole").text()); /** end **/ } catch (SeleniumException e) {