diff --git a/tests/functional/pom.xml b/tests/functional/pom.xml new file mode 100644 index 000000000..198c20793 --- /dev/null +++ b/tests/functional/pom.xml @@ -0,0 +1,153 @@ + + 4.0.0 + + com.colosa.qa.automation + pm3FunctionalTests + 1.0-SNAPSHOT + jar + + pm3FunctionalTests + http://maven.apache.org + + + UTF-8 + UTF-8 + + + + + junit + junit + 4.11 + + + + + + org.seleniumhq.selenium + selenium-java + 2.39.0 + + + + com.itextpdf + itextpdf + 5.1.3 + jar + + + + com.itextpdf.tool + xmlworker + 1.1.1 + jar + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + true + ${JAVA_JDK_1_7_JAVAC} + UTF-8 + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + + **/TestSuiteAll.java + + + + + + org.apache.maven.surefire + surefire-junit47 + 2.16 + + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.16 + + + + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.16 + + + + + + diff --git a/tests/functional/src/main/app.conf b/tests/functional/src/main/app.conf new file mode 100644 index 000000000..56c484847 --- /dev/null +++ b/tests/functional/src/main/app.conf @@ -0,0 +1 @@ +#This file must be filled with the configuration settings for the application diff --git a/tests/functional/src/main/default.conf b/tests/functional/src/main/default.conf new file mode 100644 index 000000000..f586bd250 --- /dev/null +++ b/tests/functional/src/main/default.conf @@ -0,0 +1,27 @@ +#Default Browser connection Data +server.url=http://192.168.11.188/ +#browser.name: chrome, firefox, ie +browser.name=firefox +#browser.mode: local, remote +browser.mode=local +#browser.version=22 +#WINDOWS, MAC, LINUX +browser.platform=WINDOWS +#remote.server +remote.server.url=http://192.168.11.169:4444/wd/hub +debug.enable=1 +permissions.file.upload=archivo.txt +implicit.wait.seconds=10 + +#testing browsers (firefox, chrome, ie) +browser.count=1 +browser.browser1=firefox +browser.platform1=WINDOWS +#browser.version1=23 +browser.browser2=chrome +browser.platform2=WINDOWS +#browser.version2=22 +browser.browser3=ie +browser.platform3=WINDOWS +#browser.version3=22 + diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/Browser.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Browser.java new file mode 100644 index 000000000..eba97a52e --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Browser.java @@ -0,0 +1,164 @@ +package com.colosa.qa.automatization.common; + +/* +public class Browser { + + private static WebDriver _driver = null; + private static BrowserInstance _browserInstance = null; + private static long _timeoutSeconds = 0; + + + public static void checkBrowserSettingsFromSystemProperties() throws IOException { + //Read browser information from default page this is done in the constructor of Browsersettings + + //Read browser information from registry + //-Dbrowser.settings=1 -Dbrowser.mode=local -Dbrowser.name=firefox + //-Dbrowser.settings=1 -Dbrowser.mode=remote -Dbrowser.name=firefox -Dremote.server.url=http:// browser.version= + //if variable set from system properties overrride configuration of browser + String setBrowserSettings = System.getProperty("browser.settings"); + + if(setBrowserSettings != null){ + System.out.printf("User Browser Settings detected\n"); + String browserMode = System.getProperty("browser.mode"); + BrowserConfiguration.getInstance().setBrowserMode(browserMode); + String browserName = System.getProperty("browser.name"); + BrowserConfiguration.getInstance().setBrowserName(browserName); + + System.out.printf(" Browser Mode: %s, Browser Name: %s \n", + browserMode, browserName); + + if(browserMode.equals("remote")){ + String browserVersion = System.getProperty("browser.version"); + BrowserConfiguration.getInstance().setBrowserVersion(browserVersion); + String browserPlatform = System.getProperty("browser.platform"); + BrowserConfiguration.getInstance().setBrowserPlatform(browserPlatform); + String remoteServerUrl = System.getProperty("remote.server.url"); + BrowserConfiguration.getInstance().setRemoteServerUrl(remoteServerUrl); + + System.out.printf(" Browser Version: %s, Browser Platform: %s, Remote Server URL:%s\n", + browserVersion, browserPlatform, remoteServerUrl ); + + } + } + + } + + // + * Create a default instance of the browser using default configuration from registry + * @return Return the instance of the browser created by default + * @throws FileNotFoundException + * @throws IOException + // + public static WebDriver driver() throws FileNotFoundException, IOException{ + if(_driver == null){ + System.out.printf("Create New Browser instance.\n"); + + checkBrowserSettingsFromSystemProperties(); + + + String browserMode = BrowserConfiguration.getInstance().getBrowserMode(); //ConfigurationSettings.getInstance().getSetting("browser.mode"); + String browserName = "firefox"; + + browserName = BrowserConfiguration.getInstance().getBrowserName(); + + if(browserMode.equals("local")){ + _browserInstance = new BrowserInstance(browserMode, browserName, "", "", ""); + _driver = _browserInstance.getInstanceDriver(); + } + + if(browserMode.equals("remote")){ + String browserVersion = BrowserConfiguration.getInstance().getBrowserVersion();//ConfigurationSettings.getInstance().getSetting("browser.version"); + String browserPlatform = BrowserConfiguration.getInstance().getBrowserPlatform();//ConfigurationSettings.getInstance().getSetting("browser.platform"); + String remoteServerUrl = BrowserConfiguration.getInstance().getRemoteServerUrl();//ConfigurationSettings.getInstance().getSetting("remote.server.url"); + + System.out.printf("Remote browser:%s, version:%s, platform:%s, url:%s \n", + browserName, browserVersion, browserPlatform, remoteServerUrl); + + _browserInstance = new BrowserInstance(browserMode, browserName, browserVersion, browserPlatform, remoteServerUrl); + + _driver = _browserInstance.getInstanceDriver(); + } + } + return _driver; + } + + + + public static void maximize(){ + _browserInstance.maximize(); + } + + public static void gotoUrl(String url){ + _browserInstance.gotoUrl(url); + } + + public static String title(){ + return _browserInstance.title(); + } + + public static void close(){ + _browserInstance.quit(); + + _driver = null; + _browserInstance = null; + } + + public static void quit(){ + _browserInstance.quit(); + _driver = null; + _browserInstance = null; + } + + public static By getBySearchCriteria(String str, Object... args) throws Exception{ + return _browserInstance.getBySearchCriteria(str, args); + } + + public static By getBySearchCriteriaUsingCriteria(String searchCriteria) throws Exception{ + return _browserInstance.getBySearchCriteriaUsingCriteria(searchCriteria); + } + + public static WebElement getParent(WebElement element) throws Exception{ + return _browserInstance.getParent(element); + } + + public static WebElement getElement(String str) throws Exception{ + return _browserInstance.getElement(str); + } + + public static List getElements(String str) throws Exception{ + return _browserInstance.getElements(str); + } + + public static WebElement getElementf(String str, Object... args) throws Exception{ + return _browserInstance.getElementf(str, args); + } + + public static Boolean elementExists(String key, int occurrences) throws Exception{ + return _browserInstance.elementExists(key, occurrences); + } + + public static Boolean elementExists(String key) throws Exception{ + return _browserInstance.elementExists(key); + } + + public static Boolean elementExistsSearchCriteria(String searchCriteria, int occurrences) throws Exception{ + return _browserInstance.elementExistsSearchCriteria(searchCriteria, occurrences); + } + + public static Boolean elementExistsSearchCriteria(String searchCriteria) throws Exception{ + return _browserInstance.elementExistsSearchCriteria(searchCriteria); + } + + public static Boolean waitForElement(By elementLocator, long timeoutSeconds) throws Exception{ + + return _browserInstance.waitForElement(elementLocator, timeoutSeconds); + } + + public static void waitForElement(String key, long timeoutSeconds) throws Exception{ + _browserInstance.waitForElement(key, timeoutSeconds); + } + + public static List getPreviousSimblingElements(WebElement currentElement){ + return _browserInstance.getPreviousSimblingElements(currentElement); + } +} */ \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserConfiguration.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserConfiguration.java new file mode 100644 index 000000000..9d644e220 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserConfiguration.java @@ -0,0 +1,109 @@ +package com.colosa.qa.automatization.common; + +import java.io.IOException; + +/** + * Created with IntelliJ IDEA. + * User: Herbert Saal + * Date: 3/8/13 + * Time: 5:16 PM + * To change this template use File | Settings | File Templates. + */ +public class BrowserConfiguration { + private static BrowserConfiguration ourInstance = new BrowserConfiguration(); + + public static BrowserConfiguration getInstance() { + return ourInstance; + } + + private BrowserConfiguration() { + //init browser configuration by default + try { + getBrowserMode(); + getBrowserName(); + getBrowserVersion(); + getBrowserPlatform(); + getRemoteServerUrl(); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + + } + + public String getBrowserMode() throws IOException { + //read configuration from registry if not found read from configuration file and store in registry + String browserMode = (String)Registry.getInstance().getReference("browser.mode"); + if(browserMode == null){ + browserMode = ConfigurationSettings.getInstance().getSetting("browser.mode"); + Registry.getInstance().register("browser.mode", browserMode); + } + + return browserMode; + + } + + public void setBrowserMode(String browserMode) throws IOException { + //set configuration in registry + Registry.getInstance().register("browser.mode", browserMode); + } + + public String getBrowserName() throws IOException { + String browserName = (String)Registry.getInstance().getReference("browser.name"); + if(browserName == null){ + browserName = ConfigurationSettings.getInstance().getSetting("browser.name"); + Registry.getInstance().register("browser.name", browserName); + } + + return browserName; + } + + public void setBrowserName(String browserName) throws IOException { + //set configuration in registry + Registry.getInstance().register("browser.name", browserName); + } + + public String getBrowserVersion() throws IOException { + String browserVersion = (String)Registry.getInstance().getReference("browser.version"); + if(browserVersion == null){ + browserVersion = ConfigurationSettings.getInstance().getSetting("browser.version"); + Registry.getInstance().register("browser.version", browserVersion); + } + + return browserVersion; + } + + public void setBrowserVersion(String browserVersion) throws IOException { + //set configuration in registry + Registry.getInstance().register("browser.version", browserVersion); + } + + public String getBrowserPlatform() throws IOException { + String browserPlatform = (String)Registry.getInstance().getReference("browser.platform"); + if(browserPlatform == null){ + browserPlatform = ConfigurationSettings.getInstance().getSetting("browser.platform"); + Registry.getInstance().register("browser.platform", browserPlatform); + } + return browserPlatform; + } + + public void setBrowserPlatform(String browserPlatform) throws IOException { + //set configuration in registry + Registry.getInstance().register("browser.platform", browserPlatform); + } + + public String getRemoteServerUrl() throws IOException { + String remoteServerUrl = (String)Registry.getInstance().getReference("remote.server.url"); + if(remoteServerUrl == null){ + remoteServerUrl = ConfigurationSettings.getInstance().getSetting("remote.server.url"); + Registry.getInstance().register("remote.server.url", remoteServerUrl); + } + + return remoteServerUrl; + } + + public void setRemoteServerUrl(String remoteServerUrl) throws IOException { + //set configuration in registry + Registry.getInstance().register("remote.server.url", remoteServerUrl); + } + +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserInstance.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserInstance.java new file mode 100644 index 000000000..5f6d8449c --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserInstance.java @@ -0,0 +1,599 @@ +package com.colosa.qa.automatization.common; + +import org.openqa.selenium.*; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.ie.InternetExplorerDriver; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Wait; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class BrowserInstance { + + private WebDriver _instanceDriver = null; + private int _implicitWaitSeconds = 0; + + /** + * Get default Browser Settings + * @param browserName The default configuration for the specified browser, if empty default browser is used. + * @return BrowserSettings object + * @throws IOException + */ + public static BrowserSettings getDefaultBrowserSettings(String browserName) throws IOException { + int browserCount = 1; + BrowserSettings browserSettings = new BrowserSettings(); + + List browserSettingsList = null; + + //set browser information from configuration file + //check if the browsername is empty then default browser is used. + if(browserName.equals("")){ + browserSettings = readBrowserSettings(0); + + //Read browser information from registry and update in object + //-Dbrowser.settings=1 -Dbrowser.mode=local -Dbrowser.name=firefox + //-Dbrowser.settings=1 -Dbrowser.mode=remote -Dbrowser.name=firefox -Dremote.server.url=http:// browser.version= + //if variable set from system properties override configuration of browser + String setBrowserSettings = System.getProperty("browser.settings"); + + if(setBrowserSettings != null){ + System.out.printf("User Browser Settings detected\n"); + browserSettings.setBrowserMode(System.getProperty("browser.mode")); + browserSettings.setBrowserName(System.getProperty("browser.name")); + browserSettings.setBrowserVersion(System.getProperty("browser.version")); + browserSettings.setBrowserPlatform(System.getProperty("browser.platform")); + browserSettings.setRemoteServerUrl(System.getProperty("remote.server.url")); + } + } + else{ + //get configuration specific for the specified browser + browserCount = Integer.parseInt(ConfigurationSettings.getInstance().getSetting("browser.count")); + for (int i = 1; i <= browserCount; i++){ + BrowserSettings auxBrowserSettings = readBrowserSettings(i); + //browserSettingsList.add(readBrowserSettings(i)); + + if(auxBrowserSettings.getBrowserName().equals(browserName)){ + browserSettings = auxBrowserSettings; + break; + } + } + } + + Logger.addLog("getDefaultBrowserSettings . " + browserSettings.toString()); + + return browserSettings; + } + + /** + * Read the browser configuration from configuration file + * @param browserNumber 0 use the default browser + * @return + */ + public static BrowserSettings readBrowserSettings(Integer browserNumber) throws IOException { + BrowserSettings browserSettings = new BrowserSettings(); + if(browserNumber == 0){ + browserSettings.setBrowserMode(ConfigurationSettings.getInstance().getSetting("browser.mode")); + browserSettings.setBrowserName(ConfigurationSettings.getInstance().getSetting("browser.name")); + browserSettings.setBrowserVersion(ConfigurationSettings.getInstance().getSetting("browser.version")); + browserSettings.setBrowserPlatform(ConfigurationSettings.getInstance().getSetting("browser.platform")); + browserSettings.setRemoteServerUrl(ConfigurationSettings.getInstance().getSetting("remote.server.url")); + } + else{ + browserSettings.setBrowserMode(ConfigurationSettings.getInstance().getSetting("browser.mode")); + browserSettings.setBrowserName(ConfigurationSettings.getInstance().getSetting("browser.browser" + (browserNumber))); + browserSettings.setBrowserVersion(ConfigurationSettings.getInstance().getSetting("browser.version" + (browserNumber))); + browserSettings.setBrowserPlatform(ConfigurationSettings.getInstance().getSetting("browser.platform" + (browserNumber))); + browserSettings.setRemoteServerUrl(ConfigurationSettings.getInstance().getSetting("remote.server.url")); + } + + return browserSettings; + } + + public BrowserInstance(BrowserSettings browserSettings) throws MalformedURLException { + this(browserSettings.getBrowserMode(), browserSettings.getBrowserName(), + browserSettings.getBrowserVersion(), browserSettings.getBrowserPlatform(), + browserSettings.getRemoteServerUrl()); + + } + + public BrowserInstance(String browserMode, String browserName, String browserVersion, String browserPlatform, String remoteServerUrl) throws MalformedURLException { + //create a new instance of the Browser + + if(browserMode.equals("local")){ + if(browserName.equals("chrome")){ + //start chrome maximized by default, +// ChromeOptions options = new ChromeOptions(); +// options.addArguments("--start-maximized"); +// +// _instanceDriver = new ChromeDriver(options); + _instanceDriver = new ChromeDriver(); + } + if(browserName.equals("ie")){ + _instanceDriver = new InternetExplorerDriver(); + } + if(browserName.equals("firefox")){ + //FirefoxProfile profile = allProfiles.getProfile("develop"); + DesiredCapabilities firefox = DesiredCapabilities.firefox(); + firefox.setCapability("elementScrollBehavior", 1); + //firefox.setCapability(FirefoxDriver.PROFILE, profile); + _instanceDriver = new FirefoxDriver(firefox); + } + + } + + if(browserMode.equals("remote")){ + + System.out.printf("Instance Remote browser:%s, version:%s, platform:%s, url:%s \n", + browserName, browserVersion, browserPlatform, remoteServerUrl); + + DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); + + if(browserName.equals("chrome")){ + //start chrome maximized by default +// ChromeOptions options = new ChromeOptions(); +// options.addArguments("--start-maximized"); + + desiredCapabilities = DesiredCapabilities.chrome(); + +// desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options); + }else if(browserName.equals("ie")){ + desiredCapabilities = DesiredCapabilities.internetExplorer(); + }else if(browserName.equals("firefox")){ + desiredCapabilities = DesiredCapabilities.firefox(); + desiredCapabilities.setCapability("elementScrollBehavior", 1); + } + + if(browserVersion != null && !browserVersion.equals("")){ + desiredCapabilities.setVersion(browserVersion); + } + + if(browserPlatform != null && !browserPlatform.equals("")){ + if(browserPlatform.equals("WINDOWS")){ + desiredCapabilities.setPlatform(Platform.WINDOWS); + }else if(browserPlatform.equals("LINUX")){ + desiredCapabilities.setPlatform(Platform.LINUX); + }else if(browserPlatform.equals("MAC")){ + desiredCapabilities.setPlatform(Platform.MAC); + } + }else{ + desiredCapabilities.setPlatform(Platform.ANY); + } + + URL url=new URL(remoteServerUrl); + + _instanceDriver = new RemoteWebDriver(url, desiredCapabilities); + } + + //maximize browser by default + maximize(); + } + + public WebDriver getInstanceDriver(){ + return _instanceDriver; + } + + public void gotoUrl(String url){ + _instanceDriver.get(url); + } + + public String title(){ + return _instanceDriver.getTitle(); + } + + public void close(){ + _instanceDriver.close(); + } + + public void quit(){ + _instanceDriver.quit(); + } + + public void maximize(){ + + _instanceDriver.manage().window().maximize(); + + } + + public void switchToDefaultContent(){ + _instanceDriver.switchTo().defaultContent(); + } + + public void switchToFrame(String frame){ + _instanceDriver.switchTo().frame(frame); + } + + public Alert switchToAlert(){ + return _instanceDriver.switchTo().alert(); + } + + public int getImplicitWaitSeconds(){ + return _implicitWaitSeconds; + } + + public void setImplicitWait(int seconds){ + _implicitWaitSeconds = seconds; + + _instanceDriver.manage().timeouts().implicitlyWait(_implicitWaitSeconds, TimeUnit.SECONDS); + } + + public void turnOffImplicitWaits() { + _instanceDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); + } + + public void turnOnImplicitWaits() { + _instanceDriver.manage().timeouts().implicitlyWait(_implicitWaitSeconds, TimeUnit.SECONDS); + } + + public By getBySearchCriteria(String str, Object... args) throws Exception{ + By by = null; + + String key = str; + if(str==null) + throw new Exception("The the search criteria must be specified"); + + if(str.lastIndexOf(Constant.SEARCH_CRITERIA_SEPARATOR)==-1) { + str = ConfigurationSettings.getInstance().getSetting(str); + + if(str == null) + throw new Exception("There's no value for the key: "+key); + + str = String.format(str, args); + + if(str.lastIndexOf(Constant.SEARCH_CRITERIA_SEPARATOR)==-1) + throw new Exception("The search prefix to find the element must be specified"); + } + + by = this.getBySearchCriteriaUsingCriteria(str); + + return by; + } + + public By getBySearchCriteriaUsingCriteria(String searchCriteria) throws Exception{ + By by = null; + + Logger.addLog("searching element using criteria => "+ searchCriteria); + + if(searchCriteria==null) + throw new Exception("The the search criteria must be specified"); + + if(searchCriteria.lastIndexOf(Constant.SEARCH_CRITERIA_SEPARATOR)==-1) + throw new Exception("The search prefix to find the element must be specified"); + + String[] criteria = searchCriteria.split(Constant.SEARCH_CRITERIA_SEPARATOR, 2); + + Logger.addLog("searching element => criteria: "+ criteria[0] + " value:" + criteria[1]); + + if(criteria[0].equals("id")) + by = By.id(criteria[1]); + else if(criteria[0].equals("cssSelector")) + by = By.cssSelector(criteria[1]); + else if(criteria[0].equals("className")) + by = By.className(criteria[1]); + else if(criteria[0].equals("linkText")) + by = By.linkText(criteria[1]); + else if(criteria[0].equals("name")) + by = By.name(criteria[1]); + else if(criteria[0].equals("partialLinkText")) + by = By.partialLinkText(criteria[1]); + else if(criteria[0].equals("tagName")) + by = By.tagName(criteria[1]); + else if(criteria[0].equals("xpath")) + by = By.xpath(criteria[1]); + else + throw new Exception("Invalid search prefix"); + return by; + } + + public By getBySearchCriteria(FieldKeyType criteria, String key) throws Exception { + By by = null; + + if(criteria == FieldKeyType.ID) + by = By.id(key); + else if(criteria == FieldKeyType.CSSSELECTOR) + by = By.cssSelector(key); + else if(criteria == FieldKeyType.CLASSNAME) + by = By.className(key); + else if(criteria == FieldKeyType.LINKTEXT) + by = By.linkText(key); + else if(criteria == FieldKeyType.NAME) + by = By.name(key); + else if(criteria == FieldKeyType.PARTIALLINKTEXT) + by = By.partialLinkText(key); + else if(criteria == FieldKeyType.TAGNAME) + by = By.tagName(key); + else if(criteria == FieldKeyType.XPATH) + by = By.xpath(key); + else + throw new Exception("Invalid search prefix"); + return by; + } + + public WebElement getParent(WebElement element) throws Exception{ + return element.findElement(By.xpath("..")); + } + + public WebElement findElement(String str) throws Exception{ + WebElement element = this.findElement(this.getBySearchCriteria(str)); + + //Logger.addLog("Element Found: " + element.getText()); + + return element; + } + + private WebElement findElement(By searchCriteria) throws Exception{ + WebElement we = null; + + we = _instanceDriver.findElement(searchCriteria); + + return we; + } + + public WebElement findElementById(String elementId) throws Exception{ + WebElement we = null; + + we = _instanceDriver.findElement(By.id(elementId)); + + return we; + } + + public WebElement findElementByXPath(String elementXPath) throws Exception{ + WebElement we = null; + + we = findElementsByXPath(elementXPath).get(0); + + return we; + } + + public WebElement findElementByClassName(String elementClassName) throws Exception{ + WebElement we = null; + + we = findElementsByClassName(elementClassName).get(0); + + return we; + } + + public WebElement findElementByCssSelector(String cssSelector) throws Exception{ + WebElement we = null; + + we = findElementsByCssSelector(cssSelector).get(0); + + return we; + } + + public WebElement findElementByLinkText(String linkText) throws Exception{ + WebElement we = null; + + we = findElementsByLinkText(linkText).get(0); + + return we; + } + + public WebElement findElementByPartialLinkText(String partialLinkText) throws Exception{ + WebElement we = null; + + we = findElementsByPartialLinkText(partialLinkText).get(0); + + return we; + } + + public WebElement findElementByTagName(String tagName) throws Exception{ + WebElement we = null; + + we = findElementsByTagName(tagName).get(0); + + return we; + } + + public List findElements(String str) throws Exception{ + return this.findElements(this.getBySearchCriteria(str)); + } + + private List findElements(By searchCriteria) throws Exception{ + List we = null; + + we = _instanceDriver.findElements(searchCriteria); + + return we; + } + + public List findElementsByXPath(String elementXPath) throws Exception{ + List lwe = null; + + lwe = _instanceDriver.findElements(By.xpath(elementXPath)); + + return lwe; + } + + public List findElementsByClassName(String elementClassName) throws Exception{ + List lwe = null; + + lwe = _instanceDriver.findElements(By.className(elementClassName)); + + return lwe; + } + + public List findElementsByName(String elementName) throws Exception{ + List lwe = null; + + lwe = _instanceDriver.findElements(By.name(elementName)); + + return lwe; + } + + public List findElementsByCssSelector(String cssSelector) throws Exception{ + List lwe = null; + + lwe = _instanceDriver.findElements(By.cssSelector(cssSelector)); + + return lwe; + } + + public List findElementsByLinkText(String linkText) throws Exception{ + List lwe = null; + + lwe = _instanceDriver.findElements(By.linkText(linkText)); + + return lwe; + } + + public List findElementsByPartialLinkText(String partialLinkText) throws Exception{ + List lwe = null; + + lwe = _instanceDriver.findElements(By.partialLinkText(partialLinkText)); + + return lwe; + } + + public List findElementsByTagName(String tagName) throws Exception{ + List lwe = null; + + lwe = _instanceDriver.findElements(By.tagName(tagName)); + + return lwe; + } + + public WebElement getElementf(String str, Object... args) throws Exception{ + return this.findElement(this.getBySearchCriteria(str, args)); + } + + public Boolean elementExists(String key, int ocurrences) throws Exception{ + return (this.findElements(this.getBySearchCriteria(key)).size()) == ocurrences; + } + + public Boolean elementExists(String key) throws Exception{ + return this.elementExists(key, 1); + } + + public Boolean elementExistsSearchCriteria(String searchCriteria, int ocurrences) throws Exception{ + return (this.findElements(this.getBySearchCriteriaUsingCriteria(searchCriteria)).size()) == ocurrences; + } + + public Boolean elementExistsSearchCriteria(String searchCriteria) throws Exception{ + return this.elementExistsSearchCriteria(searchCriteria, 1); + } + + public boolean waitForElement(By elementLocator, long timeoutSeconds) throws Exception{ + + final By elem = elementLocator; + + WebElement myDynamicElement = (new WebDriverWait(_instanceDriver, timeoutSeconds)) + .until(new ExpectedCondition(){ + @Override + public WebElement apply(WebDriver d) { + return d.findElement(elem); + } + } + + ); + + return true; + } + + public boolean waitForElement(final WebElement fromWebElement, By elementLocator, long timeoutSeconds) throws Exception{ + + final By elem = elementLocator; + + WebElement myDynamicElement = (new WebDriverWait(_instanceDriver, timeoutSeconds)) + .until(new ExpectedCondition(){ + @Override + public WebElement apply(WebDriver d) { + return fromWebElement.findElement(elem); + } + } + + ); + + return true; + } + + /** + * Wait for page state to be completed + * @param timeoutSeconds seconds to wait for page to change status to completed + * @throws Exception + */ + public void waitForDocumentCompleted(long timeoutSeconds) throws Exception{ + /* + Boolean returnExpectedCondition = (new WebDriverWait(_instanceDriver, timeoutSeconds)) + .until(new ExpectedCondition(){ + @Override + public Boolean apply(WebDriver d) { + return (((JavascriptExecutor)_instanceDriver).executeScript("return document.readyState;")).equals("complete"); + //return ((JavascriptExecutor)_instanceDriver).executeScript("return jQuery.active;") == 0; + } + } + ); + */ + + ExpectedCondition expectation = new + ExpectedCondition() { + public Boolean apply(WebDriver driver) { + return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete"); + } + }; + + Wait wait = new WebDriverWait(_instanceDriver,timeoutSeconds); + try { + wait.until(expectation); + } catch(Throwable error) { + throw new Exception("Page not completed."); + //assertFalse("Timeout waiting for Page Load Request to complete.",true); + } + } + + public void waitForTextNotEqual(final WebElement targetElement, final String oldText, long timeoutSeconds) throws Exception{ + (new WebDriverWait(_instanceDriver, timeoutSeconds)).until(new ExpectedCondition() { + public Boolean apply(WebDriver d) { + if(!targetElement.getText().equals(oldText)){ + return true; + }else { return false; } + } + }); + } + + public void waitForElement(String key, long timeoutSeconds) throws Exception{ + + WebDriverWait wait = new WebDriverWait(_instanceDriver, timeoutSeconds); // wait for timeoutSeconds + wait.until(ExpectedConditions.presenceOfElementLocated(this.getBySearchCriteria(key))); + } + public void waitForElementToBeClickable(FieldKeyType criteria, String key, long timeoutSeconds) throws Exception{ + + waitForElementToBeClickable(this.getBySearchCriteria(criteria,key), timeoutSeconds); + } + + public void waitForElementToBeClickable(By searchCriteria, long timeoutSeconds) throws Exception{ + + WebDriverWait wait = new WebDriverWait(_instanceDriver, timeoutSeconds); // wait for timeoutSeconds + wait.until(ExpectedConditions.elementToBeClickable(searchCriteria)); + } + + public void waitForTextToBePresent(By searchCriteria, String textToBePresent, long timeoutSeconds) throws Exception{ + + WebDriverWait wait = new WebDriverWait(_instanceDriver, timeoutSeconds); // wait for timeoutSeconds + wait.until(ExpectedConditions.textToBePresentInElement(searchCriteria, textToBePresent)); + } + + public List getPreviousSimblingElements(WebElement currentElement){ + List resultElements = currentElement.findElements(By.xpath("preceding-sibling")); + + return resultElements; + } + + public void executeScript(){ + //((JavascriptExecutor)browser.getInstanceDriver()).executeScript("arguments[0].value=arguments[1]", elem, fieldData[i][j].fieldValue); + + } + + public void sleep(long timeMilliSeconds) throws Exception { + Thread.sleep(timeMilliSeconds); + } +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserSettings.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserSettings.java new file mode 100644 index 000000000..ea70cb1ca --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/BrowserSettings.java @@ -0,0 +1,68 @@ +package com.colosa.qa.automatization.common; + +/** + * Created with IntelliJ IDEA. + * User: Herbert Saal + * Date: 3/28/13 + * Time: 3:00 PM + * To change this template use File | Settings | File Templates. + */ +public class BrowserSettings { + private String _browserMode; + private String _browserName; + private String _browserVersion; + private String _browserPlatform; + private String _remoteServerURL; + + public String getBrowserMode() { + return _browserMode; + } + + public void setBrowserMode(String browserMode) { + if(browserMode != null) + _browserMode = browserMode; + } + + public String getBrowserName() { + return _browserName; + } + + public void setBrowserName(String browserName) { + if(browserName != null) + _browserName = browserName; + } + + public String getBrowserVersion() { + return _browserVersion; + } + + public void setBrowserVersion(String browserVersion) { + if(browserVersion != null) + _browserVersion = browserVersion; + } + + public String getBrowserPlatform() { + return _browserPlatform; + } + + public void setBrowserPlatform(String browserPlatform) { + if(browserPlatform != null) + _browserPlatform = browserPlatform; + } + + + public String getRemoteServerUrl() { + return _remoteServerURL; + } + + public void setRemoteServerUrl(String remoteServerUrl) { + if(remoteServerUrl != null) + _remoteServerURL = remoteServerUrl; + } + + public String toString() { + return "Browser Mode:" + _browserMode + ", Browser Name:" + _browserName + + ", Browser Version:" + _browserVersion + ", Browser Platform:" + _browserPlatform + + ", Remote Server URL:" + _remoteServerURL; + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/ConfigurationSettings.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/ConfigurationSettings.java new file mode 100644 index 000000000..924edcd24 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/ConfigurationSettings.java @@ -0,0 +1,65 @@ +package com.colosa.qa.automatization.common; + +import java.io.*; +import java.util.Properties; + +public class ConfigurationSettings{ + + private static ConfigurationSettings INSTANCE = null; + private Properties applicationProperties; + private String appConfigurationFile; + + private ConfigurationSettings(String defaultConfFile, String applicationConfFile) throws FileNotFoundException, IOException{ + FileInputStream propertiesFile = new FileInputStream(defaultConfFile); + Properties defaultProperties = new Properties(); + + this.appConfigurationFile = applicationConfFile; + defaultProperties.load(propertiesFile); + propertiesFile.close(); + + this.applicationProperties = new Properties(defaultProperties); + propertiesFile = new FileInputStream(this.appConfigurationFile); + this.applicationProperties.load(propertiesFile); + propertiesFile.close(); + } + + private static void createInstance(String defaultConfFile, String applicationConfFile) throws FileNotFoundException, IOException{ + if(INSTANCE == null) + INSTANCE = new ConfigurationSettings(defaultConfFile, applicationConfFile); + } + + public static ConfigurationSettings getInstance() throws FileNotFoundException, IOException{ + File f = new File("default.conf"); + File fa = new File("app.conf"); + if(f.exists() && fa.exists()) { + ConfigurationSettings.getInstance("default.conf", "app.conf"); + }else{ + f = new File("." + File.separator +"src"+ File.separator + "main"+ File.separator + "default.conf"); + fa = new File("." + File.separator +"src"+ File.separator +"main"+ File.separator + "app.conf"); + if(f.exists() && fa.exists()) { + ConfigurationSettings.getInstance("." + File.separator +"src"+ File.separator + "main"+ File.separator + "default.conf", "." + File.separator +"src"+ File.separator + "main"+ File.separator + "app.conf"); + } + } + return INSTANCE; + } + + public static ConfigurationSettings getInstance(String defaultConfFile, String applicationConfFile) throws FileNotFoundException, IOException{ + ConfigurationSettings.createInstance(defaultConfFile, applicationConfFile); + return INSTANCE; + } + + public String getSetting(String key){ + return this.applicationProperties.getProperty(key); + } + + public void setSetting(String key, String value) throws IOException{ + this.setSetting(key, value, null); + } + + public void setSetting(String key, String value, String comment) throws IOException{ + FileOutputStream fos = new FileOutputStream(this.appConfigurationFile); + this.applicationProperties.setProperty(key, value); + this.applicationProperties.store(fos, comment); + fos.close(); + } +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/Constant.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Constant.java new file mode 100644 index 000000000..be4cd08c4 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Constant.java @@ -0,0 +1,12 @@ +package com.colosa.qa.automatization.common; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 3/5/13 + * Time: 9:54 AM + * To change this template use File | Settings | File Templates. + */ +public class Constant { + public static final String SEARCH_CRITERIA_SEPARATOR = "__&&__"; +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/FieldKeyType.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/FieldKeyType.java new file mode 100644 index 000000000..4ab8dd0f3 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/FieldKeyType.java @@ -0,0 +1,13 @@ +package com.colosa.qa.automatization.common; + +public enum FieldKeyType{ + + ID, + XPATH, + CSSSELECTOR, + LINKTEXT, + PARTIALLINKTEXT, + TAGNAME, + CLASSNAME, + NAME; +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/FieldType.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/FieldType.java new file mode 100644 index 000000000..48fe5d732 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/FieldType.java @@ -0,0 +1,27 @@ +package com.colosa.qa.automatization.common; + +public enum FieldType{ + + TITLE, + SUBTITLE, + LINK, + FILE, + TEXTBOX, + BUTTON, + SUBMITBUTTON, + RESETBUTTON, + TEXTAREA, + DROPDOWN, + LISTBOX, + RADIOBUTTON, + CHECK, + DATEPICKER, + READONLY, + SUGGEST, + CURRENCY, + PERCENTAGE, + YESNO, + HIDDEN, + PASSWORD; + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/InvalidPageException.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/InvalidPageException.java new file mode 100644 index 000000000..432aa3dbf --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/InvalidPageException.java @@ -0,0 +1,15 @@ +package com.colosa.qa.automatization.common; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 5/6/13 + * Time: 5:46 PM + * To change this template use File | Settings | File Templates. + */ +public class InvalidPageException extends Exception { + public InvalidPageException() { super(); } + public InvalidPageException(String message) { super(message); } + public InvalidPageException(String message, Throwable cause) { super(message, cause); } + public InvalidPageException(Throwable cause) { super(cause); } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/Logger.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Logger.java new file mode 100644 index 000000000..ccabd9849 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Logger.java @@ -0,0 +1,37 @@ +package com.colosa.qa.automatization.common; + +import java.io.FileNotFoundException; +import java.io.IOException; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 6/6/13 + * Time: 2:44 PM + * To change this template use File | Settings | File Templates. + */ +public class Logger { + + public Logger(){ + + } + + public static void addLog(String logText) { + //System.out.println("VerifyPage Login ."); + //System.out.printf("Instance Remote browser:%s, version:%s, platform:%s, url:%s \n", + // browserName, browserVersion, browserPlatform, remoteServerUrl); + //debug.enable=1 + String debugEnabled = null; + try { + debugEnabled = ConfigurationSettings.getInstance().getSetting("debug.enable"); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + if(debugEnabled.equals("1")){ + System.out.println(logText); + } + + //add log code + + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/Registry.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Registry.java new file mode 100644 index 000000000..2e9d77782 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Registry.java @@ -0,0 +1,65 @@ +package com.colosa.qa.automatization.common; + + +import java.util.HashMap; +import java.util.Map; + +/** + * Registry pattern + * User: Herbert Saal + * Date: 3/7/13 + * Time: 3:50 PM + * To change this template use File | Settings | File Templates. + */ +public class Registry { + private static Registry ourInstance = new Registry(); + private final Map registry = new HashMap(); + + public static Registry getInstance() { + return ourInstance; + } + + private Registry() { + } + + /** + * Get Reference of stored object in registry identified by the key + * @param key the identifier of the object + * @return return the found object + */ + public Object getReference( + final Object key) { + Object result = null; + if (isRegistered(key)) { + result = registry.get(key); + } + return result; + } + + private boolean isRegistered(Object key) { + return registry.containsKey(key); + } + + /** + * Register the specified object (value) int he registry identified by the specified key + * @param key The identifier of the object. + * @param value The value - object to be stored in the registry + */ + public synchronized void register( + Object key, Object value) { + registry.put(key, value); + } + + /** + * Unregister the specified object from registry. + * @param key the identifier of the object -value to unregister + */ + public synchronized void unregister( + Object key) { + registry.remove(key); + + } + +} + + diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/Utils.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Utils.java new file mode 100644 index 000000000..423be8ecc --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/Utils.java @@ -0,0 +1,40 @@ +package com.colosa.qa.automatization.common; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import org.openqa.selenium.ie.InternetExplorerDriver; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.Platform; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.Select; +import java.net.URL; +import java.io.FileNotFoundException; +import java.io.IOException; +import org.openqa.selenium.JavascriptExecutor; +import java.util.Random; + + +public class Utils{ + + public static String getRandomString (int longString){ + String randomString = ""; + long milis = new java.util.GregorianCalendar().getTimeInMillis(); + Random r = new Random(milis); + int i = 0; + while ( i < longString){ + char c = (char)r.nextInt(255); + if ( (c >= '0' && c <='9') || (c >='A' && c <='Z') ){ + randomString += c; + i ++; + } + } + return randomString; + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/WaitTool.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/WaitTool.java new file mode 100644 index 000000000..787bca35c --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/WaitTool.java @@ -0,0 +1,652 @@ +package com.colosa.qa.automatization.common; + +import org.openqa.selenium.*; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 11/1/13 + * Time: 4:43 PM + * To change this template use File | Settings | File Templates. + */ +public class WaitTool { + /** Default wait time for an element. 7 seconds. */ + public static final int DEFAULT_WAIT_4_ELEMENT = 7; + /** Default wait time for a page to be displayed. 12 seconds. + * The average webpage load time is 6 seconds in 2012. + * Based on your tests, please set this value. + * "0" will nullify implicitlyWait and speed up a test. */ + public static final int DEFAULT_WAIT_4_PAGE = 12; + + + + + /** + * Wait for the element to be present in the DOM, and displayed on the page. + * And returns the first WebElement using the given method. + * + * @param driver The driver object to be used + * @param by selector to find the element + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return WebElement the first WebElement using the given method, or null (if the timeout is reached) + */ + public static WebElement waitForElement(WebDriver driver, final By by, int timeOutInSeconds) { + WebElement element; + try{ + //To use WebDriverWait(), we would have to nullify implicitlyWait(). + //Because implicitlyWait time also set "driver.findElement()" wait time. + //info from: https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + + WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); + element = wait.until(ExpectedConditions.visibilityOfElementLocated(by)); + + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return element; //return the element + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * Wait for the specified element to be present in the DOM, and displayed on the page. + * And returns the first WebElement using the given method. + * + * @param driver The driver object to be used + * @param element The element + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return WebElement the first WebElement using the given method, or null (if the timeout is reached) + */ + public static void waitForElementVisibleAndEnable(WebDriver driver, final WebElement element, int timeOutInSeconds) { + //WebElement element; + try{ + //To use WebDriverWait(), we would have to nullify implicitlyWait(). + //Because implicitlyWait time also set "driver.findElement()" wait time. + //info from: https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + + WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); + wait.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driverObject) { + return element.isDisplayed() && element.isEnabled(); + } + }); + + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return; //return + } catch (Exception e) { + e.printStackTrace(); + } + return; + } + + + + /** + * Wait for the element to be present in the DOM, regardless of being displayed or not. + * And returns the first WebElement using the given method. + * + * @param driver The driver object to be used + * @param by selector to find the element + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return WebElement the first WebElement using the given method, or null (if the timeout is reached) + */ + public static WebElement waitForElementPresent(WebDriver driver, final By by, int timeOutInSeconds) { + WebElement element; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + + WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); + element = wait.until(ExpectedConditions.presenceOfElementLocated(by)); + + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return element; //return the element + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + /** + * Wait for the List to be present in the DOM, regardless of being displayed or not. + * Returns all elements within the current page DOM. + * + * @param driver The driver object to be used + * @param by selector to find the element + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return List all elements within the current page DOM, or null (if the timeout is reached) + */ + public static List waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) { + List elements; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + + WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); + wait.until((new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driverObject) { + return areElementsPresent(driverObject, by); + } + })); + + elements = driver.findElements(by); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return elements; //return the element + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * Wait for an element to appear on the refreshed web-page. + * And returns the first WebElement using the given method. + * + * This method is to deal with dynamic pages. + * + * Some sites I (Mark) have tested have required a page refresh to add additional elements to the DOM. + * Generally you (Chon) wouldn't need to do this in a typical AJAX scenario. + * + * @param driver The driver object to use to perform this element search + * @param by selector to find the element + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return WebElement the first WebElement using the given method, or null(if the timeout is reached) + * + * @author Mark Collin + */ + public static WebElement waitForElementRefresh(WebDriver driver, final By by, + int timeOutInSeconds) { + WebElement element; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver driverObject) { + driverObject.navigate().refresh(); //refresh the page **************** + return isElementPresentAndDisplay(driverObject, by); + } + }); + element = driver.findElement(by); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return element; //return the element + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * Wait for the Text to be present in the given element, regardless of being displayed or not. + * + * @param driver The driver object to be used to wait and find the element + * @param by selector of the given element, which should contain the text + * @param text The text we are looking + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return boolean + */ + public static boolean waitForTextPresent(WebDriver driver, final By by, final String text, int timeOutInSeconds) { + boolean isPresent = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver driverObject) { + return isTextPresent(driverObject, by, text); //is the Text in the DOM + } + }); + isPresent = isTextPresent(driver, by, text); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return isPresent; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + + /** + * Wait for the Text to be present in the given element, regardless of being displayed or not. + * + * @param driver The driver object to be used to wait and find the element + * @param element The given element, which should contain the text + * @param text The text we are looking + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return boolean + */ + public static boolean waitForTextPresent(WebDriver driver, final WebElement element, final String text, int timeOutInSeconds) { + boolean isPresent = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver driverObject) { + return element.getText().contains(text); + } + }); + isPresent = element.getText().contains(text); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return isPresent; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + /** + * Wait for the Text to change in the given element, regardless of being displayed or not. + * + * @param driver The driver object to be used to wait and find the element + * @param by selector of the given element, which should contain the text + * @param currentText The text we are looking + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return boolean + */ + public static boolean waitForTextToChange(WebDriver driver, final By by, final String currentText, int timeOutInSeconds) { + boolean isPresent = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver driverObject) { + return !isTextPresent(driverObject, by, currentText); //is the Text different in the DOM + } + }); + isPresent = !isTextPresent(driver, by, currentText); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return isPresent; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + + /** + * Wait for the Text to change in the given element, regardless of being displayed or not. + * + * @param driver The driver object to be used to wait and find the element + * @param element selector of the given element, which should contain the value + * @param currentText The text we are looking + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return boolean + */ + public static boolean waitForValueToChange(WebDriver driver, final WebElement element, final String currentText, int timeOutInSeconds) { + + boolean isPresent = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driverObject) { + Logger.addLog("waitForValueToChange element value:" + element.getAttribute("value") + " != " + currentText + " => " + !element.getAttribute("value").equals("")); + if(currentText.equals("")){ + return !(element.getAttribute("value").equals("")); + }else{ + return !(element.getAttribute("value").contains(currentText)); + } + } + }); + if(currentText.equals("")){ + isPresent = !(element.getAttribute("value").equals("")); + }else{ + isPresent = !(element.getAttribute("value").contains(currentText)); + } + //isPresent = !element.getText().contains(currentText); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return isPresent; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + /** + * Wait for the Text to change in the given element, regardless of being displayed or not. + * + * @param driver The driver object to be used to wait and find the element + * @param element selector of the given element, which should contain the text + * @param currentText The text we are looking + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return boolean + */ + public static boolean waitForTextToChange(WebDriver driver, final WebElement element, final String currentText, int timeOutInSeconds) { + + boolean isPresent = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driverObject) { + Logger.addLog("waitForTextToChange element text:" + element.getText() + " != " + currentText + " => " + !element.getText().equals("")); + if(currentText.equals("")){ + return !(element.getText().equals("")); + }else{ + return !(element.getText().contains(currentText)); + } + } + }); + if(currentText.equals("")){ + isPresent = !(element.getText().equals("")); + }else{ + isPresent = !(element.getText().contains(currentText)); + } + //isPresent = !element.getText().contains(currentText); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return isPresent; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + /** + * Wait for selected element to change in the given select element, regardless of being displayed or not. + * + * @param driver The driver object to be used to wait and find the element + * @param selectElement selector of the given element, which should contain the text + * @param currentText The text we are looking + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return boolean + */ + public static boolean waitForSelectedTextToChange(WebDriver driver, final WebElement selectElement, final String currentText, int timeOutInSeconds) { + + boolean isPresent = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driverObject) { + Select selectList = new Select(selectElement); + String selectedText = ""; + try{ + WebElement selectedOption = selectList.getFirstSelectedOption(); + selectedText = selectedOption.getText(); + }catch (NoSuchElementException ex){ + //no selected element + selectedText = ""; + } + Logger.addLog("waitForSelectedTextToChange Element Text:" + selectedText + " != " + currentText); + return (!selectedText.equals(currentText)); + } + }); + Select selectList = new Select(selectElement); + String selectedText = ""; + try{ + WebElement selectedOption = selectList.getFirstSelectedOption(); + selectedText = selectedOption.getText(); + }catch (NoSuchElementException ex){ + //no selected element + selectedText = ""; + } + isPresent = !(selectedText.equals(currentText)); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return isPresent; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + /** + * Wait for selected element to change in the given select element, regardless of being displayed or not. + * + * @param driver The driver object to be used to wait and find the element + * @param selectElement selector of the given element, which should contain the text + * @param currentValue The text we are looking + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return boolean + */ + public static boolean waitForSelectedValueToChange(WebDriver driver, final WebElement selectElement, final String currentValue, int timeOutInSeconds) { + + boolean isPresent = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driverObject) { + Select selectList = new Select(selectElement); + String selectedValue = ""; + try{ + WebElement selectedOption = selectList.getFirstSelectedOption(); + selectedValue = selectedOption.getAttribute("value"); + }catch (NoSuchElementException ex){ + //no selected element + selectedValue = ""; + } + Logger.addLog("waitForSelectedValueToChange Element Value:" + selectedValue + " != " + currentValue); + return (!selectedValue.equals(currentValue)); + } + }); + Select selectList = new Select(selectElement); + String selectedValue = ""; + try{ + WebElement selectedOption = selectList.getFirstSelectedOption(); + selectedValue = selectedOption.getAttribute("value"); + }catch (NoSuchElementException ex){ + //no selected element + selectedValue = ""; + } + isPresent = !(selectedValue.equals(currentValue)); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return isPresent; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + /** + * Waits for the Condition of JavaScript. + * + * + * @param driver The driver object to be used to wait and find the element + * @param javaScript The javaScript condition we are waiting. e.g. "return (xmlhttp.readyState >= 2 && xmlhttp.status == 200)" + * @param timeOutInSeconds The time in seconds to wait until returning a failure + * + * @return boolean true or false(condition fail, or if the timeout is reached) + **/ + public static boolean waitForJavaScriptCondition(WebDriver driver, final String javaScript, + int timeOutInSeconds) { + boolean jscondition = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver driverObject) { + return (Boolean) ((JavascriptExecutor) driverObject).executeScript(javaScript); + } + }); + jscondition = (Boolean) ((JavascriptExecutor) driver).executeScript(javaScript); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return jscondition; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + + /** Waits for the completion of Ajax jQuery processing by checking "return jQuery.active == 0" condition. + * + * @param driver - The driver object to be used to wait and find the element + * @param timeOutInSeconds - The time in seconds to wait until returning a failure + * + * @return boolean true or false(condition fail, or if the timeout is reached) + * */ + public static boolean waitForJQueryProcessing(WebDriver driver, int timeOutInSeconds){ + boolean jQcondition = false; + try{ + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + new WebDriverWait(driver, timeOutInSeconds) { + }.until(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver driverObject) { + return (Boolean) ((JavascriptExecutor) driverObject).executeScript("return jQuery.active == 0"); + } + }); + jQcondition = (Boolean) ((JavascriptExecutor) driver).executeScript("return jQuery.active == 0"); + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + return jQcondition; + } catch (Exception e) { + e.printStackTrace(); + } + return jQcondition; + } + + + /** + * Coming to implicit wait, If you have set it once then you would have to explicitly set it to zero to nullify it - + */ + public static void nullifyImplicitWait(WebDriver driver) { + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + } + + + /** + * Set driver implicitlyWait() time. + */ + public static void setImplicitWait(WebDriver driver, int waitTime_InSeconds) { + driver.manage().timeouts().implicitlyWait(waitTime_InSeconds, TimeUnit.SECONDS); + } + + /** + * Reset ImplicitWait. + * To reset ImplicitWait time you would have to explicitly + * set it to zero to nullify it before setting it with a new time value. + */ + public static void resetImplicitWait(WebDriver driver) { + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait + } + + + /** + * Reset ImplicitWait. + * @param newWaittime_InSeconds - a new wait time in seconds + */ + public static void resetImplicitWait(WebDriver driver, int newWaittime_InSeconds) { + driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() + driver.manage().timeouts().implicitlyWait(newWaittime_InSeconds, TimeUnit.SECONDS); //reset implicitlyWait + } + + + /** + * Checks if the text is present in the element. + * + * @param driver - The driver object to use to perform this element search + * @param by - selector to find the element that should contain text + * @param text - The Text element you are looking for + * @return true or false + */ + private static boolean isTextPresent(WebDriver driver, By by, String text) + { + try { + return driver.findElement(by).getText().contains(text); + } catch (NullPointerException e) { + return false; + } + } + + /** + * Checks if the current text is equal to the specified. + * + * @param driver - The driver object to use to perform this element search + * @param by - selector to find the element that should contain text + * @param text - The current Text element you are looking for + * @return true or false + */ + private static boolean isTextEqual(WebDriver driver, By by, String text) + { + try { + return driver.findElement(by).getText().equals(text); + } catch (NullPointerException e) { + return false; + } + } + + + /** + * Checks if the elment is in the DOM, regardless of being displayed or not. + * + * @param driver - The driver object to use to perform this element search + * @param by - selector to find the element + * @return boolean + */ + private static boolean isElementPresent(WebDriver driver, By by) { + try { + driver.findElement(by);//if it does not find the element throw NoSuchElementException, which calls "catch(Exception)" and returns false; + return true; + } catch (NoSuchElementException e) { + return false; + } + } + + + /** + * Checks if the List are in the DOM, regardless of being displayed or not. + * + * @param driver - The driver object to use to perform this element search + * @param by - selector to find the element + * @return boolean + */ + private static boolean areElementsPresent(WebDriver driver, By by) { + try { + driver.findElements(by); + return true; + } catch (NoSuchElementException e) { + return false; + } + } + + /** + * Checks if the elment is in the DOM and displayed. + * + * @param driver - The driver object to use to perform this element search + * @param by - selector to find the element + * @return boolean + */ + private static boolean isElementPresentAndDisplay(WebDriver driver, By by) { + try { + return driver.findElement(by).isDisplayed(); + } catch (NoSuchElementException e) { + return false; + } + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/ControlOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/ControlOptions.java new file mode 100644 index 000000000..ea2eff7ce --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/ControlOptions.java @@ -0,0 +1,151 @@ +package com.colosa.qa.automatization.common.controlOptions; + +import com.colosa.qa.automatization.common.BrowserInstance; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + +import java.util.ArrayList; + +public class ControlOptions{ + + //protected String fieldname = null; + //protected String label = ""; + protected Boolean required = false; + protected Boolean readOnly = false; + private ArrayList dependentFields = new ArrayList(); + protected String defaultValue = null; + protected String hint = ""; + public Mode mode = Mode.EDIT; + protected SQLConnection sqlConnection = null; + protected String sql = null; + protected DependentFieldsApplicableBehavior dependentFieldsApplicableBehavior; + + public enum Mode{ + EDIT("edit"), + VIEW("view"); + + private String value; + + Mode(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + } + + public enum SQLConnection{ + NONE(""), + DBARRAY("dbarray"), + WORKFLOW("workflow"), + RBAC("rbac"), + REPORT("rp"); + + private String value; + + SQLConnection(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + } + + public ControlOptions(){ + this.dependentFieldsApplicableBehavior = new DependentFieldsNotApplicableOption(); + this.sqlConnection = SQLConnection.NONE; + } + + protected void fillForm(BrowserInstance browser) throws Exception{ + Select ddown = null; + this.fillRequired(browser); + this.fillReadOnly(browser); + this.fillDependentFields(browser); + this.fillDefaultValue(browser); + browser.findElement("dynaformDesigner.webElement.blankDynaformModal.hint").sendKeys(this.hint); + ddown = new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.mode")); + ddown.selectByValue(this.mode.getValue()); + this.fillSQLConnection(browser); + this.fillSQL(browser); + } + + protected void addDependentField(String fieldname){ + this.dependentFields.add(fieldname); + } +/* + public void setFieldName(String fieldname){ + this.fieldname = fieldname; + } + + public void setLabel(String label){ + this.label = label; + }*/ + + public void setSQL(String sql){ + this.sql = sql; + } + + public void setSQLConnection(SQLConnection connection){ + this.sqlConnection = connection; + } + + public void setReadOnly(Boolean readOnly){ + this.readOnly = readOnly; + } + + public void setRequired(Boolean required){ + this.required = required; + } + + public void setHint(String hint){ + this.hint = hint; + } + + public void setMode(Mode mode){ + this.mode = mode; + } + + private void fillRequired(BrowserInstance browser) throws Exception{ + if(this.required == null) + return; + WebElement we = null; + we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.required"); + if(this.required != we.isSelected()) + we.click(); + + } + + private void fillDependentFields(BrowserInstance browser) throws Exception{ + if(this.dependentFields != null) + this.dependentFieldsApplicableBehavior.fillDependentFields(browser, this.dependentFields); + } + + protected void fillDefaultValue(BrowserInstance browser) throws Exception{ + if(this.defaultValue == null) + return; + browser.findElement("dynaformDesigner.webElement.blankDynaformModal.defaultValue").sendKeys(this.defaultValue); + } + + private void fillSQLConnection(BrowserInstance browser) throws Exception{ + if(this.sqlConnection == null) + return; + (new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.sqlConnection"))).selectByValue(this.sqlConnection.getValue()); + } + + private void fillSQL(BrowserInstance browser) throws Exception{ + if(this.sql == null) + return; + browser.findElement("dynaformDesigner.webElement.blankDynaformModal.sql").sendKeys(this.sql); + } + + private void fillReadOnly(BrowserInstance browser) throws Exception{ + if(this.readOnly == null) + return; + WebElement we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.readOnly"); + if(this.readOnly != we.isSelected()) + we.click(); + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsApplicableBehavior.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsApplicableBehavior.java new file mode 100644 index 000000000..2c967512c --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsApplicableBehavior.java @@ -0,0 +1,9 @@ +package com.colosa.qa.automatization.common.controlOptions; + +import com.colosa.qa.automatization.common.BrowserInstance; + +import java.util.ArrayList; + +interface DependentFieldsApplicableBehavior{ + public void fillDependentFields(BrowserInstance browser, ArrayList fields) throws Exception; +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsApplicableOption.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsApplicableOption.java new file mode 100644 index 000000000..0eb300acb --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsApplicableOption.java @@ -0,0 +1,20 @@ +package com.colosa.qa.automatization.common.controlOptions; + +import com.colosa.qa.automatization.common.BrowserInstance; +import org.openqa.selenium.support.ui.Select; + +import java.util.ArrayList; + +public class DependentFieldsApplicableOption implements DependentFieldsApplicableBehavior{ + + public void fillDependentFields(BrowserInstance browser, ArrayList fields) throws Exception{ + if(fields == null) + return; + Select we = new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.dependentFields")); + for(String fieldName:fields) + { + we.selectByVisibleText(fieldName); + } + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsNotApplicableOption.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsNotApplicableOption.java new file mode 100644 index 000000000..b3d092cee --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/DependentFieldsNotApplicableOption.java @@ -0,0 +1,11 @@ +package com.colosa.qa.automatization.common.controlOptions; + +import com.colosa.qa.automatization.common.BrowserInstance; + +import java.util.ArrayList; + +public class DependentFieldsNotApplicableOption implements DependentFieldsApplicableBehavior{ + + public void fillDependentFields(BrowserInstance browser, ArrayList fields){} + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/InputControlOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/InputControlOptions.java new file mode 100644 index 000000000..430069667 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/InputControlOptions.java @@ -0,0 +1,72 @@ +package com.colosa.qa.automatization.common.controlOptions.input; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.controlOptions.ControlOptions; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + +import java.util.ArrayList; + +class InputControlOptions extends ControlOptions{ + + private ArrayList size = new ArrayList(); + protected String validate = null; + protected String mask = null; + protected int maxLength = -1; + + protected void fillForm(BrowserInstance browser) throws Exception{ + super.fillForm(browser); + this.fillSize(browser); + this.fillValidate(browser); + this.fillMask(browser); + this.fillMaxLength(browser); + } + + protected void setSize(int... args){ + this.size.clear(); + for(int i: args) + this.size.add(i); + } + + private void fillSize(BrowserInstance browser) throws Exception{ + if(this.size.size()==1) + { + WebElement we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.size"); + we.clear(); + we.sendKeys(Integer.toString(this.size.get(0))); + } + else if(this.size.size()==2) + { + WebElement we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.columns"); + we.clear(); + we.sendKeys(Integer.toString(this.size.get(0))); + we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.rows"); + we.clear(); + we.sendKeys(Integer.toString(this.size.get(1))); + } + } + + private void fillValidate(BrowserInstance browser) throws Exception{ + if(this.validate == null) + return; + Select we = new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.validate")); + we.selectByValue(this.validate); + } + + private void fillMask(BrowserInstance browser) throws Exception{ + if(this.mask == null) + return; + WebElement we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.mask"); + we.clear(); + we.sendKeys(this.mask); + } + + private void fillMaxLength(BrowserInstance browser) throws Exception{ + if(this.maxLength < 0) + return; + WebElement we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.maxLength"); + we.clear(); + we.sendKeys(Integer.toString(this.maxLength)); + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/NumericOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/NumericOptions.java new file mode 100644 index 000000000..9867c131f --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/NumericOptions.java @@ -0,0 +1,71 @@ +package com.colosa.qa.automatization.common.controlOptions.input; + +import com.colosa.qa.automatization.common.BrowserInstance; +import org.openqa.selenium.support.ui.Select; + +public class NumericOptions extends InputControlOptions{ + + private Validate validate = Validate.REAL_NUMBER; + private DecimalSeparator decimalSeparator = DecimalSeparator.PERIOD; + private String formula = null; + + public enum Validate{ + INTEGER("Int"), REAL_NUMBER("Real"); + + private String value; + + Validate(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + }; + + public enum DecimalSeparator{ + PERIOD("."), COMMA(","); + + private String value; + + DecimalSeparator(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + } + + public void setMask(String mask){ + this.mask = mask; + } + + public void setSize(int i){ + super.setSize(i); + } + + public void setFormula(String formula){ + this.formula = formula; + } + + public void setValidate(Validate validate){ + this.validate = validate; + } + + public void setDecimalSeparator(DecimalSeparator decimalSeparator){ + this.decimalSeparator = decimalSeparator; + } + + public void setDefaultValue(String defaultValue){ + this.defaultValue = defaultValue; + } + + public void fillForm(BrowserInstance browser) throws Exception{ + super.fillForm(browser); + new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.validate")).selectByValue(this.validate.getValue()); + new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.decimalSeparator")).selectByValue(this.decimalSeparator.getValue()); + browser.findElement("dynaformDesigner.webElement.blankDynaformModal.formula").sendKeys(this.formula); + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/PasswordOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/PasswordOptions.java new file mode 100644 index 000000000..b20966ea7 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/PasswordOptions.java @@ -0,0 +1,37 @@ +package com.colosa.qa.automatization.common.controlOptions.input; + +import com.colosa.qa.automatization.common.BrowserInstance; +import org.openqa.selenium.WebElement; + +public class PasswordOptions extends InputControlOptions{ + + private Boolean autocomplete = false; + + public PasswordOptions(){ + this.sqlConnection = null; + this.sql = null; + } + + private void setSQLConnection(){} + private void setSQL(){} + + public void setMaxLength(int length){ + this.maxLength = length; + } + + public void setSize(int i){ + super.setSize(i); + } + + public void setAutocomplete(Boolean autocomplete){ + this.autocomplete = autocomplete; + } + + public void fillForm(BrowserInstance browser) throws Exception{ + super.fillForm(browser); + WebElement we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.autocomplete"); + if(this.autocomplete != we.isSelected()) + we.click(); + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/SuggestOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/SuggestOptions.java new file mode 100644 index 000000000..59cfccd43 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/SuggestOptions.java @@ -0,0 +1,102 @@ +package com.colosa.qa.automatization.common.controlOptions.input; + +import com.colosa.qa.automatization.common.BrowserInstance; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + +public class SuggestOptions extends InputControlOptions{ + + private SaveSelectedOptionAs saveSelectedOptionAs = SaveSelectedOptionAs.LABEL; + private StoreNewEntryPrimaryKeyType storeNewEntryPrimaryKeyType; + private int maxResults = 6; + private Boolean showNoResultsMessage = false; + private Boolean storeNewEntry = false; + private String javascript = ""; + private String table = "0"; + private String primaryKey = "0"; + + public enum SaveSelectedOptionAs{ + LABEL("1"), VALUE("0"); + + private String value; + + SaveSelectedOptionAs(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + } + + public enum StoreNewEntryPrimaryKeyType{ + NONE("0"), INTEGER("int"), VARCHAR("varchar"); + + private String value; + + StoreNewEntryPrimaryKeyType(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + } + + public SuggestOptions(){ + this.readOnly = null; + } + + public void setSize(int i){ + super.setSize(i); + } + + public void setSaveSelectedOptionAs(SaveSelectedOptionAs saveAs){ + this.saveSelectedOptionAs = saveAs; + } + + public void setMaxResults(int i){ + this.maxResults = i; + } + public void setShowNoResultsMessage(Boolean bln){ + this.showNoResultsMessage = bln; + } + public void enableStoreNewEntry(String table, String primaryKey, StoreNewEntryPrimaryKeyType type){ + this.storeNewEntry = true; + this.table = table; + this.primaryKey = primaryKey; + this.storeNewEntryPrimaryKeyType = type; + } + + public void disableStoreNewEntry(){ + this.storeNewEntry = false; + this.table = "0"; + this.primaryKey = "0"; + this.storeNewEntryPrimaryKeyType = StoreNewEntryPrimaryKeyType.NONE; + } + + public void setJavascript(String script){ + this.javascript = script; + } + + public void addDependentField(String fieldName){ + super.addDependentField(fieldName); + } + + public void fillForm(BrowserInstance browser) throws Exception{ + super.fillForm(browser); + (new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.saveSelectedOptionAs"))).selectByValue(this.saveSelectedOptionAs.getValue()); + browser.findElement("dynaformDesigner.webElement.blankDynaformModal.maxResults").sendKeys(Integer.toString(this.maxResults)); + WebElement we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.showNoResultsMessage"); + if(this.showNoResultsMessage != we.isSelected()) + we.click(); + we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.storeNewEntry"); + if(we.isSelected() != this.storeNewEntry) + we.click(); + (new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.storeNewEntry.table"))).selectByValue(this.table); + (new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.storeNewEntry.primaryKey"))).selectByValue(this.primaryKey); + (new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.storeNewEntry.primaryKeyType"))).selectByValue(storeNewEntryPrimaryKeyType.getValue()); + browser.findElement("dynaformDesigner.webElement.blankDynaformModal.javascriptCallback").sendKeys(this.javascript); + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/TextAreaOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/TextAreaOptions.java new file mode 100644 index 000000000..73c18a726 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/TextAreaOptions.java @@ -0,0 +1,19 @@ +package com.colosa.qa.automatization.common.controlOptions.input; + +import com.colosa.qa.automatization.common.BrowserInstance; + +public class TextAreaOptions extends InputControlOptions{ + + public void fillForm(BrowserInstance browser) throws Exception{ + super.fillForm(browser); + } + + public void setSize(int columns, int rows){ + super.setSize(columns, rows); + } + + public void setSize(int i){ + this.setSize(i, i); + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/TextFieldOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/TextFieldOptions.java new file mode 100644 index 000000000..68f72a361 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/input/TextFieldOptions.java @@ -0,0 +1,96 @@ +package com.colosa.qa.automatization.common.controlOptions.input; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.controlOptions.DependentFieldsApplicableOption; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + +public class TextFieldOptions extends InputControlOptions{ + + private TextTransform textTransform = TextTransform.NONE; + + public enum TextTransform{ + NONE(""), + UPPER_CASE("UPPER"), + LOWER_CASE("LOWER"); + + private String value; + + TextTransform(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + } + + public enum Validate{ + ANY("Any"), + ALPHA("Alpha"), + ALPHA_NUMERIC("AlphaNum"), + INT("Int"), + REAL("Real"), + EMAIL("Email"), + LOGIN("Login"); + + private String value; + + Validate(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + } + + public TextFieldOptions(){ + this.dependentFieldsApplicableBehavior = new DependentFieldsApplicableOption(); + this.validate = (Validate.ANY).getValue(); + } + + public void setValidate(Validate validate){ + this.validate = validate.getValue(); + } + + public void setTextTransform(TextTransform tf){ + this.textTransform = tf; + } + + public void setSize(int i){ + super.setSize(i); + } + + public void setMask(String mask){ + this.mask = mask; + } + + public void setMaxLength(int length){ + this.maxLength = length; + } + + public void setDefaultValue(String defaultValue){ + this.defaultValue = defaultValue; + } + + public void addDependentField(String fieldName){ + super.addDependentField(fieldName); + } + + @Override + public void fillForm(BrowserInstance browser) throws Exception{ + super.fillForm(browser); + WebElement we = null; + Select ddown = null; + + //ddown = new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.validate")); + //ddown.selectByValue(this.validate.getValue()); + //browser.findElement("dynaformDesigner.webElement.blankDynaformModal.mask").sendKeys(this.mask); + ddown = new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.textTransform")); + ddown.selectByValue(this.textTransform.getValue()); + //we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.size"); + //we.clear(); + //we.sendKeys(Integer.toString(this.size)); + } +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/DropDownOption.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/DropDownOption.java new file mode 100644 index 000000000..4d00ce7e8 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/DropDownOption.java @@ -0,0 +1,25 @@ +package com.colosa.qa.automatization.common.controlOptions.selection; + +class DropDownOption{ + + private String key = null; + private String value = null; + + public DropDownOption(String key, String value){ + this.key = key; + this.value = value; + } + + public String getKey(){ + return this.key; + } + + public void setValue(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/DropDownOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/DropDownOptions.java new file mode 100644 index 000000000..d57e09f55 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/DropDownOptions.java @@ -0,0 +1,43 @@ +package com.colosa.qa.automatization.common.controlOptions.selection; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.controlOptions.ControlOptions; +import com.colosa.qa.automatization.common.controlOptions.DependentFieldsApplicableOption; + +import java.util.ArrayList; + +public class DropDownOptions extends ControlOptions{ + + private ArrayList options = new ArrayList(); + + public DropDownOptions(){ + this.dependentFieldsApplicableBehavior = new DependentFieldsApplicableOption(); + } + + public void addOption(String label, String value){ + options.add(new DropDownOption(label, value)); + } + + public void addDependentField(String fieldName){ + super.addDependentField(fieldName); + } + + public void setDefaultValue(String value){ + this.defaultValue = value; + } + + @Override + public void fillForm(BrowserInstance browser) throws Exception{ + super.fillForm(browser); + int i = 1; + for(DropDownOption opt:this.options) + { + if(i>1) + browser.findElement("dynaformDesigner.webElement.dropdownModal.gridNewElementButton").click(); + browser.getElementf("dynaformDesigner.webElement.dropdownModal.gridValueElementLocator", i).sendKeys(opt.getValue()); + browser.getElementf("dynaformDesigner.webElement.dropdownModal.gridLabelElementLocator", i).sendKeys(opt.getKey()); + i++; + } + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/ListBoxOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/ListBoxOptions.java new file mode 100644 index 000000000..06fe0e20f --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/ListBoxOptions.java @@ -0,0 +1,31 @@ +package com.colosa.qa.automatization.common.controlOptions.selection; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.controlOptions.DependentFieldsNotApplicableOption; +import org.openqa.selenium.WebElement; + +public class ListBoxOptions extends DropDownOptions{ + + private int size = 4; + + public ListBoxOptions(){ + + } + + //protected void setReadOnly(Boolean readOnly){} + + public void setSize(int size){ + this.size = size; + } + + @Override + public void fillForm(BrowserInstance browser) throws Exception{ + this.dependentFieldsApplicableBehavior = new DependentFieldsNotApplicableOption();; + this.readOnly = null; + super.fillForm(browser); + WebElement we = browser.findElement("dynaformDesigner.webElement.blankDynaformModal.size"); + we.clear(); + we.sendKeys(Integer.toString(this.size)); + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/YesNoOptions.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/YesNoOptions.java new file mode 100644 index 000000000..a7cac5f66 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/controlOptions/selection/YesNoOptions.java @@ -0,0 +1,43 @@ +package com.colosa.qa.automatization.common.controlOptions.selection; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.controlOptions.ControlOptions; +import org.openqa.selenium.support.ui.Select; + +public class YesNoOptions extends ControlOptions{ + + public enum Options{ + YES("1"), NO(""); + + private String value; + + Options(String value){ + this.value = value; + } + + public String getValue(){ + return this.value; + } + } + + public void setDefaultValue(Options option){ + this.defaultValue = option.getValue(); + } + + @Override + protected void fillDefaultValue(BrowserInstance browser) throws Exception{ + new Select(browser.findElement("dynaformDesigner.webElement.blankDynaformModal.defaultValue")).selectByValue(this.defaultValue); + } + + private void setRequired(){} + + private void setSQL(/* String sql */){} + + private void setSQLConnection(/*SQLConnection connection*/){} + + public void fillForm(BrowserInstance browser) throws Exception{ + this.sqlConnection = null; + this.required = null; + super.fillForm(browser); + } +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSFloatingMenu.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSFloatingMenu.java new file mode 100644 index 000000000..637e69f3a --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSFloatingMenu.java @@ -0,0 +1,136 @@ +package com.colosa.qa.automatization.common.extJs; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 12/17/13 + * Time: 12:35 PM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSFloatingMenu { + private BrowserInstance browserInstance; + //private WebElement floatingMenuParent; + private WebElement floatingMenu; + private WebElement floatingMenuListContent; + List auxSearchList; + List listExtJSMenuItem = null; + + public ExtJSFloatingMenu(BrowserInstance browserInstance) throws Exception { + //this.floatingMenuParent = floatingMenuParent; + this.browserInstance = browserInstance; + + + // findElement should not be used to look for non-present elements, use findElements(By) and assert zero length response instead. + auxSearchList = browserInstance.getInstanceDriver().findElements(By.cssSelector("div.x-menu.x-menu-floating:not([style='visibility:hidden'])")); + //auxSearchList = this.floatingMenuParent.findElements(By.cssSelector("div.x-menu")); //:not([style='visibility:hidden']) + if(auxSearchList.size() > 0){ + //use the first x-toolbar found + this.floatingMenu = auxSearchList.get(0); + Logger.addLog("FloatingMenu found div.x-menu.x-menu-floating"); + }else + { + throw new Exception("FloatingMenu not found in specified element."); + } + //mejorar la selección de elementos + + + /* + if(auxSearchList.size() > 0){ + //use the first x-toolbar found + this.floatingMenu = auxSearchList.get(0); + Logger.addLog("FloatingMenu found div.x-menu.x-menu-floating"); + }else + { + throw new Exception("FloatingMenu not found in specified element."); + } + + //search visible floating menu + String classAttribute = floatingMenuParent.getAttribute("class"); + Logger.addLog("Attribute " + classAttribute); + if(classAttribute.contains("x-menu") && classAttribute.contains("x-menu-floating")){ + //this is the toolbar element + Logger.addLog("The passed element is the same floating menu: x-menu-floating"); + this.floatingMenu = floatingMenuParent; + }else{ + //search for the toolbar element + //Logger.addLog("before Toolbar find x-panel-tbar"); + // findElement should not be used to look for non-present elements, use findElements(By) and assert zero length response instead. + browserInstance.getInstanceDriver().findElements(By.cssSelector("div.x-menu")); + auxSearchList = this.floatingMenuParent.findElements(By.cssSelector("div.x-menu")); //:not([style='visibility:hidden']) + + //mejorar la selección de elementos + + + + if(auxSearchList.size() > 0){ + //use the first x-toolbar found + this.floatingMenu = auxSearchList.get(0); + Logger.addLog("FloatingMenu found div.x-menu.x-menu-floating"); + }else + { + throw new Exception("FloatingMenu not found in specified element."); + } + }*/ + + //Logger.addLog("before Toolbar find x-toolbar-ct"); + auxSearchList = this.floatingMenu.findElements(By.cssSelector("ul.x-menu-list")); + if(auxSearchList.size() > 0){ + this.floatingMenuListContent = auxSearchList.get(0); + Logger.addLog("FloatingMenu content found ul.x-menu-list"); + }else + { + throw new Exception("FloatingMenu content not found in toolbar element."); + } + + //detect all toolbar cells + this.listExtJSMenuItem = queryListMenuItems(); + } + + private List queryListMenuItems(){ + + List listItems = this.floatingMenuListContent.findElements(By.cssSelector("li.x-menu-list-item")); + Logger.addLog("Get current list of Menu Items: " + listItems.size()); + + + List listMenuItems = new ArrayList(listItems.size()); + + for (WebElement menuListItem : listItems) { + //get menu item + WebElement menuItem = menuListItem.findElement(By.className("x-menu-item")); + listMenuItems.add(new ExtJSMenuItem(menuItem)); + + Logger.addLog(" menu item data: " + menuItem.getTagName() + ":" + menuItem.getText()); + } + + return listMenuItems; + } + + /** + * Find menu item in menu based in the specified text. + * @param menuText text to search item + * @return ExtJSMenuItem found menu item, null in other case. + */ + public ExtJSMenuItem findMenuItem(String menuText){ + ExtJSMenuItem resultMenuItem = null; + + for (ExtJSMenuItem menuItem : this.listExtJSMenuItem) { + Logger.addLog(" if (menu item:" + menuItem.getText() + "==" + menuText + ")"); + + if(menuItem.getText().trim().equals(menuText)){ + Logger.addLog(" menu item found:" + menuItem.getText()); + resultMenuItem = menuItem; + break; + } + } + + return resultMenuItem; + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSForm.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSForm.java new file mode 100644 index 000000000..9e9c36be4 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSForm.java @@ -0,0 +1,91 @@ +package com.colosa.qa.automatization.common.extJs; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import com.colosa.qa.automatization.common.WaitTool; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 12/18/13 + * Time: 11:23 AM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSForm { + private BrowserInstance browserInstance; + private WebElement xForm; + List auxSearchList; + List xFormItems; + + public ExtJSForm(BrowserInstance browserInstance) throws Exception { + //search the first visible windows + this.browserInstance = browserInstance; + + // findElement should not be used to look for non-present elements, use findElements(By) and assert zero length response instead. + auxSearchList = browserInstance.getInstanceDriver().findElements(By.cssSelector("form.x-form")); + if(auxSearchList.size() > 0){ + //use the first x-toolbar found + this.xForm = auxSearchList.get(0); + Logger.addLog("xForm found form.x-form"); + }else + { + throw new Exception("xForm not found in specified element."); + } + + this.xFormItems = this.queryListFormItems(); + } + + private List queryListFormItems() throws Exception { + + List listFormItems = this.xForm.findElements(By.cssSelector("div.x-form-item")); + Logger.addLog("Get current list of form items: " + listFormItems.size()); + + List listXFormItems = new ArrayList(listFormItems.size()); + + for (WebElement xFormItem : listFormItems) { + listXFormItems.add(new ExtJSFormItem(xFormItem, this.browserInstance)); + + Logger.addLog(" form item: " + xFormItem.getTagName() + ":" + xFormItem.getText()); + } + + return listXFormItems; + } + + /** + * Find Form Item based in the item label. + * @param itemLabel text to search item + * @return ExtJSFormItem found form item null in other case. + */ + public ExtJSFormItem findFormItem(String itemLabel){ + ExtJSFormItem resultFormItem = null; + + for (ExtJSFormItem extJSFormItem : this.xFormItems) { + Logger.addLog(" form item:" + extJSFormItem.getLabel() + "==" + itemLabel); + + if(extJSFormItem.getLabel().trim().contains(itemLabel)){ + Logger.addLog(" form item found:" + extJSFormItem.getLabel()); + resultFormItem = extJSFormItem; + break; + } + } + + return resultFormItem; + } + + /** + * Find form item in base to zero based index + * @param formItemIndex The Zero based index of the form item. + * @return ExtJSFormItem the found form item + */ + public ExtJSFormItem findFormItem(int formItemIndex){ + ExtJSFormItem resultFormItem = null; + resultFormItem = this.xFormItems.get(formItemIndex); + Logger.addLog(" return toolbar cell:" + formItemIndex); + return resultFormItem; + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSFormItem.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSFormItem.java new file mode 100644 index 000000000..6feb3b6ad --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSFormItem.java @@ -0,0 +1,69 @@ +package com.colosa.qa.automatization.common.extJs; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 12/18/13 + * Time: 11:30 AM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSFormItem { + private BrowserInstance browserInstance; + private WebElement xFormItem; + private WebElement xFormItemLabel; + private WebElement xFormItemElement; + List auxSearchList; + + public ExtJSFormItem(WebElement xFormItem, BrowserInstance browserInstance) throws Exception { + //search the first visible windows + this.browserInstance = browserInstance; + + //verify that this is a form item + String classAttribute = xFormItem.getAttribute("class"); + if(classAttribute.contains("x-form-item")){ + //this is the toolbar element + Logger.addLog("The passed element is a form item: x-form-item"); + this.xFormItem = xFormItem; + }else{ + throw new Exception("xform item not found in specified element."); + } + + auxSearchList = this.xFormItem.findElements(By.cssSelector("label.x-form-item-label")); + if(auxSearchList.size() > 0){ + //use the first x-toolbar found + this.xFormItemLabel = auxSearchList.get(0); + Logger.addLog("form found label.x-form-item-label"); + }else + { + throw new Exception("Form label not found in specified element."); + } + + auxSearchList = this.xFormItem.findElements(By.cssSelector("div.x-form-element")); + if(auxSearchList.size() > 0){ + //use the first x-toolbar found + this.xFormItemElement = auxSearchList.get(0); + Logger.addLog("form found div.x-form-element"); + }else + { + throw new Exception("Form element not found in specified element."); + } + } + + /** + * Get item label + * @return + */ + public String getLabel(){ + + return this.xFormItemLabel.getText(); + } + + +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGrid.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGrid.java new file mode 100644 index 000000000..d41b10569 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGrid.java @@ -0,0 +1,403 @@ +/* + * Created with IntelliJ IDEA. + * Author: Herbert Saal + * Date: 5/16/13 + * Time: 11:40 AM + * +*/ + +package com.colosa.qa.automatization.common.extJs; + +import java.util.ArrayList; +import java.util.List; +//import java.util.concurrent.TimeUnit; +import java.lang.Exception; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import com.colosa.qa.automatization.common.WaitTool; +import org.openqa.selenium.*; +//import org.openqa.selenium.Keys; +//import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.support.ui.WebDriverWait; +//import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.ExpectedCondition; + +public class ExtJSGrid{ + + private WebDriver driver; + private WebElement grid; + private WebElement headerToolbar; + private List headerToolbarCells; + private WebElement searchInput; + private WebElement gridBody; + private ExtJSGridHeader gridBodyHeader; + private ExtJSToolbar bottomToolbar = null; + private WebElement bottomCellCounterText; + //private List gridHeaders; + private List rows; + private List auxListElements; + + private List pager; + private WebElement btn_first; + private WebElement btn_previous; + private WebElement btn_next; + private WebElement btn_last; + private WebElement btn_refresh; + private int currentPage; + private int totalPages; + private int items; //*falta dar utilidad + private int timeout; + + /** + * Creates an ExtJsGrid class. + * @param grid The element that has the class = x-grid-panel + * @param browserInstance The browser driver + * @param timeout + */ + public ExtJSGrid(WebElement grid, BrowserInstance browserInstance, int timeout) throws Exception { + //verify x-grid-panel class + + this.driver = browserInstance.getInstanceDriver(); + this.grid = grid; + this.timeout = timeout; + this.headerToolbar = this.grid.findElement(By.cssSelector("div.x-panel-tbar")); + this.headerToolbarCells = this.headerToolbar.findElements(By.cssSelector("td.x-toolbar-cell")); + this.gridBody = this.grid.findElement(By.cssSelector("div.x-grid3")); + this.auxListElements = this.grid.findElements(By.cssSelector("div.x-panel-bbar")); + if(this.auxListElements.size()>0){ + this.bottomToolbar = new ExtJSToolbar(this.auxListElements.get(0), browserInstance); + this.bottomCellCounterText = this.bottomToolbar.findToolbarCell(11).getWebElement(); + Logger.addLog("Bottom Toolbar found, cell 11:" + this.bottomCellCounterText.getText()); + } + //this.gridBodyHeader = this.gridBody.findElement(By.cssSelector("div.x-grid3-header")); + + //this.gridHeaders = this.gridBodyHeader.findElements(By.cssSelector("td.x-grid3-hd.x-grid3-cell:not([style='display:none'])")); + this.pager = this.grid.findElements(By.xpath("div/div[3]/div/table/tbody/tr/td/table/tbody/tr/td")); + this.btn_first = this.pager.get(0).findElement(By.xpath("table/tbody/tr[2]/td[2]/em/button")); + this.btn_previous = this.pager.get(1).findElement(By.xpath("table/tbody/tr[2]/td[2]/em/button")); + this.btn_next = this.pager.get(7).findElement(By.xpath("table/tbody/tr[2]/td[2]/em/button")); + this.btn_last = this.pager.get(8).findElement(By.xpath("table/tbody/tr[2]/td[2]/em/button")); + this.btn_refresh = this.pager.get(10).findElement(By.xpath("table/tbody/tr[2]/td[2]/em/button")); + this.init(); + + WaitTool.waitForJavaScriptCondition(this.driver, "return (document.readyState == 'complete');", 15); + } + + /** + * + * @param grid + * @param browserInstance + */ + public ExtJSGrid(WebElement grid, BrowserInstance browserInstance) throws Exception { + this(grid, browserInstance, 30); + } + + private void init(){ + if(!this.driver.getClass().getName().equals("org.openqa.selenium.firefox.FirefoxDriver")) + { + WebDriverWait wait = new WebDriverWait(this.driver, this.timeout); + //try{ + //wait.until(new PageStatusChanged(this.grid.findElement(By.xpath("div/div[3]/div/table/tbody/tr/td[2]/table/tbody/tr/td[1]/table/tbody/tr/td/div")).getText().trim())); + //wait.until(new PageStatusChanged("")); + String[] statuses = {"", "Displaying Empty"}; + wait.until(new PageStatusChanged(statuses)); + //} + } + this.updateCurrentPage(); + this.updateTotalPages(); + } + + private void updateTotalPages(){ + this.totalPages = Integer.parseInt(this.pager.get(5).findElement(By.xpath("div")).getText().trim().substring(3)); + } + + private void updateCurrentPage(){ + this.currentPage = Integer.parseInt(this.pager.get(4).findElement(By.xpath("input")).getAttribute("value")); + } + + public int getCurrentPage(){ + return this.currentPage; + } + + public int getTotalPages(){ + return this.totalPages; + } + + public int nextPage(){ + Logger.addLog("next"); + return this.moveToPage(1); + } + + public int previousPage(){ + return this.moveToPage(0); + } + + public int firstPage(){ + return this.moveToPage(2); + } + + public int lastPage(){ + return this.moveToPage(3); + } + + public int refreshPage(){ + return this.moveToPage(4); + } + + public List getRows(){ + return this.grid.findElements(By.xpath("div/div[2]/div/div[1]/div[2]/div/div")); + } + + public void setSearchFieldGrid(Boolean headerToolBar, Integer cellNumber){ + this.searchInput = null; + /* + Logger.addLog("setSearchFieldGrid search cells: " + cellNumber); + //list of toolbar CELLS + Logger.addLog("setSearchFieldGrid Total toolbar cells: " + headerToolbarCells.size()); + Integer counter = 0; + for(WebElement toolbarElement: headerToolbarCells){ + counter++; + Logger.addLog(" setSearchFieldGrid Toolbar cells[" + counter + "]: " + toolbarElement.getText()); + }*/ + + //pm_search_text_field + + //set the search cell as a headerToolbar of footer cell in toolbar. + if(headerToolBar){ + this.searchInput = headerToolbarCells.get(cellNumber-1).findElement(By.cssSelector("input.x-form-text[type='text']")); + } + } + + public List getCurrentListRows(){ + //clear previous list of rows + + //div#ext-gen25.x-grid3 div#ext-gen26.x-grid3-viewport div#ext-gen28.x-grid3-scroller div#ext-gen30.x-grid3-body div.x-grid3-row + List listRows = this.gridBody.findElements(By.cssSelector("div.x-grid3-body div.x-grid3-row")); + Logger.addLog("Get current list of rows total: " + listRows.size()); + + //WaitTool.waitForJavaScriptCondition(this.driver, "return (document.readyState == 'complete');", 15); + + + List listGridRows = new ArrayList(listRows.size()); + + for (WebElement gridRow : listRows) { + Logger.addLog(" row data: " + gridRow.getText()); + + listGridRows.add(new ExtJSGridRow(gridRow)); + } + + return listGridRows; + } + + public List findRowsBySearchField(String searchCriteria) throws Exception { + if(this.searchInput == null){ + throw new Exception("Search field not defined, define it with setSearchFieldGrid function."); + } + + String currentTextStatus = this.bottomCellCounterText.getText().trim(); + + this.searchInput.sendKeys(searchCriteria); + this.searchInput.sendKeys(Keys.RETURN); + + //wait for counter of grid changes to one if the row is found. + //only wait for one, wait for text to change + //WaitTool.waitForTextPresent(this.driver, this.bottomCellCounterText, "Display Items 1 - 1 of 1", 15); + WaitTool.waitForTextToChange(this.driver, this.bottomCellCounterText, currentTextStatus, 15); + + //return list of rows, only the filtered list is returned + return this.getCurrentListRows(); + } + + public ExtJSGridRow searchAndReturnRow(String searchCriteria, String columnName) throws Exception { + ExtJSGridRow resultGridRow = null; + Boolean rowFound = false; + + if(this.searchInput == null){ + throw new Exception("Search field not defined, define it with setSearchFieldGrid function."); + } + + String currentTextStatus = this.bottomCellCounterText.getText().trim(); + + this.searchInput.sendKeys(searchCriteria); + this.searchInput.sendKeys(Keys.RETURN); + + //wait for counter of grid changes to one if the row is found. + //wait for text to change + WaitTool.waitForTextToChange(this.driver, this.bottomCellCounterText, currentTextStatus, 15); + + //return list of rows, only the filtered list is returned + List listFoundRows = this.getCurrentListRows(); + Logger.addLog("Search grid total items: " + listFoundRows.size()); + + //update header + this.gridBodyHeader = new ExtJSGridHeader(this.grid); + + //compare each found row with the value of the specified column + for (ExtJSGridRow gridRow:listFoundRows){ + //get the number of the column of the header + Integer headerIndex = this.gridBodyHeader.getHeaderColumnNumber(columnName); + Logger.addLog(" Header with name: " + columnName + " Index:" + headerIndex); + + Logger.addLog(" Row Data: " + gridRow.getRowColumnText(headerIndex)); + + if(gridRow.getRowColumnText(headerIndex).equals(searchCriteria)){ + resultGridRow = gridRow; + //rowFound = true; + break; + } + } + + return resultGridRow; + } + + public WebElement getRowByColumnValue(String columnName, String columnValue) throws Exception{ + WebElement header = this.grid.findElement(By.xpath("div/div[2]/div/div[1]/div[1]")); + List headerFields = header.findElements(By.xpath("div/div/table/thead/tr/td")); + int columnNumber = 1; + boolean flag = false; + for(WebElement field:headerFields) + { + if(field.getText().trim().equals(columnName)) + { + flag = true; + break; + } + columnNumber++; + } + if(!flag) + throw new Exception("No se encontro una columna en el grid con el nombre \""+columnName+"\""); + flag = false; + while(this.currentPage <= this.totalPages) + { + headerFields = this.getRows(); + Logger.addLog(headerFields.size() + " " + this.currentPage + " de " + this.totalPages); + for(WebElement row:headerFields) + if(row.findElement(By.xpath("table/tbody/tr/td["+Integer.toString(columnNumber)+"]/div")).getText().trim().equals(columnValue)) + return row; + if(this.currentPage == this.totalPages) + break; + this.nextPage(); + } + return null; + } + + public WebElement getRowByColumnsValue(String columnName, String otherColumnName, String columnValue, String otherColumnValue) throws Exception{ + WebElement header = this.grid.findElement(By.xpath("div/div[2]/div/div[1]/div[1]")); + List headerFields = header.findElements(By.xpath("div/div/table/thead/tr/td")); + int columnNumber = 1; + int otherColumnNumber = 1; + boolean flag = false; + for(WebElement field:headerFields) + { + if(field.getText().trim().equals(columnName)) + { + flag = true; + break; + } + columnNumber++; + } + if(!flag) + throw new Exception("No se encontraron columnas en el grid con el nombre \""+columnName+"\" "); + flag = false; + while(this.currentPage <= this.totalPages) + { + headerFields = this.getRows(); + Logger.addLog(headerFields.size() + " " + this.currentPage + " de " + this.totalPages); + for(WebElement row:headerFields) + if((row.findElement(By.xpath("table/tbody/tr/td["+Integer.toString(columnNumber)+"]/div")).getText().trim().equals(columnValue)) && (row.findElement(By.xpath("table/tbody/tr/td["+Integer.toString(otherColumnNumber)+"]/div")).getText().trim().equals(columnValue))) + return row; + if(this.currentPage == this.totalPages) + break; + this.nextPage(); + } + return null; + } + + + + private int moveToPage(int option){ + WebDriverWait wait = new WebDriverWait(this.driver, this.timeout); + PageStatusChanged statusChanged = new PageStatusChanged(); + PageRefreshed pageRefreshed = new PageRefreshed(); + + switch(option) + { + case 0: + if(this.currentPage == 1) + return 0; + this.btn_previous.click(); + break; + case 1: + if(this.currentPage >= this.totalPages) + return 0; + this.btn_next.click(); + break; + case 2: + if(this.currentPage == 1) + return 0; + this.btn_first.click(); + break; + case 3: + if(this.currentPage == this.totalPages) + return 0; + this.btn_last.click(); + break; + case 4: + this.btn_refresh.click(); + } + if(option!=4) + wait.until(statusChanged); + else + wait.until(pageRefreshed); + this.updateTotalPages(); + this.updateCurrentPage(); + return this.getCurrentPage(); + } + + private int inArray(String[] arr, String str){ + for(int i=0; i{ + + private String status; + private String[] statuses = {}; + + public PageStatusChanged(String status){ + this.status = status; + Logger.addLog("actual " + this.status); + } + + public PageStatusChanged(String[] statuses){ + this.statuses = statuses; + } + + public PageStatusChanged(){ + this.status = grid.findElement(By.xpath("div/div[3]/div/table/tbody/tr/td[2]/table/tbody/tr/td[1]/table/tbody/tr/td/div")).getText().trim(); + //Logger.addLog("actual "+this.status); + } + + @Override + public Boolean apply(WebDriver input) { + String actual = grid.findElement(By.xpath("div/div[3]/div/table/tbody/tr/td[2]/table/tbody/tr/td[1]/table/tbody/tr/td/div")).getText().trim(); + //Logger.addLog(actual+" / "+this.status+" => "+!actual.equals(this.status)); + if(this.statuses.length == 0) + return !actual.equals(this.status); + else + return !(inArray(this.statuses, actual)>-1); + } + } + + private class PageRefreshed implements ExpectedCondition{ + + @Override + public Boolean apply(WebDriver input) { + return pager.get(10).findElement(By.xpath("table")).getAttribute("class").indexOf("x-item-disabled") == -1; + } + } + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGridHeader.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGridHeader.java new file mode 100644 index 000000000..ddec77654 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGridHeader.java @@ -0,0 +1,65 @@ +package com.colosa.qa.automatization.common.extJs; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * Author: herbert + * Date: 5/16/13 + * Time: 11:40 AM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSGridHeader { + WebElement grid = null; + WebElement gridBody = null; + WebElement gridHeader = null; + List listColumns = null; + + /** + * Initialized the grid header with element that represent grid + * @param grid The element that has the class = x-grid-panel + */ + public ExtJSGridHeader(WebElement grid){ + + this.grid = grid; + this.gridBody = this.grid.findElement(By.cssSelector("div.x-grid3")); + + this.gridHeader = this.gridBody.findElement(By.cssSelector("div.x-grid3-header")); + this.listColumns = this.gridHeader.findElements(By.cssSelector("td.x-grid3-hd.x-grid3-cell:not([style='display:none'])")); + } + + /** + * Get the header column name in base to his position + * @param headerNumber one based index of the column + * @return the name of the column + */ + public String getHeaderColumnName(Integer headerNumber){ + WebElement cell = this.listColumns.get(headerNumber-1).findElement(By.className("x-grid3-hd-inner")); + return cell.getText(); + } + + public int countColumns(){ + return this.listColumns.size(); + } + + public Integer getHeaderColumnNumber(String headerName){ + Integer count = 0; + Boolean found = false; + for(WebElement header:this.listColumns){ + count++; + if(header.findElement(By.className("x-grid3-hd-inner")).getText().equals(headerName)){ + // + found = true; + break; + } + } + if(found){ + return count; + } + + return null; + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGridRow.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGridRow.java new file mode 100644 index 000000000..97521b882 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSGridRow.java @@ -0,0 +1,48 @@ +package com.colosa.qa.automatization.common.extJs; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 5/15/13 + * Time: 3:30 PM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSGridRow{ + WebElement gridRow = null; + List listColumns = null; + + /** + * Initialized with the webelement that represent a Tree-node
+ * @param gridRow + */ + public ExtJSGridRow(WebElement gridRow){ + //validate + + this.gridRow = gridRow; + this.listColumns = this.gridRow.findElements(By.cssSelector("td.x-grid3-col.x-grid3-cell:not([style='display:none'])")); + } + + /** + * Get the cell(row, column) text + * @param columnNumber one based index of the column + * @return the text of the cell + */ + public String getRowColumnText(Integer columnNumber){ + WebElement cell = this.listColumns.get(columnNumber-1).findElement(By.className("x-grid3-cell-inner")); + return cell.getText(); + } + + public int countColumns(){ + return this.listColumns.size(); + } + + public WebElement getGridRow(){ + return this.gridRow; + } + +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSMenuItem.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSMenuItem.java new file mode 100644 index 000000000..b6a83679f --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSMenuItem.java @@ -0,0 +1,37 @@ +package com.colosa.qa.automatization.common.extJs; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 12/17/13 + * Time: 2:16 PM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSMenuItem { + WebElement menuItem = null; + WebElement menuItemText = null; + + public ExtJSMenuItem(WebElement menuItem){ + this.menuItem = menuItem; + this.menuItemText = this.menuItem.findElement(By.className("x-menu-item-text")); + } + + /** + * Click element in Menu + */ + public void click(){ + this.menuItem.click(); + } + + /** + * Get text in menu + * @return + */ + public String getText(){ + + return this.menuItemText.getText(); + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSToolbar.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSToolbar.java new file mode 100644 index 000000000..dd249d904 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSToolbar.java @@ -0,0 +1,137 @@ +package com.colosa.qa.automatization.common.extJs; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import com.colosa.qa.automatization.common.WaitTool; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 6/10/13 + * Time: 1:33 PM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSToolbar { + private BrowserInstance browserInstance; + private WebElement toolbar; + private WebElement toolbarContent; + private List listExtJSToolbarCells; + List auxSearchList; + + + /** + * Represents a ExtJs Toolbar + * @param toolbar element with class x-toolbar + * @param browserInstance browser instance + */ + public ExtJSToolbar(WebElement toolbar, BrowserInstance browserInstance) throws Exception { + this.browserInstance = browserInstance; + this.toolbar = toolbar; + + String classAttribute = toolbar.getAttribute("class"); + if(classAttribute.contains("x-toolbar")){ + //this is the toolbar element + Logger.addLog("The passed element is the same toolbar: x-toolbar"); + this.toolbar = toolbar; + }else{ + //search for the toolbar element + //Logger.addLog("before Toolbar find x-panel-tbar"); + // findElement should not be used to look for non-present elements, use findElements(By) and assert zero length response instead. + auxSearchList = toolbar.findElements(By.className("x-toolbar")); + if(auxSearchList.size() > 0){ + //use the first x-toolbar found + this.toolbar = auxSearchList.get(0); + Logger.addLog("Toolbar found x-toolbar"); + }else + { + throw new Exception("Toolbar not found in specified element."); + } + } + + //Logger.addLog("before Toolbar find x-toolbar-ct"); + auxSearchList = this.toolbar.findElements(By.className("x-toolbar-ct")); + if(auxSearchList.size() > 0){ + this.toolbarContent = auxSearchList.get(0); + Logger.addLog("Toolbar content found x-toolbar-ct"); + }else + { + throw new Exception("Toolbar content not found in toolbar element."); + } + + //detect all toolbar cells + this.listExtJSToolbarCells = queryListToolbarCells(); + } + + private List queryListToolbarCells(){ + + List listCells = this.toolbarContent.findElements(By.cssSelector("td.x-toolbar-cell")); + Logger.addLog("Get current list of cells: " + listCells.size()); + + + List listToolbarCells = new ArrayList(listCells.size()); + + for (WebElement toolbarCell : listCells) { + listToolbarCells.add(new ExtJSToolbarCell(toolbarCell, this.browserInstance)); + + Logger.addLog(" cell data: " + toolbarCell.getTagName() + ":" + toolbarCell.getText()); + } + + return listToolbarCells; + } + + public List getListToolbarCells(){ + return queryListToolbarCells(); + } + + /** + * Find cell in toolbar based in the cell text. + * @param buttonText text to search cell + * @return ExtJSToolbarCell found cell null in other case. + */ + public ExtJSToolbarCell findToolbarCell(String buttonText){ + ExtJSToolbarCell resultToolbarCell = null; + + for (ExtJSToolbarCell extjsToolbarCell : this.listExtJSToolbarCells) { + Logger.addLog(" toolbar cell:" + extjsToolbarCell.getCellText() + "==" + buttonText); + + if(extjsToolbarCell.getCellText().trim().equals(buttonText)){ + Logger.addLog(" toolbar cell found:" + extjsToolbarCell.getCellText()); + resultToolbarCell = extjsToolbarCell; + break; + } + } + + return resultToolbarCell; + } + + /** + * Find Toolbar cell in base to zero based index of cell + * @param cellIndex The Zero based index of the cell to return. + * @return ExtJSToolbarCell the found cell + */ + public ExtJSToolbarCell findToolbarCell(int cellIndex){ + ExtJSToolbarCell resultToolbarCell = null; + resultToolbarCell = this.listExtJSToolbarCells.get(cellIndex); + WaitTool.waitForElementVisibleAndEnable(browserInstance.getInstanceDriver(), resultToolbarCell.getWebElement(), 5); + Logger.addLog(" return toolbar cell:" + cellIndex); + return resultToolbarCell; + } + + /* + public ExtJSToolbarCell waitForToolbarCellDisplay(int cellIndex){ + ExtJSToolbarCell resultToolbarCell = null; + resultToolbarCell = this.listExtJSToolbarCells.get(cellIndex); + + //resultToolbarCell.getWebElement().isDisplayed(); + //Logger.addLog(" return toolbar cell:" + cellIndex); + return resultToolbarCell; + }*/ + + +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSToolbarCell.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSToolbarCell.java new file mode 100644 index 000000000..04b4ee0fc --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSToolbarCell.java @@ -0,0 +1,173 @@ +package com.colosa.qa.automatization.common.extJs; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 6/10/13 + * Time: 1:45 PM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSToolbarCell { + private BrowserInstance browserInstance; + private WebElement toolbarCell; //element with class x-toolbar-cell + private List toolbarCellOptions; + /*private WebElement toolbarCellButton; + private WebElement toolbarCellText; + private WebElement toolbarCellSeparator; + private WebElement toolbarCellWrap;*/ + + /** + * Initialize with an element that represent a Toolbar Cell, that has the class x-toolbar-cell + * @param toolbarCell webelement with class x-toolbar-cell + * @param browserInstance browser instance + */ + public ExtJSToolbarCell(WebElement toolbarCell, BrowserInstance browserInstance) { + this.browserInstance = browserInstance; + + //this.headerToolbar = this.grid.findElement(By.cssSelector("div.x-panel-tbar")); + //this.headerToolbarCells = this.headerToolbar.findElements(By.cssSelector("td.x-toolbar-cell")); + this.toolbarCell = toolbarCell; + //WebElement toolbarCellContent; + //get the child + /* + this.toolbarCellTable = this.toolbarCell.findElement(By.cssSelector("table")); + this.driver = driver; + + //detect what type of cell is + String classAttribute = this.toolbarCellTable.getAttribute("class"); + + */ + /* + Logger.addLog("New Toolbar cell identify type"); + + this.browserInstance.turnOffImplicitWaits(); + this.toolbarCellOptions = this.toolbarCell.findElements(By.cssSelector(".x-btn, .xtb-text, .xtb-sep, .x-form-field-wrap")); + this.browserInstance.turnOnImplicitWaits(); + + if(this.toolbarCellOptions.size() > 0){ + Logger.addLog("Toolbar element found!!!"); + //an element was found + toolbarCellContent = this.toolbarCellOptions.get(0); + //detect what type of cell is + String classAttribute = toolbarCellContent.getAttribute("class"); + if(classAttribute.contains("x-btn")){ + Logger.addLog("It's a button!!!"); + this.toolbarCellButton = toolbarCellContent; + Logger.addLog(" text:" + getCellText()); + } + + if(classAttribute.contains("xtb-text")){ + Logger.addLog("It's a text!!!"); + this.toolbarCellText = toolbarCellContent; + Logger.addLog(" text:" + getCellText()); + } + + if(classAttribute.contains("xtb-sep")){ + Logger.addLog("It's a separator!!!"); + this.toolbarCellSeparator = toolbarCellContent; + Logger.addLog(" text:" + getCellText()); + } + + if(classAttribute.contains("x-form-field-wrap")){ + Logger.addLog("It's a wrapper!!!"); + this.toolbarCellWrap = toolbarCellContent; + Logger.addLog(" text:" + getCellText()); + } + } */ + } + + /** + * Get webelement of toolbar-cell + */ + public WebElement getWebElement(){ + return this.toolbarCell; + //html.ext-strict body#ext-gen3.ext-gecko div#navPanel.x-panel div#ext-gen16.x-panel-bwrap div#ext-gen17.x-panel-tbar div#ext-comp-1004.x-toolbar table.x-toolbar-ct tbody tr td.x-toolbar-left table tbody tr.x-toolbar-left-row td#ext-gen27.x-toolbar-cell table#caseNotes.x-btn tbody.x-btn-small tr td.x-btn-mc em button#ext-gen28.x-btn-text + } + + /** + * Click any non-identified element in toolbar-cell + */ + public void click(){ + this.toolbarCell.click(); + //html.ext-strict body#ext-gen3.ext-gecko div#navPanel.x-panel div#ext-gen16.x-panel-bwrap div#ext-gen17.x-panel-tbar div#ext-comp-1004.x-toolbar table.x-toolbar-ct tbody tr td.x-toolbar-left table tbody tr.x-toolbar-left-row td#ext-gen27.x-toolbar-cell table#caseNotes.x-btn tbody.x-btn-small tr td.x-btn-mc em button#ext-gen28.x-btn-text + } + + /** + * Click toolbar button + */ + public void clickButton() throws Exception { + WebElement cellButton = null; + Logger.addLog("click button"); + + this.browserInstance.turnOffImplicitWaits(); + this.toolbarCellOptions = this.toolbarCell.findElements(By.cssSelector(".x-btn")); + this.browserInstance.turnOnImplicitWaits(); + + if(this.toolbarCellOptions.size() > 0){ + Logger.addLog("button element found!!!"); + //an element was found + cellButton = this.toolbarCellOptions.get(0); + cellButton.findElement(By.cssSelector("button")).click(); + }else{ + throw new Exception("Button not found!!"); + } + + //x-btn x-btn-text-icon + //click the element if is a button + } + + /** + * Get text in cell + * @return + */ + public String getCellText(){ + String cellText = ""; + + cellText = this.toolbarCell.getText(); + + /* + //if is a button or a text get the text + // x-btn-text + if(this.toolbarCellText != null){ + + cellText = this.toolbarCellText.getText(); + //Logger.addLog("Cell text:" + cellText); + } + + if(this.toolbarCellButton != null){ + WebElement button = this.toolbarCellButton.findElement(By.className("x-btn-text")); + if(button != null){ + cellText = button.getText(); + //Logger.addLog("Button text:" + cellText); + } + } + + if(this.toolbarCellSeparator != null){ + cellText = "|"; + //Logger.addLog("Separator text:" + cellText); + } + + if(this.toolbarCellWrap != null){ + cellText = "[]"; + //Logger.addLog("Wrap text:" + cellText); + } */ + + return cellText; + } + + /** + * Set text in cell + * @param text + */ + public void setCellText(String text){ + this.toolbarCell.sendKeys(text); + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSTree.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSTree.java new file mode 100644 index 000000000..f7179db13 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSTree.java @@ -0,0 +1,400 @@ +package com.colosa.qa.automatization.common.extJs; + +import java.util.ArrayList; +import java.util.List; + +import com.colosa.qa.automatization.common.Logger; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.By; + +public class ExtJSTree{ + + private WebDriver driver; + private WebElement tree; + private int timeout; + private WebElement currentNode; + private WebElement root = null; + private List listTreeRootNodes; + + /** + * Class used to manage - navigate ext-js tree + * @param tree the web element that is most near to the element that has the class atribute= " x-tree-root-ct" + * The first element with this class is selected as the root of the tree. + * @param driver the web driver + */ + public ExtJSTree(WebElement tree, WebDriver driver) throws Exception { + this.driver = driver; + this.tree = tree; + //this.timeout = timeout; + //element with class x-tree-root-ct + Logger.addLog("ExtJSTree()->find x-tree-root-ct"); + this.root = tree.findElement(By.className("x-tree-root-ct"));//(By.xpath("div/div/ul/div")); + if(this.root == null){ + //change of root node + throw new Exception("No ExtJs tree structure found. The specified element is not a tree."); + } + + //check if there's another level + WebElement auxRoot = null; + auxRoot = this.root.findElement(By.className("x-tree-root-node")); + if(auxRoot != null){ + //change of root node + this.root =auxRoot; + } + + //this.currentNode = this.root; + + this.readTreeNodes(); + + //check if node was found + if(this.root == null){ + throw new Exception("No ExtJs tree structure found."); + } + } + + public List readTreeNodes(){ + List rootNodes = null; + + //search root nodes + rootNodes = this.root.findElements(By.cssSelector(this.root.getTagName() + " > li.x-tree-node:not([style='display: none;'])")); //style="" [style=''] + //rootNodes = this.root.findElements(By.cssSelector("x-tree-node-el")); + + listTreeRootNodes = new ArrayList(rootNodes.size()); + + Logger.addLog("ExtJSTree()->getListRootNodes list x-tree-node-el: " + rootNodes.size()); + + for (WebElement rootNode : rootNodes) { + + ExtJSTreeNode newTreeNode = new ExtJSTreeNode(rootNode, this.driver); + + Logger.addLog("ExtJSTree()->rootNode: " + newTreeNode.getNodeText()); + + listTreeRootNodes.add(newTreeNode); + } + + return listTreeRootNodes; + } + + /** + * Go to element that represent the root "/" + */ + public void gotoRoot(){ + //this.root.findElement(By.xpath("div/a/span")).click(); + this.root = tree.findElement(By.className("x-tree-root-ct")); + this.currentNode = this.root; + } + + public void refresh(){ + this.tree.findElement(By.xpath("div[1]/div[1]")).click(); + //talvez esperar a que se termine de cargar + } + + public List getListRootNodes(){ + /*List rootNodes = null; + + //search root nodes + rootNodes = this.root.findElements(By.cssSelector(this.root.getTagName() + " > li.x-tree-node")); //style="" [style=''] + //rootNodes = this.root.findElements(By.cssSelector("x-tree-node-el")); + + List listTreeRootNodes = new ArrayList(rootNodes.size()); + + Logger.addLog("ExtJSTree()->getListRootNodes list x-tree-node-el: " + listTreeRootNodes.size()); + + for (WebElement rootNode : rootNodes) { + + ExtJSTreeNode newTreeNode = new ExtJSTreeNode(rootNode, this.driver); + + Logger.addLog("ExtJSTree()->rootNode: " + newTreeNode.getNodeText()); + + listTreeRootNodes.add(newTreeNode); + } + + return listTreeRootNodes;*/ + return listTreeRootNodes; + } + + /** + * Select the specified node in the tree from the root + * @param nodePath The path to the node, start with /rootNode/nodelevel1/nodelevel2 etc. + * The complete path must be specified. Regular expressions are supported. + * @return The found tree node + */ + public ExtJSTreeNode getTreeNode(String nodePath, Boolean useRegularExpresion) throws Exception { + //ExtJSTreeNode treeNodeModel = new ExtJSTreeNode(); + + return ExtJSTreeNode.getTreeNodeInList(this.listTreeRootNodes, nodePath, useRegularExpresion); + + /* + ExtJSTreeNode resultTreeNode = null; + String searchPath = path; + + //search first node from left of path (root node) + String nodeName = getLeftNodePath(searchPath); + searchPath = removeLeftNodePath(searchPath); + + Logger.addLog("ExtJSTree()->getTreeNode: search node:" + nodeName + " pending path:" + searchPath ); + + + //search in root nodes + for(ExtJSTreeNode rootNodeElement:this.listTreeRootNodes){ + + //check if is the same node + if(useRegularExpresion){ + Logger.addLog("ExtJSTree()->getTreeNode: usign reg expresions if "+ rootNodeElement.getNodeText() + "== " + nodeName ); + if(rootNodeElement.getNodeText().matches(nodeName)){ + //verify if is the node that we are searching for + if(searchPath.equals("")){ + //this is the search node + resultTreeNode = rootNodeElement; + }else{ + //continue searching nodes + resultTreeNode = rootNodeElement.getTreeNode(searchPath, useRegularExpresion); + } + break; + } + }else{ + Logger.addLog("ExtJSTree()->getTreeNode: using equals if "+ rootNodeElement.getNodeText() + " == " + nodeName ); + if(rootNodeElement.getNodeText().equals(nodeName)){ + //verify if is the node that we are searching for + if(searchPath.equals("")){ + resultTreeNode = rootNodeElement; + }else{ + //continue searching nodes + resultTreeNode = rootNodeElement.getTreeNode(searchPath, useRegularExpresion); + } + break; + } + } + } + + if(resultTreeNode == null){ + throw new Exception("No treeNode found with the specified path."); + } + + return resultTreeNode; */ + } + + public ExtJSTreeNode getTreeNode(String path) throws Exception { + return getTreeNode(path, false); + } + +/* + public ExtJSTreeNode gotoNode(String path) throws Exception { + return gotoNode(path, false); + } */ + + /** + * Select the specified node in the tree from the root + * @param path The path to the node, start with /rootNode/nodelevel1/nodelevel2 etc. + * The complete path must be specified. Regular expressions are supported. + * @return The found tree node + */ + /* + public ExtJSTreeNode gotoNode(String path, Boolean useRegularExpresion) throws Exception { + String itemToSearch = null; + List rootNodes = null; + List filterNodes = null; + ExtJSTreeNode rootNode = null; + ExtJSTreeNode auxRootNode = null; + ExtJSTreeNode resultWebElement = null; + String searchPath = path; + + //search root nodes + Logger.addLog("ExtJsTree-> Root tagname:" + this.root.getTagName()); + rootNodes = this.root.findElements(By.cssSelector(this.root.getTagName() + " > li.x-tree-node")); //style="" [style=''] + + //search first node from left of path (root node) + String nodeName = getLeftNodePath(searchPath); + searchPath = removeLeftNodePath(searchPath); + + //list of nodes + Logger.addLog("ExtJsTree->Number of root nodes found:" + rootNodes.size()); + Logger.addLog("ExtJsTree->Search root node:" + nodeName); + + //verify if list of nodes is available + if(rootNodes == null){ + throw new Exception("ExtJsTree->No root nodes detected in tree structure."); + } + + //x-tree-root-ct div.x-tree-root-node + //search the root node in the path + for(WebElement rootNodeElement:rootNodes){ + //check treenode text + auxRootNode = new ExtJSTreeNode(rootNodeElement, this.driver); + // + Logger.addLog("ExtJsTree->search rootNode:" + auxRootNode.getNodeText()); + + if(useRegularExpresion){ + if(auxRootNode.getNodeText().matches(nodeName)){ + rootNode = auxRootNode; + break; + } + }else{ + if(auxRootNode.getNodeText().equals(nodeName)){ + rootNode = auxRootNode; + break; + } + } + } + + //verify if root node is available + if(rootNode == null){ + throw new Exception("ExtJsTree->Root node not found."); + } + + //search for child nodes? + if(searchPath.trim().equals("")){ + //this is the search node + return rootNode; + } + + Logger.addLog("ExtJsTree-> Root node found:" + rootNode.getNodeText()); + + resultWebElement = gotoNodeFromNode(rootNode, searchPath, useRegularExpresion); + + return resultWebElement; + } + + public ExtJSTreeNode gotoNodeFromNode(ExtJSTreeNode currentNode, String path) throws Exception { + return this.gotoNodeFromNode(currentNode, path, false); + } + + */ + /** + * Find the node from the specified node, the path must not include the current node + * If the node is not found null is returned. + * @param currentNode the current node, is an element with the class = "x-tree-node" + * @param path path to the node, the current node must not be included. + * @return + */ + /* + public ExtJSTreeNode gotoNodeFromNode(ExtJSTreeNode currentNode, String path, Boolean useRegularExpresion) throws Exception { + ExtJSTreeNode rootNode = currentNode; + //ExtJSTreeNode auxRootNode = null; + String searchPath = path; + Boolean nodeFound =false; + + //current path + Logger.addLog("ExtJsTree->GotoNodeFromNode->current node Path:" + path); + + while(!searchPath.trim().equals("")){ + //verify if node is found in level + nodeFound =false; + + //search in list of nodes + //search first node from left of path (root node) + String auxNodeName = getLeftNodePath(searchPath); + searchPath = removeLeftNodePath(searchPath); + Logger.addLog("ExtJsTree->GotoNodeFromNode->find node:" + auxNodeName); + + //count child nodes + Logger.addLog("ExtJsTree->GotoNodeFromNode->child nodes:" + rootNode.getListChildNodes().size()); + for (ExtJSTreeNode childNode : rootNode.getListChildNodes()) { + + //check treenode text + //auxRootNode = new ExtJSTreeNode(webElement); + Logger.addLog("ExtJsTree->GotoNodeFromNode->search childNode:" + childNode.getNodeText()); + if(useRegularExpresion){ + if(childNode.getNodeText().matches(auxNodeName)){ + rootNode = childNode; + nodeFound = true; + break; + } + }else{ + if(childNode.getNodeText().equals(auxNodeName)){ + rootNode = childNode; + nodeFound = true; + break; + } + } + }; + //continue with the next level in path + if(nodeFound){ + //check if we are at the end of the path + if(!searchPath.trim().equals("")){ + //continue searching the path + //assign the new root node + //the found node was assigned to rootNode + } else + { + //the complete path was found + break; + } + }else{ + //node not found, return error + break; + } + } + //the found node is rootNode + if(nodeFound){ + //node found + Logger.addLog("Node found:" + rootNode.getNodeText()); + return rootNode; + } + else{ + throw new Exception("ExtJsTree->Node not found."); + } + }*/ + + public WebElement getRootNode(){ + return this.root; + } + + public WebElement getCurrentNode(){ + return this.currentNode; + } + /* + public String getLeftNodePath(String path){ + String workingPath = path; + + workingPath = removeSeparatorPath(workingPath); + + if(path.trim().equals("")){ + return ""; + } + + String[] splits = workingPath.split("/"); + + //se trata de + return splits[0]; + } + + public String removeLeftNodePath(String path){ + String workingPath = path; + + workingPath = removeSeparatorPath(workingPath); + + if(workingPath.trim().equals("")){ + return ""; + } + + int firstIndex = workingPath.indexOf("/"); + + //there's no more nodes + if(firstIndex == -1){ + return ""; + } + //se trata de + return workingPath.substring(firstIndex); + } + + public String removeSeparatorPath(String path){ + String workingPath = path; + + if(path.trim().equals("")){ + return ""; + } + + //quitar el nodo root si existe + if(workingPath.charAt(0) == '/'){ + workingPath = workingPath.substring(1); + } + //remove the last character + if(workingPath.charAt(workingPath.length()-1) == '/'){ + workingPath = workingPath.substring(0, workingPath.length()-1); + } + //se trata de + return workingPath; + }*/ +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSTreeNode.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSTreeNode.java new file mode 100644 index 000000000..cbb748661 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSTreeNode.java @@ -0,0 +1,202 @@ +package com.colosa.qa.automatization.common.extJs; + +import com.colosa.qa.automatization.common.Logger; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 5/7/13 + * Time: 2:07 PM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSTreeNode { + WebElement treeNode = null; + private WebDriver driver; + List childTreeNodes = null; + + /** + * This class represent a tree node element, must be initialized -> class x-tree-node-el + * @param treeNode element with class: x-tree-node-el + * @param driver + */ + public ExtJSTreeNode(WebElement treeNode, WebDriver driver){ + this.treeNode = treeNode; + this.driver = driver; + + //search the child nodes of this node + //childTreeNodes = findListChildNodes(); + } + + public String getNodeText(){ + WebElement node = this.treeNode.findElement(By.cssSelector("div.x-tree-node-el a.x-tree-node-anchor span")); + return node.getText(); + } + + public void click(){ + WebElement node = this.treeNode.findElement(By.cssSelector("div.x-tree-node-el a.x-tree-node-anchor")); + node.click(); + } + + public void doubleClick(){ + Actions action = new Actions(this.driver); + + WebElement node = this.treeNode.findElement(By.cssSelector("div.x-tree-node-el")); + action.doubleClick(node); + action.perform(); + } + + public int countChildNodes(){ + //List childList = this.treeNode.findElements(By.cssSelector("ul.x-tree-node-ct li.x-tree-node")); + return childTreeNodes.size(); + } + + private List findListChildNodes(){ + List childList = this.treeNode.findElements(By.cssSelector(this.treeNode.getTagName() + " > ul.x-tree-node-ct li.x-tree-node:not([style='display: none;'])")); //style="display: none;" + + Logger.addLog("ExtJSTreeNode()->findListChildNodes: " + this.treeNode.getTagName() + " > ul.x-tree-node-ct li.x-tree-node:not([style='display: none;']) count:" + childList.size()); + + List listTreeChildNodes = new ArrayList(childList.size()); + + for (WebElement childNode : childList) { + ExtJSTreeNode jsTreeNode = new ExtJSTreeNode(childNode, this.driver); + Logger.addLog("ExtJSTreeNode()->findListChildNodes add node to list: " + jsTreeNode.getNodeText()); + + listTreeChildNodes.add(jsTreeNode); + } + return listTreeChildNodes; + } + + public List getListChildNodes(){ + return childTreeNodes; + } + + /*public WebElement getWebElementNode(){ + return this.treeNode; + }*/ + + public ExtJSTreeNode getTreeNode(String nodePath, Boolean useRegularExpresion) throws Exception { + //find child tree nodes + this.childTreeNodes = findListChildNodes(); + + return this.getTreeNodeInList(this.childTreeNodes, nodePath, useRegularExpresion); + } + + /** + * Get the tree node in base to search path starting from current search node + * @param nodePath search path to find a node + * @param useRegularExpresion true if regular expression is used in search path + * @return + * @throws Exception + */ + public static ExtJSTreeNode getTreeNodeInList(List listTreeNodes, String nodePath, Boolean useRegularExpresion) throws Exception { + ExtJSTreeNode resultTreeNode = null; + String searchPath = nodePath; + + //search first node from left of path (root node) + String nodeName = getLeftNodePath(searchPath); + searchPath = removeLeftNodePath(searchPath); + + Logger.addLog("ExtJSTree()->getTreeNode: search node:" + nodeName + " pending path:" + searchPath ); + + //search in child nodes + for(ExtJSTreeNode treeNode:listTreeNodes){ + + //check if is the same node + if(useRegularExpresion){ + Logger.addLog("ExtJSTree()->getTreeNode: usign reg expresions if "+ treeNode.getNodeText() + " == " + nodeName ); + if(treeNode.getNodeText().matches(nodeName)){ + //verify if is the node that we are searching for + if(searchPath.equals("")){ + //this is the search node + resultTreeNode = treeNode; + }else{ + //continue searching nodes + resultTreeNode = treeNode.getTreeNode(searchPath, useRegularExpresion); + } + break; + } + }else{ + Logger.addLog("ExtJSTree()->getTreeNode: usign equals if "+ treeNode.getNodeText() + " == " + nodeName ); + if(treeNode.getNodeText().equals(nodeName)){ + //verify if is the node that we are searching for + if(searchPath.equals("")){ + resultTreeNode = treeNode; + }else{ + //continue searching nodes + resultTreeNode = treeNode.getTreeNode(searchPath, useRegularExpresion); + } + break; + } + } + } + + //if node null -> error + if(resultTreeNode == null){ + throw new Exception("No treeNode found with the specified path."); + } + + return resultTreeNode; + + } + + public static String getLeftNodePath(String path){ + String workingPath = path; + + workingPath = removeSeparatorPath(workingPath); + + if(path.trim().equals("")){ + return ""; + } + + String[] splits = workingPath.split("/"); + + //se trata de + return splits[0]; + } + + public static String removeLeftNodePath(String path){ + String workingPath = path; + + workingPath = removeSeparatorPath(workingPath); + + if(workingPath.trim().equals("")){ + return ""; + } + + int firstIndex = workingPath.indexOf("/"); + + //there's no more nodes + if(firstIndex == -1){ + return ""; + } + //se trata de + return workingPath.substring(firstIndex); + } + + public static String removeSeparatorPath(String path){ + String workingPath = path; + + if(path.trim().equals("")){ + return ""; + } + + //quitar el nodo root si existe + if(workingPath.charAt(0) == '/'){ + workingPath = workingPath.substring(1); + } + //remove the last character + if(workingPath.charAt(workingPath.length()-1) == '/'){ + workingPath = workingPath.substring(0, workingPath.length()-1); + } + //se trata de + return workingPath; + } + +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSWindow.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSWindow.java new file mode 100644 index 000000000..04df0b7d0 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSWindow.java @@ -0,0 +1,51 @@ +package com.colosa.qa.automatization.common.extJs; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: herbert + * Date: 12/18/13 + * Time: 10:14 AM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSWindow { + private BrowserInstance browserInstance; + private WebElement xWindow; + private WebElement xWindowContent; + List auxSearchList; + + public ExtJSWindow(BrowserInstance browserInstance) throws Exception { + //search the first visible windows + this.browserInstance = browserInstance; + + // findElement should not be used to look for non-present elements, use findElements(By) and assert zero length response instead. + auxSearchList = browserInstance.getInstanceDriver().findElements(By.cssSelector("div.x-window")); //[style='visibility: visible'] + if(auxSearchList.size() > 0){ + //use the first x-toolbar found + this.xWindow = auxSearchList.get(0); + Logger.addLog("xWindow found div.x-window [style='visibility:visible']"); + }else + { + throw new Exception("xWindow not found in specified element."); + } + + auxSearchList = this.xWindow.findElements(By.cssSelector("div.x-window-body")); + if(auxSearchList.size() > 0){ + this.xWindowContent = auxSearchList.get(0); + Logger.addLog("xWindow content found div.x-window-body"); + }else + { + throw new Exception("xWindow content not found in browser."); + } + } + + public WebElement getWindowElement(){ + return this.xWindow; + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSWindowToolbar.java b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSWindowToolbar.java new file mode 100644 index 000000000..36689be92 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/common/extJs/ExtJSWindowToolbar.java @@ -0,0 +1,94 @@ +package com.colosa.qa.automatization.common.extJs; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents a x windows Toolbar. + * User: herbert + * Date: 10/4/13 + * Time: 11:01 AM + * To change this template use File | Settings | File Templates. + */ +public class ExtJSWindowToolbar { + private BrowserInstance browserInstance; + private WebElement toolbar; + private WebElement toolbarContent; + private List listExtJSToolbarCells; + + /** + * Represents a ExtJs Window Toolbar + * @param toolbar element with class x-window-tbar + * @param browserInstance + */ + public ExtJSWindowToolbar(WebElement toolbar, BrowserInstance browserInstance){ + this.browserInstance = browserInstance; + this.toolbar = toolbar; + + String classAttribute = toolbar.getAttribute("class"); + if(classAttribute.contains("x-window-tbar")){ + //this is the toolbar element + Logger.addLog("The passed element is the same toolbar: x-window-tbar"); + this.toolbar = toolbar; + }else{ + //search for the toolbar element + //Logger.addLog("before Toolbar find x-panel-tbar"); + this.toolbar = toolbar.findElement(By.className("x-window-tbar")); + Logger.addLog("Toolbar found x-window-tbar"); + } + + //Logger.addLog("before Toolbar find x-toolbar-ct"); + //this.toolbarContent = this.toolbar.findElement(By.className("x-toolbar-ct")); + //Logger.addLog("Toolbar content found x-toolbar-ct"); + + this.listExtJSToolbarCells = queryListToolbarCells(); + } + + private List queryListToolbarCells(){ + + //List listCells = this.toolbarContent.findElements(By.cssSelector("td.x-toolbar-cell")); + List listCells = this.toolbar.findElements(By.cssSelector("td.x-toolbar-cell")); + Logger.addLog("Found current list of cells: " + listCells.size()); + + List listToolbarCells = new ArrayList(listCells.size()); + + for (WebElement toolbarCell : listCells) { + Logger.addLog(" create toolbar cell data."); + + listToolbarCells.add(new ExtJSToolbarCell(toolbarCell, this.browserInstance)); + + Logger.addLog(" cell data: " + toolbarCell.getTagName() + ":" + toolbarCell.getText()); + } + + return listToolbarCells; + } + + public ExtJSToolbarCell findToolbarCell(String buttonText){ + ExtJSToolbarCell resultToolbarCell = null; + + for (ExtJSToolbarCell extjsToolbarCell : this.listExtJSToolbarCells) { + //Logger.addLog(" toolbar cell:" + extjsToolbarCell.getCellText() + " vs " + buttonText); + + if(extjsToolbarCell.getCellText().trim().equals(buttonText)){ + Logger.addLog(" toolbar cell found:" + extjsToolbarCell.getCellText()); + resultToolbarCell = extjsToolbarCell; + break; + } + } + + return resultToolbarCell; + } + + public ExtJSToolbarCell findToolbarCell(int cellIndex){ + ExtJSToolbarCell resultToolbarCell = this.listExtJSToolbarCells.get(cellIndex); + return resultToolbarCell; + } + + +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/pages/Page.java b/tests/functional/src/main/java/com/colosa/qa/automatization/pages/Page.java new file mode 100644 index 000000000..edb4f736d --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/pages/Page.java @@ -0,0 +1,39 @@ +package com.colosa.qa.automatization.pages; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.ConfigurationSettings; + +public abstract class Page{ + protected String url; + protected String pageTitle; + protected BrowserInstance browser; + protected Integer implicitWaitSeconds = 0; + + public Page(BrowserInstance browser) throws Exception { + this.browser = browser; + + //init implicit wait time + implicitWaitSeconds = Integer.parseInt(ConfigurationSettings.getInstance().getSetting("implicit.wait.seconds")); + browser.setImplicitWait(implicitWaitSeconds); + + url = ""; + pageTitle = ""; + //Logger.addLog("Page contructor....:" + url); + } + + /** + * Go to default URL server + */ + public void gotoUrl(String url){ + this.url = url; + //Logger.addLog("Page.Goto url:" + url); + this.browser.gotoUrl(url); + //Logger.addLog("Browser.goto url:" + url); + } + + public boolean isAt(){ + return (this.browser.title() == pageTitle); + } + + public abstract void verifyPage() throws Exception; +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/pages/Pages.java b/tests/functional/src/main/java/com/colosa/qa/automatization/pages/Pages.java new file mode 100644 index 000000000..706340024 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/pages/Pages.java @@ -0,0 +1,40 @@ +package com.colosa.qa.automatization.pages; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.ConfigurationSettings; + +import java.io.IOException; + +public class Pages{ + protected BrowserInstance _browserInstance; + + public Pages(BrowserInstance browserInstance){ + _browserInstance = browserInstance; + } + + public void gotoDefaultUrl() throws IOException { + String url; + //default url + url = ConfigurationSettings.getInstance().getSetting("server.url"); + + _browserInstance.gotoUrl(url); + } + + /* + public Login Login() throws Exception{ + + Login loginPage = new Login(_browserInstance); + + return loginPage; + } + + public Main Main() throws Exception{ + + Main mainPage = new Main(_browserInstance); + + return mainPage; + } + */ + + +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/tests/common/Test.java b/tests/functional/src/main/java/com/colosa/qa/automatization/tests/common/Test.java new file mode 100644 index 000000000..748b01f6f --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/tests/common/Test.java @@ -0,0 +1,98 @@ +package com.colosa.qa.automatization.tests.common; + +import com.colosa.qa.automatization.common.BrowserSettings; +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.ConfigurationSettings; +import com.colosa.qa.automatization.common.Logger; +import com.colosa.qa.automatization.pages.Pages; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.junit.After; +import org.junit.runners.Suite; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; + +/** + * Created with IntelliJ IDEA. + * User: Herbert Saal + * Date: 3/28/13 + * Time: 11:58 AM + * To change this template use File | Settings | File Templates. + */ +@RunWith(value = Parameterized.class) +public abstract class Test { + protected String browserName; + protected BrowserInstance browserInstance; + protected Pages pages; + + /*public Test() throws IOException { + + String browserName = "firefox"; + + this.browserName = browserName; + Logger.addLog("Test with browser:" + browserName); + //initialize test pages + initializeTest(browserName); + //initialize pages + pages = new Pages(browserInstance); + } */ + + public Test(String browserName) throws IOException { + + this.browserName = browserName; + Logger.addLog("Test with browser:" + browserName); + //initialize test pages + initializeTest(browserName); + //initialize pages + pages = new Pages(browserInstance); + } + + @Parameters + public static Collection data() { + int browserCount = 1; + Object[][] data = null; + //get the supported browsers from configuration file: + try { + browserCount = Integer.parseInt(ConfigurationSettings.getInstance().getSetting("browser.count")); + + data = new Object[browserCount][1]; + for (int i = 0; i< browserCount; i++){ + String browserName = ConfigurationSettings.getInstance().getSetting("browser.browser" + (i + 1)); + data[i][0] = browserName; + Logger.addLog("Add Browser for test: "+browserName); + } + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + + //Object[][] data = new Object[][] { { "firefox" }, { "chrome" }, { "ie" } }; + //Logger.addLog("Browsers to test with:" + Arrays.toString(data)); + + return Arrays.asList(data); + + /*return Arrays.asList(new Object[][]) { + { "AGCCG", "AGTTA" }, + { "AGTTA", "GATCA" }, + { "GGGAT", "AGCCA" } + } */ + } + + public void initializeTest(String browserName) throws IOException { + Logger.addLog("initializeTest ."); + //creates the instance of the Browser + BrowserSettings browserSettings = BrowserInstance.getDefaultBrowserSettings(browserName); + Logger.addLog("initializeTest .."); + //change browser name + browserSettings.setBrowserName(browserName); + Logger.addLog("initializeTest ..."); + browserInstance = new BrowserInstance(browserSettings); + Logger.addLog("initializeTest ...."); + } + + public void goToUrl(String url){ + browserInstance.gotoUrl(url); + } +} diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/tests/common/WebDriverFunctionsPMOS2.java b/tests/functional/src/main/java/com/colosa/qa/automatization/tests/common/WebDriverFunctionsPMOS2.java new file mode 100644 index 000000000..26947b2c5 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/tests/common/WebDriverFunctionsPMOS2.java @@ -0,0 +1,348 @@ +/* +Pensado y Desarrollado por Daniel Canedo +para Colosa QA +http://duhnnie.net +last update: 2012-10-23 Hrs. 16:40 +*/ + +package com.colosa.qa.automatization.tests.common; + +import com.colosa.qa.automatization.common.BrowserInstance; +import com.colosa.qa.automatization.common.Logger; +import com.colosa.qa.automatization.common.extJs.ExtJSGrid; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class WebDriverFunctionsPMOS2{ + + private WebDriver driver = null; + private BrowserInstance _browserInstance = null; + private int skin = 1; //0: classic / 1: uxmodern + private int timeout = 30; //default timeout in seconds + + public WebDriverFunctionsPMOS2(BrowserInstance browserInstance, int skin){ + this.driver = browserInstance.getInstanceDriver(); + this._browserInstance = browserInstance; + this.skin = skin; + } + + public WebDriverFunctionsPMOS2(BrowserInstance browserInstance, int skin, int timeout){ + this(browserInstance, skin); + this.timeout = timeout; + this.driver.manage().timeouts().implicitlyWait(this.timeout, TimeUnit.SECONDS); + } + + public boolean login(String username, String password, String workspace){ + this.waitForElementPresent(By.name("form[USR_USERNAME]")); + if(this.skin == 1) + { + WebElement we = this.driver.findElement(By.name("form[USR_USERNAME]")); + we.clear(); + we.sendKeys(username); + we = this.driver.findElement(By.name("form[USR_PASSWORD]")); + we.clear(); + we.sendKeys(password); + we = this.driver.findElement(By.id("workspace")); + we.clear(); + we.sendKeys(workspace); + this.driver.findElement(By.name("form[USR_PASSWORD]")).sendKeys(Keys.RETURN); + } + else + { + WebElement we = this.driver.findElement(By.id("form[USR_USERNAME]")); + we.clear(); + we.sendKeys(username); + we = this.driver.findElement(By.name("form[USR_PASSWORD]")); + we.clear(); + we.sendKeys(password); + we = this.driver.findElement(By.id("form[USER_ENV]")); + if(we.getAttribute("type").equals("text")) + we.clear(); + we.sendKeys(workspace); + we = this.driver.findElement(By.id("form[BSUBMIT]")); + we.click(); + } + return true; + } + + public void logout(){ + this.driver.switchTo().defaultContent(); + if(this.skin==0) + this.driver.findElement(By.xpath("//*[@id='pm_header']/table/tbody/tr[1]/td[2]/div/small/a")).click(); + } + + public boolean goSection(String sectionName){ + + WebElement we = null; + List wel; + this.driver.switchTo().defaultContent(); + Logger.addLog("Redireccionando a seccion " + sectionName + "..."); + if(this.skin == 0) + { + this.waitForElementPresent(By.cssSelector("ul#pm_menu li a"),60); + we = this.driver.findElement(By.id("pm_menu")); + we = we.findElement(By.linkText(sectionName)); + } + else + { + this.waitForElementPresent(By.xpath("//div[@id='mainTabPanel']"), 60); + wel = this.driver.findElements(By.xpath("//div[@id='mainTabPanel']/div/div/ul/li")); + for(WebElement we2:wel) + { + we = we2.findElement(By.xpath("a[2]/em/span/span")); + if(we.getText().equals(sectionName)) + break; + } + } + //Logger.addLog(we); //raro pero se necesita esta linea para que funcione correctamente + if(we == null) + return false; + we.click(); + return true; + } + + private String[] pathToArray(String path){ + if(path.charAt(0) == '/') + path = path.substring(1); + if(path.charAt(path.length()-1) == '/') + path = path.substring(0, path.length()); + + return path.split("/"); + } + + public boolean selectMenuTreePanelOption(String path) throws Exception{ + List wel; + WebElement option = null; + String[] pathLevels; + String aux=""; + + if(path.length() == 0) + return false; + + pathLevels = this.pathToArray(path.toLowerCase()); + + if(pathLevels.length>2) + throw new Exception("the PATH parameter must contain up to 2 path levels."); + + Logger.addLog("Intentando ingresar a " + pathLevels[0] + ((pathLevels.length > 1) ? " => " + pathLevels[1] : "") + "..."); + + this.goSection("HOME"); + if(this.skin == 0) + this.driver.switchTo().frame("casesFrame"); + else + { + this.waitForElementPresent(By.id("pm-frame-cases"),this.timeout); + this.driver.switchTo().frame("pm-frame-cases"); + } + + if(pathLevels.length==2 || path.charAt(path.length()-1)=='/') + wel = this.driver.findElements(By.xpath("//div[@id='tree-panel']/div/div/ul/div/li")); + else + wel = this.driver.findElements(By.xpath("//div[@id='tree-panel']/div/div/ul/div/li/ul/li")); + for(WebElement we:wel) + try{ + aux = we.findElement(By.xpath("div/a/span")).getText().toLowerCase(); + if(aux.length()>=pathLevels[0].length()) + if(aux.substring(0, pathLevels[0].length()).equals(pathLevels[0])) + { + option = we; + break; + } + }catch(java.lang.StringIndexOutOfBoundsException e){ + throw new Exception("No se encontró el grupo de opciones: \""+pathLevels[0]+"\""); + } + if(option == null) + throw new Exception("No se encontró el grupo de opciones: \""+pathLevels[0]+"\""); + if(pathLevels.length==2) + { + wel = option.findElements(By.xpath("ul/li")); + option = null; + for(WebElement we:wel) + { + aux = we.findElement(By.xpath("div/a/span")).getText().toLowerCase(); + try{ + if(aux.substring(0, pathLevels[1].length()).equals(pathLevels[1])) + { + option = we; + break; + } + }catch(java.lang.StringIndexOutOfBoundsException e) + { + throw new Exception("No se encontró opción: \""+pathLevels[1] + "\" en el grupo de opciones: \""+pathLevels[0]+"\""); + } + } + if(option == null) + throw new Exception("No se encontró opción: \""+pathLevels[1] + "\" en el grupo de opciones: \""+pathLevels[0]+"\""); + } + option.findElement(By.xpath("div/a/span")).click(); + return true; + } + + public int startCase(String processName) throws Exception{ + WebElement we; + String[] path = this.pathToArray(processName); + List wel; + Actions action = new Actions(this.driver); + boolean flag = false; + int value = 0; + + this.selectMenuTreePanelOption("Cases/New case"); + this.driver.switchTo().frame("casesSubFrame"); + //this.waitForElementPresent(By.id("startCaseTreePanel"),30);//para telefónica + we = this.driver.findElement(By.id("startCaseTreePanel")); + if(path.length>2) + throw new Exception("the string Path parameter can contain up to 2 segments, you asshole!"); + + Logger.addLog("Buscando caso " + processName + "..."); + if(path.length==2) + { + wel = we.findElements(By.xpath("div/div[2]/ul/div/li")); + we = null; + for(WebElement we2:wel) + if(we2.findElement(By.xpath("div/a/span")).getText().equals(path[0])) + { + we = we2; + break; + } + if(we == null) + throw new Exception("No se encontro el proceso: "+processName); + wel = we.findElements(By.xpath("ul/li")); + for(WebElement we2:wel) + { + we = we2.findElement(By.xpath("div/a/span")); + if(we.getText().equals(path[1])) + { + flag = true; + break; + } + } + if(!flag) + throw new Exception("No se encontro el proceso: "+processName); + } + else{ + wel = we.findElements(By.xpath("div/div[2]/ul/div/li/ul/li")); + for(WebElement we2:wel) + { + we = we2.findElement(By.xpath("div/a/span")); + if(we.getText().equals(path[0])) + { + flag = true; + break; + } + } + if(!flag) + throw new Exception("No se encontro el proceso: "+processName); + } + Logger.addLog("Iniciando caso " + processName + "..." + we); + action.doubleClick(we); + action.perform(); + + value = Integer.parseInt(this.driver.findElement(By.xpath("//div[@id='caseTabPanel']/div[1]/div[1]/ul/li[@id='caseTabPanel__casesTab']")).getText().trim().substring(8)); + return value; + } + + public int startCase(String processName, boolean flag) throws Exception{ + int value = this.startCase(processName); + if(flag) + { + this.waitForElementPresent(By.id("openCaseFrame"), this.timeout); + this.driver.switchTo().frame("openCaseFrame"); + } + return value; + } + + public boolean openProcess(String processName) throws Exception { + this.goSection("DESIGNER"); + WebElement we = null; + Actions action = new Actions(this.driver); + + if(this.skin == 0) + this.driver.switchTo().frame("frameMain"); + if(this.skin == 1) + this.driver.switchTo().frame("pm-frame-processes"); + + WebElement grid = this.driver.findElement(By.id("processesGrid")); + ExtJSGrid extGrid = new ExtJSGrid(grid, this._browserInstance); + WebElement pager = this.driver.findElement(By.xpath("//div[@id='processesGrid']/div/div[3]/div/table/tbody/tr/td[1]/table/tbody/tr")); + List wl; + int index = 1; + int pages = Integer.parseInt(pager.findElement(By.xpath("td[6]/div")).getText().trim().substring(3)); + + Logger.addLog("Buscando proceso \"" + processName + "\"..."); + + while(extGrid.getCurrentPage()<=extGrid.getTotalPages() && we==null){ + Logger.addLog("Buscando en pagina " + extGrid.getCurrentPage() + " de " + extGrid.getTotalPages() + "..."); + wl = grid.findElements(By.xpath("div/div[2]/div/div[1]/div[2]/div/div")); + for(WebElement we2:wl) + { + //Logger.addLog(we2.findElement(By.xpath("table/tbody/tr[1]/td[5]/div")).getText()+" "+processName); + if(we2.findElement(By.xpath("table/tbody/tr[1]/td[5]/div")).getText().equals(processName)) + { + we = we2; + Logger.addLog("Se encontro el proceso \"" + processName + "\""); + break; + } + } + if(extGrid.getCurrentPage()==extGrid.getTotalPages() || we!=null) + break; + extGrid.nextPage(); + } + + if(we==null) + Logger.addLog("ERROR al intentar abrir el proceso \"" + processName + "\", no se encontró el proceso"); //talvez se deberia lanzar un error + else + { + Logger.addLog("Abriendo proceso \"" + processName + "\"..."); + action.doubleClick(we); + action.perform(); + } + return true; + } +/* + public void openCase(int numCase){ + ExtJSGrid grid; + this.selectMenuTreePanelOption("Cases/Inbox"); + this.driver.switchTo().frame("casesSubFrame"); + grid = new ExtJSGrid(this.driver.findElement(By.id("casesGrid")), this.driver); + grid.getRowByColumn("#", Integer.toString(numCase)); + }*/ + + public boolean openProcess(String processName, String category){ + return true; + } + + public WebElement getTask(String taskName){ + WebElement designPanel = this.driver.findElement(By.xpath("//div[@id='pm_target']/div[1]/div[1]/div[3]")); + return designPanel.findElement(By.xpath("div[@class='processmap_task___processmaker'][div[1]='"+taskName.trim()+"']")); + } + + public void selectTaskContextMenuOption(String taskName, String option){ + WebElement contextMenu; + new Actions(this.driver).contextClick(this.getTask(taskName)).perform(); + contextMenu = this.driver.findElement(By.cssSelector("body > div.app_menuRight_container___processmaker")); + contextMenu.findElement(By.xpath("div[div[2]='"+option.trim()+"']")).click(); + } + + public boolean waitForElementPresent(By elementLocator){ + return this.waitForElementPresent(elementLocator, this.timeout); + } + + public boolean waitForElementPresent(By elementLocator, long timeout){ + this.driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS); + //try{ + this.driver.findElement(elementLocator); + + this.driver.manage().timeouts().implicitlyWait(this.timeout, TimeUnit.SECONDS); + return true; + //}catch(NoSuchElementException e){ + //System.err.print(e.getMessage()); + //} + //return false; + } +} \ No newline at end of file diff --git a/tests/functional/src/main/java/com/colosa/qa/automatization/tests/test/Example.java b/tests/functional/src/main/java/com/colosa/qa/automatization/tests/test/Example.java new file mode 100644 index 000000000..993058c34 --- /dev/null +++ b/tests/functional/src/main/java/com/colosa/qa/automatization/tests/test/Example.java @@ -0,0 +1,43 @@ +package com.colosa.qa.automatization.tests.test; + +import com.colosa.qa.automatization.common.FieldType; +import com.colosa.qa.automatization.common.Logger; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.FileNotFoundException; +import java.io.IOException; + +/** + * Created with IntelliJ IDEA. + * User: marco + * Date: 09-07-13 + * Time: 04:41 PM + * To change this template use File | Settings | File Templates. + */ +public class Example extends com.colosa.qa.automatization.tests.common.Test { + + public Example(String browserName) throws IOException { + super(browserName); + } + + @Before + public void setup(){ + + } + + @After + public void cleanup(){ + //browserInstance.quit(); + } + + @Test + public void testExample() throws FileNotFoundException, IOException, Exception{ + pages.gotoDefaultUrl(); + + Logger.addLog("Test testDependentFieldsCase with browserName:" + this.browserName); + + } +} diff --git a/tests/functional/src/test/java/com/colosa/qa/automatization/TestSuiteAll.java b/tests/functional/src/test/java/com/colosa/qa/automatization/TestSuiteAll.java new file mode 100644 index 000000000..6801383f4 --- /dev/null +++ b/tests/functional/src/test/java/com/colosa/qa/automatization/TestSuiteAll.java @@ -0,0 +1,33 @@ +package com.colosa.qa.automatization; + +import com.colosa.qa.automatization.common.Logger; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +/** + * Created with IntelliJ IDEA. + * User: Herbert Saal + * Date: 3/4/13 + * Time: 2:27 PM + * To change this template use File | Settings | File Templates. + + */ +@RunWith(value = Suite.class) +@SuiteClasses({ + com.colosa.qa.automatization.tests.test.Example.class + + }) +public class TestSuiteAll { + @BeforeClass + public static void setUpClass() { + Logger.addLog("Master setup"); + + } + + @AfterClass public static void tearDownClass() { + // Logger.addLog("Master tearDown"); + } +}