http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/InstancePage.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/InstancePage.java b/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/InstancePage.java deleted file mode 100644 index 48193a2..0000000 --- a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/InstancePage.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.ui.search; - -import org.apache.falcon.regression.core.util.UIAssert; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.FindBys; -import org.openqa.selenium.support.PageFactory; - -import java.util.EnumSet; -import java.util.List; -import java.util.Set; - - -/** - * Class representation of Search UI entity page. - */ -public class InstancePage extends AbstractSearchPage { - private final String nominalTime; - - /** - * Possible instance actions available on instance page. - */ - public enum Button { - Resume, - Rerun, - Suspend, - Kill - } - - public InstancePage(WebDriver driver) { - super(driver); - nominalTime = driver.findElement(By.xpath("//h3")).getText().split("\\|")[1].trim(); - } - - - @FindBys({ - @FindBy(className = "detailsBox"), - @FindBy(className = "row") - }) - private WebElement detailsBox; - - @FindBys({ - @FindBy(xpath = "//h3/a") - }) - private WebElement entityLink; - - - - @Override - public void checkPage() { - UIAssert.assertDisplayed(detailsBox, "Dependency box"); - UIAssert.assertDisplayed(entityLink, "Link to parrent entity"); - } - - public InstancePage refreshPage() { - return backToEntityPage().openInstance(nominalTime); - } - - public String getStatus() { - return driver.findElement(By.xpath("//h4[@class='instance-title']/span")).getText(); - } - - public String getEntityName() { - return entityLink.getText(); - } - - public boolean isLineagePresent() { - List<WebElement> lineage = driver.findElements(By.className("lineage-graph")); - return !lineage.isEmpty() && lineage.get(0).isDisplayed(); - } - - - public Set<Button> getButtons(boolean active) { - List<WebElement> buttons = detailsBox.findElement(By.className("buttonCell")) - .findElements(By.className("btn")); - Set<Button> result = EnumSet.noneOf(Button.class); - for (WebElement button : buttons) { - if ((button.getAttribute("disabled") == null) == active) { - result.add(Button.valueOf(button.getText())); - } - } - return result; - } - - public void clickButton(Button button) { - detailsBox.findElement(By.className("buttonCell")) - .findElements(By.className("btn")).get(button.ordinal()).click(); - waitForAngularToFinish(); - } - - public EntityPage backToEntityPage() { - entityLink.click(); - return PageFactory.initElements(driver, EntityPage.class); - } -}
http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/LoginPage.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/LoginPage.java b/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/LoginPage.java deleted file mode 100644 index 5b261fb..0000000 --- a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/LoginPage.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.ui.search; - -import org.apache.falcon.regression.core.enumsAndConstants.MerlinConstants; -import org.apache.falcon.regression.core.util.UIAssert; -import org.apache.log4j.Logger; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.FindBys; -import org.openqa.selenium.support.PageFactory; -import org.testng.Assert; - -/** Page object for the Login Page. */ -public class LoginPage extends AbstractSearchPage { - private static final Logger LOGGER = Logger.getLogger(LoginPage.class); - public static final String UI_DEFAULT_USER = MerlinConstants.CURRENT_USER_NAME; - - public LoginPage(WebDriver driver) { - super(driver); - } - - @FindBys({ - @FindBy(className = "mainUIView"), - @FindBy(className = "login") - }) - protected WebElement loginElem; - - public static LoginPage open(WebDriver driver) { - driver.get(UI_URL); - LOGGER.info("Opened a URL: " + UI_URL); - return PageFactory.initElements(driver, LoginPage.class); - } - - private WebElement getUserTextBox() { - return loginElem.findElement(By.xpath("//input[@name='user']")); - } - - public void appendToUserName(String text) { - getUserTextBox().sendKeys(text); - } - - public String getUserVisibleWarning() { - final WebElement userTextBox = getUserTextBox(); - - final WebElement userWarnLabel = getParentElement(userTextBox).findElement( - By.xpath("//label[contains(@class, 'custom-danger') and contains(@class, 'validationMessageGral')]")); - if (userWarnLabel.isDisplayed()) { - return userWarnLabel.getText(); - } - return ""; - } - - /** Try to login by pressing the login button. */ - public void tryLogin() { - LOGGER.info("Trying to login."); - final WebElement loginButton = loginElem.findElement(By.id("login.submit")); - UIAssert.assertDisplayed(loginButton, "Login button"); - loginButton.click(); - } - - /** Login successfully and take to the next page i.e. search page. */ - public SearchPage doDefaultLogin() { - if (!MerlinConstants.IS_SECURE) { - getUserTextBox().clear(); - appendToUserName(UI_DEFAULT_USER); - tryLogin(); - } - LOGGER.info("Search page should have opened."); - final SearchPage searchPage = PageFactory.initElements(driver, SearchPage.class); - searchPage.checkPage(); - final PageHeader searchHeader = searchPage.getPageHeader(); - if (!MerlinConstants.IS_SECURE) { - searchHeader.checkLoggedIn(); - Assert.assertEquals(searchHeader.getLoggedInUser(), LoginPage.UI_DEFAULT_USER, - "Unexpected user is displayed"); - } - return searchPage; - } - - @Override - public void checkPage() { - UIAssert.assertDisplayed(loginElem, "Cluster box"); - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/MirrorWizardPage.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/MirrorWizardPage.java b/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/MirrorWizardPage.java deleted file mode 100644 index f990c92..0000000 --- a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/MirrorWizardPage.java +++ /dev/null @@ -1,517 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.ui.search; - -import org.apache.commons.lang3.StringUtils; -import org.apache.falcon.cli.FalconCLI; -import org.apache.falcon.entity.v0.Frequency; -import org.apache.falcon.entity.v0.cluster.Interfacetype; -import org.apache.falcon.entity.v0.process.ACL; -import org.apache.falcon.entity.v0.process.Retry; -import org.apache.falcon.regression.Entities.ClusterMerlin; -import org.apache.falcon.regression.Entities.RecipeMerlin; -import org.apache.falcon.regression.core.util.TimeUtil; -import org.apache.falcon.regression.core.util.UIAssert; -import org.apache.log4j.Logger; -import org.joda.time.DateTime; -import org.joda.time.format.DateTimeFormat; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.FindBys; - -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** Page object of the Mirror creation page. */ -public class MirrorWizardPage extends AbstractSearchPage { - private static final Logger LOGGER = Logger.getLogger(MirrorWizardPage.class); - @FindBys({ - @FindBy(className = "mainUIView"), - @FindBy(className = "formPage") - }) - private WebElement mirrorBox; - - public MirrorWizardPage(WebDriver driver) { - super(driver); - } - - @Override - public void checkPage() { - UIAssert.assertDisplayed(mirrorBox, "Mirror box"); - } - - - public void setName(String name) { - clearAndSetByNgModel("UIModel.name", name); - } - - public void setTags(List<String> tags) { - //TODO add code here - } - - public void setMirrorType(FalconCLI.RecipeOperation recipeOperation) { - switch (recipeOperation) { - case HDFS_REPLICATION: - driver.findElement(By.xpath("//button[contains(.,'File System')]")).click(); - break; - case HIVE_DISASTER_RECOVERY: - driver.findElement(By.xpath("//button[contains(.,'HIVE')]")).click(); - break; - default: - break; - } - } - - - public void setHiveReplication(RecipeMerlin recipeMerlin) { - if (StringUtils.isNotEmpty(recipeMerlin.getSourceTable())) { - clickById("targetHIVETablesRadio"); - clearAndSetByNgModel("UIModel.source.hiveDatabase", recipeMerlin.getSourceDb()); - clearAndSetByNgModel("UIModel.source.hiveTables", recipeMerlin.getSourceTable()); - } else { - clickById("targetHIVEDatabaseRadio"); - clearAndSetByNgModel("UIModel.source.hiveDatabases", recipeMerlin.getSourceDb()); - } - } - - - public void setStartTime(String validityStartStr) { - final DateTime startDate = TimeUtil.oozieDateToDate(validityStartStr); - - clearAndSetByNgModel("UIModel.validity.start", DateTimeFormat.forPattern("MM/dd/yyyy").print(startDate)); - final WebElement startTimeBox = driver.findElement(By.className("startTimeBox")); - final List<WebElement> startHourAndMinute = startTimeBox.findElements(By.tagName("input")); - final WebElement hourText = startHourAndMinute.get(0); - final WebElement minuteText = startHourAndMinute.get(1); - clearAndSet(hourText, DateTimeFormat.forPattern("hh").print(startDate)); - clearAndSet(minuteText, DateTimeFormat.forPattern("mm").print(startDate)); - final WebElement amPmButton = startTimeBox.findElement(By.tagName("button")); - if (!amPmButton.getText().equals(DateTimeFormat.forPattern("a").print(startDate))) { - amPmButton.click(); - } - } - - public void setEndTime(String validityEndStr) { - final DateTime validityEnd = TimeUtil.oozieDateToDate(validityEndStr); - - clearAndSetByNgModel("UIModel.validity.end", DateTimeFormat.forPattern("MM/dd/yyyy").print(validityEnd)); - final WebElement startTimeBox = driver.findElement(By.className("endTimeBox")); - final List<WebElement> startHourAndMinute = startTimeBox.findElements(By.tagName("input")); - final WebElement hourText = startHourAndMinute.get(0); - final WebElement minuteText = startHourAndMinute.get(1); - clearAndSet(hourText, DateTimeFormat.forPattern("hh").print(validityEnd)); - clearAndSet(minuteText, DateTimeFormat.forPattern("mm").print(validityEnd)); - final WebElement amPmButton = startTimeBox.findElement(By.tagName("button")); - if (!amPmButton.getText().equals(DateTimeFormat.forPattern("a").print(validityEnd))) { - amPmButton.click(); - } - } - - public void toggleAdvancedOptions() { - final WebElement advanceOption = driver.findElement(By.xpath("//h4[contains(.,'Advanced options')]")); - advanceOption.click(); - } - - public void setFrequency(Frequency frequency) { - clearAndSetByNgModel("UIModel.frequency.number", frequency.getFrequency()); - selectNgModelByVisibleText("UIModel.frequency.unit", frequency.getTimeUnit().name().toLowerCase()); - } - - public void setHdfsDistCpMaxMaps(String distCpMaxMaps) { - clearAndSetByNgModel("UIModel.allocation.hdfs.maxMaps", distCpMaxMaps); - } - - - public void setHdfsMaxBandwidth(String replicationMaxMaps) { - clearAndSetByNgModel("UIModel.allocation.hdfs.maxBandwidth", replicationMaxMaps); - } - - public void setHiveDistCpMaxMaps(String distCpMaxMaps) { - clearAndSetByNgModel("UIModel.allocation.hive.maxMapsDistcp", distCpMaxMaps); - } - - - public void setHiveReplicationMaxMaps(String replicationMaxMaps) { - clearAndSetByNgModel("UIModel.allocation.hive.maxMapsMirror", replicationMaxMaps); - } - - public void setMaxEvents(String maxEvents) { - clearAndSetByNgModel("UIModel.allocation.hive.maxMapsEvents", maxEvents); - } - - public void setHiveMaxBandwidth(String maxBandWidth) { - clearAndSetByNgModel("UIModel.allocation.hive.maxBandwidth", maxBandWidth); - } - - - public void setSourceInfo(ClusterMerlin srcCluster) { - setSourceStaging(srcCluster.getLocation("staging")); - setSourceHiveEndpoint(srcCluster.getInterfaceEndpoint(Interfacetype.REGISTRY)); - } - - public void setSourceHiveEndpoint(String hiveEndpoint) { - clearAndSetByNgModel("UIModel.hiveOptions.source.hiveServerToEndpoint", hiveEndpoint); - } - - public void setSourceStaging(String stagingLocation) { - clearAndSetByNgModel("UIModel.hiveOptions.source.stagingPath", stagingLocation); - } - - public void setTargetInfo(ClusterMerlin tgtCluster) { - setTargetStaging(tgtCluster.getLocation("staging")); - setTargetHiveEndpoint(tgtCluster.getInterfaceEndpoint(Interfacetype.REGISTRY)); - } - - public void setTargetHiveEndpoint(String hiveEndPoint) { - clearAndSetByNgModel("UIModel.hiveOptions.target.hiveServerToEndpoint", hiveEndPoint); - } - - public void setTargetStaging(String hiveEndpoint) { - clearAndSetByNgModel("UIModel.hiveOptions.target.stagingPath", hiveEndpoint); - } - - public void setRetry(Retry retry) { - selectNgModelByVisibleText("UIModel.retry.policy", retry.getPolicy().toString().toUpperCase()); - clearAndSetByNgModel("UIModel.retry.delay.number", retry.getDelay().getFrequency()); - selectNgModelByVisibleText("UIModel.retry.delay.unit", retry.getDelay().getTimeUnit().name().toLowerCase()); - clearAndSetByNgModel("UIModel.retry.attempts", String.valueOf(retry.getAttempts())); - } - - - public void setAcl(ACL acl) { - setAclOwner(acl.getOwner()); - setAclGroup(acl.getGroup()); - setAclPermission(acl.getPermission()); - } - - public void setAclOwner(String aclOwner) { - clearAndSetSlowlyByNgModel("UIModel.acl.owner", aclOwner); - } - - public boolean isAclOwnerWarningDisplayed() { - final WebElement warning = - findElementByNgModel("UIModel.acl.owner").findElement(By.xpath("./following-sibling::*")); - waitForAngularToFinish(); - return warning.isDisplayed(); - } - - public void setAclGroup(String aclGroup) { - clearAndSetSlowlyByNgModel("UIModel.acl.group", aclGroup); - } - - public boolean isAclGroupWarningDisplayed() { - final WebElement warning = - findElementByNgModel("UIModel.acl.group").findElement(By.xpath("./following-sibling::*")); - waitForAngularToFinish(); - return warning.isDisplayed(); - } - - public void setAclPermission(String aclPermission) { - clearAndSetSlowlyByNgModel("UIModel.acl.permissions", aclPermission); - } - - public boolean isAclPermissionWarningDisplayed() { - final WebElement warning = - findElementByNgModel("UIModel.acl.permissions").findElement(By.xpath("./following-sibling::*")); - waitForAngularToFinish(); - return warning.isDisplayed(); - } - - public void next() { - final WebElement nextButton = driver.findElement(By.xpath("//button[contains(.,'Next')]")); - nextButton.click(); - } - - public void previous() { - final WebElement prevButton = driver.findElement(By.xpath("//button[contains(.,'Previous')]")); - prevButton.click(); - } - - public void silentPrevious() { - try { - previous(); - } catch (Exception ignore) { - //ignore - } - } - - public void cancel() { - driver.findElement(By.xpath("//a[contains(.,'Cancel')]")); - } - - public void save() { - final WebElement saveButton = driver.findElement(By.xpath("//button[contains(.,'Save')]")); - UIAssert.assertDisplayed(saveButton, "Save button in not displayed."); - saveButton.click(); - waitForAlert(); - } - - public ClusterBlock getSourceBlock() { - return new ClusterBlock("Source"); - } - - public ClusterBlock getTargetBlock() { - return new ClusterBlock("Target"); - } - - /** - * Populates hive dr UI with parameters from recipe. - * @param recipe recipe - * @param overwriteDefaults should it overwrite HiveDR default values automatically picked up by UI - */ - public void applyRecipe(RecipeMerlin recipe, boolean overwriteDefaults) { - final ClusterMerlin srcCluster = recipe.getSrcCluster(); - final ClusterMerlin tgtCluster = recipe.getTgtCluster(); - setName(recipe.getName()); - setTags(recipe.getTags()); - setMirrorType(recipe.getRecipeOperation()); - getSourceBlock().selectCluster(srcCluster.getName()); - getTargetBlock().selectCluster(tgtCluster.getName()); - getSourceBlock().selectRunHere(); - setStartTime(recipe.getValidityStart()); - setEndTime(recipe.getValidityEnd()); - toggleAdvancedOptions(); - switch (recipe.getRecipeOperation()) { - case HDFS_REPLICATION: - getSourceBlock().setPath(recipe.getSourceDir()); - getTargetBlock().setPath(recipe.getTargetDir()); - setHdfsDistCpMaxMaps(recipe.getDistCpMaxMaps()); - setHdfsMaxBandwidth(recipe.getDistCpMaxMaps()); - break; - case HIVE_DISASTER_RECOVERY: - setHiveReplication(recipe); - setHiveDistCpMaxMaps(recipe.getDistCpMaxMaps()); - setHiveReplicationMaxMaps(recipe.getReplicationMaxMaps()); - setMaxEvents(recipe.getMaxEvents()); - setHiveMaxBandwidth(recipe.getMapBandwidth()); - if (overwriteDefaults) { - setSourceInfo(recipe.getSrcCluster()); - setTargetInfo(recipe.getTgtCluster()); - } - break; - default: - break; - } - setFrequency(recipe.getFrequency()); - setRetry(recipe.getRetry()); - setAcl(recipe.getAcl()); - } - - public int getStepNumber() { - try { - driver.findElement(By.xpath("//button[contains(.,'Previous')]")); - return 2; - } catch (Exception ignore) { - //ignore - } - return 1; - } - - public Map<Summary, String> getSummaryProperties() { - String formText = driver.findElement(By.id("formSummaryBox")).getText(); - Map<Summary, String> props = new EnumMap<>(Summary.class); - props.put(Summary.NAME, getBetween(formText, "Name", "Type")); - props.put(Summary.TYPE, getBetween(formText, "Type", "Tags")); - props.put(Summary.TAGS, getBetween(formText, "Tags", "Source")); - props.put(Summary.RUN_ON, getBetween(formText, "Run On", "Schedule")); - props.put(Summary.START, getBetween(formText, "Start on:", "End on:")); - props.put(Summary.END, getBetween(formText, "End on:", "Max Maps")); - props.put(Summary.MAX_MAPS, getBetween(formText, "Max Maps", "Max Bandwidth")); - props.put(Summary.MAX_BANDWIDTH, getBetween(formText, "Max Bandwidth", "ACL")); - - props.put(Summary.ACL_OWNER, getBetween(formText, "Owner:", "Group:")); - props.put(Summary.ACL_GROUP, getBetween(formText, "Group:", "Permissions:")); - props.put(Summary.ACL_PERMISSIONS, getBetween(formText, "Permissions:", "Retry")); - - props.put(Summary.RETRY_POLICY, getBetween(formText, "Policy:", "delay:")); - props.put(Summary.RETRY_DELAY, getBetween(formText, "delay:", "Attempts:")); - props.put(Summary.RETRY_ATTEMPTS, getBetween(formText, "Attempts:", "Frequency")); - - props.put(Summary.FREQUENCY, getBetween(formText, "Frequency", "Previous")); - - String source = getBetween(formText, "Source", "Target"); - String target = getBetween(formText, "Target", "Run On"); - if ("HDFS".equals(props.get(Summary.TYPE))) { - props.put(Summary.SOURCE_LOCATION, getBetween(source, "Location", "Path")); - props.put(Summary.TARGET_LOCATION, getBetween(target, "Location", "Path")); - if ("HDFS".equals(props.get(Summary.SOURCE_LOCATION))) { - props.put(Summary.SOURCE_CLUSTER, getBetween(source, "^", "Location")); - props.put(Summary.SOURCE_PATH, getBetween(source, "Path:", "$")); - - } else { - props.put(Summary.SOURCE_PATH, getBetween(source, "Path:", "URL")); - props.put(Summary.SOURCE_URL, getBetween(source, "URL:", "$")); - - } - if ("HDFS".equals(props.get(Summary.TARGET_LOCATION))) { - props.put(Summary.TARGET_CLUSTER, getBetween(target, "^", "Location")); - props.put(Summary.TARGET_PATH, getBetween(target, "Path:", "$")); - - } else { - props.put(Summary.TARGET_PATH, getBetween(target, "Path:", "URL")); - props.put(Summary.TARGET_URL, getBetween(target, "URL:", "$")); - - } - - } else { - LOGGER.error("TODO Read info for HIVE replication."); - } - - - return props; - } - - /** Parts of the mirror summary. */ - public enum Summary { - NAME, - TYPE, - TAGS, - RUN_ON, - START, - END, - MAX_MAPS, - MAX_BANDWIDTH, - ACL_OWNER, - ACL_GROUP, - ACL_PERMISSIONS, - RETRY_POLICY, - RETRY_DELAY, - RETRY_ATTEMPTS, - FREQUENCY, - SOURCE_LOCATION, - SOURCE_PATH, - SOURCE_CLUSTER, - SOURCE_URL, - TARGET_LOCATION, - TARGET_PATH, - TARGET_CLUSTER, - TARGET_URL, - - } - - private static String getBetween(String text, String first, String second) { - Pattern pattern = Pattern.compile(".*" + first + "(.+)" + second + ".*", Pattern.DOTALL); - Matcher matcher = pattern.matcher(text); - if (matcher.find()) { - return matcher.group(1).trim(); - } else { - return null; - } - } - - /** - * Block of source or target cluster with parameters. - */ - public final class ClusterBlock { - private final WebElement mainBlock; - private final WebElement runHereButton; - private final String blockType; - - private ClusterBlock(String type) { - this.blockType = type; - mainBlock = driver.findElement(By.xpath("//h3[contains(.,'" + type + "')]/..")); - runHereButton = mainBlock.findElement(By.id("runJobOn" + type + "Radio")); - } - - public Set<Location> getAvailableLocationTypes() { - List<WebElement> inputs = getLocationBox().findElements(By.xpath(".//input")); - Set<Location> result = EnumSet.noneOf(Location.class); - for (WebElement input : inputs) { - result.add(Location.getByInput(input)); - } - return result; - } - - public Location getSelectedLocationType() { - WebElement selected = getLocationBox() - .findElement(By.xpath("//input[contains(@class,'ng-valid-parse')]")); - return Location.getByInput(selected); - } - - public void setLocationType(Location type) { - getLocationBox().findElement(By.xpath( - String.format(".//input[translate(@value,'azures','AZURES')='%s']", type.toString()))).click(); - } - - public void selectRunHere() { - runHereButton.click(); - } - - public Set<String> getAvailableClusters() { - List<WebElement> options = mainBlock.findElements(By.xpath(".//option[not(@disabled)]")); - Set<String> clusters = new TreeSet<>(); - for (WebElement option : options) { - clusters.add(option.getText()); - } - return clusters; - } - - public void selectCluster(String clusterName) { - selectNgModelByVisibleText("UIModel." + blockType.toLowerCase() + ".cluster", clusterName); - } - - public void setPath(String path) { - final WebElement srcPathElement = getPath(); - clearAndSet(srcPathElement, path); - } - - public boolean isRunHereSelected() { - return runHereButton.getAttribute("class").contains("ng-valid-parse"); - } - - public boolean isRunHereAvailable() { - return runHereButton.getAttribute("disabled") == null; - } - - - private WebElement getLocationBox() { - return mainBlock.findElement(By.className("locationBox")); - } - - private WebElement getPath() { - return mainBlock.findElement(By.name(blockType.toLowerCase() + "ClusterPathInput")); - } - - - - } - - /** - * Types of source/target location. - */ - public enum Location { - HDFS, - AZURE, - S3; - - private static Location getByInput(WebElement input) { - return Location.valueOf(input.getAttribute("value").trim().toUpperCase()); - } - - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/PageHeader.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/PageHeader.java b/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/PageHeader.java deleted file mode 100644 index 61d9475..0000000 --- a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/PageHeader.java +++ /dev/null @@ -1,310 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.ui.search; - -import org.apache.falcon.regression.core.enumsAndConstants.MerlinConstants; -import org.apache.falcon.regression.core.util.AssertUtil; -import org.apache.falcon.regression.core.util.TimeUtil; -import org.apache.falcon.regression.core.util.UIAssert; -import org.apache.log4j.Logger; -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.FindBys; -import org.openqa.selenium.support.PageFactory; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.testng.Assert; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** Page object for header of the search ui pages. */ -public class PageHeader { - private static final Logger LOGGER = Logger.getLogger(PageHeader.class); - - protected WebDriver driver; - - public PageHeader(WebDriver driver) { - this.driver = driver; - } - - @FindBy(className = "navbar") - private WebElement header; - - @FindBys({ - @FindBy(className = "navbar"), - @FindBy(className = "logoTitle") - }) - private WebElement homeButton; - - @FindBys({ - @FindBy(className = "navbar"), - @FindBy(className = "logoTitle"), - @FindBy(className = "falconLogo") - }) - private WebElement falconLogo; - - @FindBys({ - @FindBy(className = "navbar"), - @FindBy(className = "loginHeaderBox") - }) - private WebElement loginHeaderBox; - - @FindBys({ - @FindBy(className = "navbar"), - @FindBy(className = "createNavWrapper") - }) - private WebElement createEntityBox; - - @FindBy(id = "cluster.create") - private WebElement clusterCreateButton; - - @FindBy(id = "feed.create") - private WebElement feedCreateButton; - - @FindBy(id = "process.create") - private WebElement processCreateButton; - - @FindBy(id = "dataset.create") - private WebElement mirrorCreateButton; - - @FindBys({ - @FindBy(className = "uploadNavWrapper"), - }) - private WebElement uploadEntityBox; - - @FindBys({ - @FindBy(className = "uploadNavWrapper"), - @FindBy(className = "btn-file") - }) - private WebElement uploadEntityButton; - - - public WebElement getHomeButton() { - return homeButton; - } - - public void checkLoggedIn() { - Assert.assertEquals(getLogoutButton().getText(), "Logout", - "Unexpected text on logout button"); - } - - public SearchPage gotoHome() { - homeButton.click(); - final SearchPage searchPage = PageFactory.initElements(driver, SearchPage.class); - searchPage.checkPage(); - final PageHeader searchHeader = searchPage.getPageHeader(); - if (!MerlinConstants.IS_SECURE) { - searchHeader.checkLoggedIn(); - Assert.assertEquals(searchHeader.getLoggedInUser(), LoginPage.UI_DEFAULT_USER, - "Unexpected user is displayed"); - } - return searchPage; - } - - public void checkLoggedOut() { - UIAssert.assertNotDisplayed(getLogoutButton(), "logout button"); - } - - /** - * Check header and make sure all the buttons/links are working correctly. Handles both - * logged in and logged out scenarios. - */ - public void checkHeader() { - //home button is always displayed - UIAssert.assertDisplayed(homeButton, "falcon logo"); - Assert.assertEquals(homeButton.getText(), "Falcon", "Unexpected home button text"); - UIAssert.assertDisplayed(falconLogo, "falcon logo"); - final WebElement helpLink = loginHeaderBox.findElement(By.tagName("a")); - UIAssert.assertDisplayed(helpLink, "help link"); - - final String oldUrl = driver.getCurrentUrl(); - //displayed if user is logged in: create entity buttons, upload entity button, username - if (MerlinConstants.IS_SECURE || getLogoutButton().isDisplayed()) { - //checking create entity box - UIAssert.assertDisplayed(createEntityBox, "Create entity box"); - final WebElement createEntityLabel = createEntityBox.findElement(By.tagName("h4")); - Assert.assertEquals(createEntityLabel.getText(), "Create an entity", - "Unexpected create entity text"); - //checking upload entity part - UIAssert.assertDisplayed(uploadEntityBox, "Create entity box"); - final WebElement uploadEntityLabel = uploadEntityBox.findElement(By.tagName("h4")); - Assert.assertEquals(uploadEntityLabel.getText(), "Upload an entity", - "Unexpected upload entity text"); - Assert.assertEquals(uploadEntityButton.getText(), "Browse for the XML file", - "Unexpected text on upload entity button"); - //checking if logged-in username is displayed - if (!MerlinConstants.IS_SECURE) { - UIAssert.assertDisplayed(getLogoutButton(), "Logout button"); - AssertUtil.assertNotEmpty(getLoggedInUser(), "Expecting logged-in username."); - } - - //create button navigation - doCreateCluster(); - driver.get(oldUrl); - doCreateFeed(); - driver.get(oldUrl); - doCreateProcess(); - driver.get(oldUrl); - doCreateMirror(); - driver.get(oldUrl); - } - //home button navigation - homeButton.click(); - Assert.assertTrue(getHomeUrls().contains(driver.getCurrentUrl()), - "home button navigate to: " + driver.getCurrentUrl() + " instead of: " + getHomeUrls()); - driver.get(oldUrl); - - //help link navigation - Assert.assertEquals(helpLink.getText(), "Help", "Help link expected to have text 'Help'"); - clickLink(helpLink); - int helpPageloadTimeoutThreshold = 30; - new WebDriverWait(driver, helpPageloadTimeoutThreshold).until( - ExpectedConditions.stalenessOf(helpLink)); - Assert.assertEquals(driver.getCurrentUrl(), MerlinConstants.HELP_URL, - "Unexpected help url"); - driver.get(oldUrl); - } - - /** - * Useful in cases when selenium fails to click a link due to it's bugs. - */ - private void clickLink(WebElement link) { - JavascriptExecutor executor = (JavascriptExecutor) driver; - executor.executeScript("arguments[0].click();", link); - } - - public void uploadXml(String filePath) throws IOException { - final WebElement uploadEntityTextBox = uploadEntityBox.findElement(By.id("files")); - uploadEntityTextBox.sendKeys(filePath); - //wait for alert - driver.findElements( - By.xpath("//div[@class='messages notifs' and contains(@style,'opacity') and not(contains(@style,'1;'))]")); - } - - public ClusterWizardPage doCreateCluster() { - UIAssert.assertDisplayed(clusterCreateButton, "Cluster create button"); - Assert.assertEquals(clusterCreateButton.getText(), "Cluster", - "Unexpected text on create cluster button"); - clusterCreateButton.click(); - final ClusterWizardPage clusterPage = PageFactory.initElements(driver, ClusterWizardPage.class); - clusterPage.checkPage(); - return clusterPage; - } - - public FeedWizardPage doCreateFeed() { - UIAssert.assertDisplayed(feedCreateButton, "Feed create button"); - Assert.assertEquals(feedCreateButton.getText(), "Feed", - "Unexpected text on create feed button"); - feedCreateButton.click(); - final FeedWizardPage feedPage = PageFactory.initElements(driver, FeedWizardPage.class); - feedPage.checkPage(); - return feedPage; - } - - public ProcessWizardPage doCreateProcess() { - UIAssert.assertDisplayed(processCreateButton, "Process create button"); - Assert.assertEquals(processCreateButton.getText(), "Process", - "Unexpected text on create process button"); - processCreateButton.click(); - final ProcessWizardPage processPage = PageFactory.initElements(driver, ProcessWizardPage.class); - processPage.checkPage(); - return processPage; - } - - public MirrorWizardPage doCreateMirror() { - UIAssert.assertDisplayed(mirrorCreateButton, "Mirror create button"); - Assert.assertEquals(mirrorCreateButton.getText(), "Mirror", - "Unexpected text on create mirror button"); - mirrorCreateButton.click(); - final MirrorWizardPage mirrorPage = PageFactory.initElements(driver, MirrorWizardPage.class); - mirrorPage.checkPage(); - return mirrorPage; - } - - private List<String> getHomeUrls() { - List<String> urls = new ArrayList<>(); - String homeUrl = MerlinConstants.PRISM_URL; - urls.add(homeUrl); - urls.add(homeUrl.replaceAll("/$", "") + "/#/"); - return urls; - } - - public String getLoggedInUser() { - return loginHeaderBox.findElement(By.tagName("div")).getText(); - } - - private WebElement getLogoutButton() { - return loginHeaderBox.findElements(By.xpath("button[@ng-click='logOut()']")).get(0); - } - - private WebElement getNotificationButton() { - return loginHeaderBox.findElements(By.xpath("button[@ng-click='notify()']")).get(0); - } - - /** - * Validates number of notifications contained by notification bar and last notification message. - */ - public void validateNotificationCountAndCheckLast(int count, String message) { - WebElement notificationButton = getNotificationButton(); - notificationButton.click(); - waitForAngularToFinish(); - - // Test notifications dropdown visibility - WebElement notificationDropdown = notificationButton.findElement(By.className("messages")); - Assert.assertTrue(notificationDropdown.getAttribute("style").contains("display: block;"), - "Notifications are not visible."); - - // Test validity of number of notifications - List<WebElement> notifications = notificationDropdown.findElements(By.xpath("div")); - Assert.assertEquals(notifications.size() - 1, count, "Invalid notification count."); - - // Test validity of last notification - String lastNotification = notifications.get(0).getText(); - Assert.assertTrue(lastNotification.contains(message), "Invalid last notification text."); - } - - public LoginPage doLogout() { - LOGGER.info("Going to logout."); - getLogoutButton().click(); - final LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class); - loginPage.checkPage(); - return loginPage; - } - - protected void waitForAngularToFinish() { - final String javaScript = "return (window.angular != null) && " - + "(angular.element(document).injector() != null) && " - + "(angular.element(document).injector().get('$http').pendingRequests.length === 0)"; - boolean isLoaded = false; - for (int i = 0; i < AbstractSearchPage.PAGELOAD_TIMEOUT_THRESHOLD && !isLoaded; i++) { - final Object output = ((JavascriptExecutor) driver).executeScript(javaScript); - isLoaded = Boolean.valueOf(output.toString()); - LOGGER.info(i+1 + ". waiting on angular to finish."); - TimeUtil.sleepSeconds(1); - } - LOGGER.info("angular is done continuing..."); - } - - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/ProcessWizardPage.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/ProcessWizardPage.java b/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/ProcessWizardPage.java deleted file mode 100644 index 8fcc5b7..0000000 --- a/falcon-regression/merlin/src/main/java/org/apache/falcon/regression/ui/search/ProcessWizardPage.java +++ /dev/null @@ -1,960 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.ui.search; - -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; -import org.apache.falcon.entity.v0.Frequency; -import org.apache.falcon.entity.v0.process.ACL; -import org.apache.falcon.entity.v0.process.Cluster; -import org.apache.falcon.entity.v0.process.Clusters; -import org.apache.falcon.entity.v0.process.EngineType; -import org.apache.falcon.entity.v0.process.ExecutionType; -import org.apache.falcon.entity.v0.process.Input; -import org.apache.falcon.entity.v0.process.Inputs; -import org.apache.falcon.entity.v0.process.Output; -import org.apache.falcon.entity.v0.process.Outputs; -import org.apache.falcon.entity.v0.process.PolicyType; -import org.apache.falcon.entity.v0.process.Retry; -import org.apache.falcon.entity.v0.process.Validity; -import org.apache.falcon.entity.v0.process.Workflow; -import org.apache.falcon.regression.Entities.ProcessMerlin; -import org.apache.falcon.regression.core.util.UIAssert; -import org.apache.log4j.Logger; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.FindBys; -import org.openqa.selenium.support.ui.Select; -import org.testng.Assert; - -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.TimeZone; - -/** Page object of the Process creation page. */ -public class ProcessWizardPage extends EntityWizardPage { - - private static final Logger LOGGER = Logger.getLogger(ProcessWizardPage.class); - - @FindBys({ - @FindBy(className = "mainUIView"), - @FindBy(className = "entityForm") - }) - private WebElement processBox; - - @FindBy(xpath = "//form[@name='processForm']/div[1]") - private WebElement summaryBox; - - @FindBys({ - @FindBy(className = "mainUIView"), - @FindBy(className = "entityForm"), - @FindBy(className = "nextBtn") - }) - private WebElement nextButton; - - @FindBys({ - @FindBy(className = "mainUIView"), - @FindBy(className = "entityForm"), - @FindBy(className = "prevBtn") - }) - private WebElement previousButton; - - @FindBy(xpath = "//a[contains(.,'Cancel')]") - private WebElement cancelButton; - - @FindBy(xpath = "//fieldset[@id='fieldWrapper']") - private WebElement formBox; - - public ProcessWizardPage(WebDriver driver) { - super(driver); - } - - @Override - public void checkPage() { - UIAssert.assertDisplayed(processBox, "Process box"); - } - - /** - * Completes step 1 and clicks next. - */ - public void goToPropertiesStep(ProcessMerlin process) { - setProcessGeneralInfo(process); - clickNext(); - - } - - public void goToClustersStep(ProcessMerlin process) { - goToPropertiesStep(process); - - setProcessPropertiesInfo(process); - clickNext(); - } - - public void clickNext() { - nextButton.click(); - } - - public void clickPrevious(){ - previousButton.click(); - } - - public void clickCancel(){ - cancelButton.click(); - } - - /*----- Step1 General info ----*/ - - private WebElement getName() { - return driver.findElement(By.id("entityNameField")); - } - - public void setName(String name) { - final WebElement nameElement = getName(); - nameElement.clear(); - for (String s : name.split("")) { - nameElement.sendKeys(s); - } - } - private WebElement getTagsSection() { - return driver.findElement(By.id("tagsSection")); - } - - private WebElement getAddTagButton() { - return driver.findElement(By.className("formViewContainer")) - .findElement(By.xpath("./form/div[4]/button")); - } - - private List<WebElement> getDeleteTagButtons() { - return getTagsSection().findElements(By.tagName("button")); - } - - private List<WebElement> getTagTextFields() { - return getTagsSection().findElements(By.tagName("input")); - } - - public void deleteTags() { - //delete all tags - final List<WebElement> deleteTagButtons = getDeleteTagButtons(); - for (WebElement deleteTagButton : Lists.reverse(deleteTagButtons)) { - deleteTagButton.click(); - } - for (WebElement textField : getTagTextFields()) { - textField.clear(); - } - } - - private WebElement getTagKey(int index) { - return processBox.findElements(By.xpath("//input[@ng-model='tag.key']")).get(index); - } - private WebElement getTagValue(int index) { - return processBox.findElements(By.xpath("//input[@ng-model='tag.value']")).get(index); - } - - public void setTagKey(int index, String tagKey){ - getTagKey(index).sendKeys(tagKey); - } - public void setTagValue(int index, String tagValue){ - getTagValue(index).sendKeys(tagValue); - } - - public void setTags(String tagsStr){ - if (StringUtils.isEmpty(tagsStr)){ - return; - } - String[] tags = tagsStr.split(","); - for (int i = 0; i < tags.length; i++){ - String[] keyValue = tags[i].split("="); - setTagKey(i, keyValue[0]); - setTagValue(i, keyValue[1]); - if (tags.length > i + 1){ - getAddTagButton().click(); - } - } - } - - public String getTagKeyText(int index){ - return getTagKey(index).getAttribute("value"); - } - - public String getTagValueText(int index){ - return getTagValue(index).getAttribute("value"); - } - - public boolean isPigRadioSelected(){ - return getPigRadio().isSelected(); - } - - public String getEngineVersionText(){ - return getEngineVersion().getFirstSelectedOption().getAttribute("value"); - } - - private WebElement getWfName() { - return driver.findElement(By.id("workflowNameField")); - } - - private WebElement getOozieRadio() { - return driver.findElement(By.id("oozieEngineRadio")); - } - - private WebElement getPigRadio() { - return driver.findElement(By.id("pigEngineRadio")); - } - - private WebElement getHiveRadio() { - return driver.findElement(By.id("hiveEngineRadio")); - } - - private Select getEngineVersion() { - return new Select(driver.findElement(By.id("engineVersionField"))); - } - - private WebElement getPath() { - return driver.findElement(By.id("pathField")); - } - - public void setWorkflow(Workflow processWf) { - final WebElement wfName = getWfName(); - wfName.clear(); - wfName.sendKeys(processWf.getName()); - switch (processWf.getEngine()) { - case OOZIE: - getOozieRadio().click(); - break; - case PIG: - getPigRadio().click(); - break; - case HIVE: - getHiveRadio().click(); - break; - default: - Assert.fail("Unexpected workflow engine: " + processWf.getEngine()); - } - final String version = processWf.getVersion(); - // The getVersion() method returns '1.0' if its null, hence the hack below - if (StringUtils.isNotEmpty(version) && !version.equals("1.0")) { - getEngineVersion().selectByVisibleText(version); - } - final WebElement path = getPath(); - path.clear(); - path.sendKeys(processWf.getPath()); - } - - private WebElement getAclOwner() { - return driver.findElement(By.name("aclOwnerInput")); - } - - private WebElement getAclGroup() { - return driver.findElement(By.name("aclGroupInput")); - } - - private WebElement getAclPerm() { - return driver.findElement(By.name("aclPermissionsInput")); - } - - public void setAcl(ACL acl) { - final WebElement aclOwner = getAclOwner(); - aclOwner.clear(); - aclOwner.sendKeys(acl.getOwner()); - final WebElement aclGroup = getAclGroup(); - aclGroup.clear(); - aclGroup.sendKeys(acl.getGroup()); - final WebElement aclPerm = getAclPerm(); - aclPerm.clear(); - aclPerm.sendKeys(acl.getPermission()); - } - - public void setProcessGeneralInfo(ProcessMerlin process) { - setName(process.getName()); - final String tags = StringUtils.trimToEmpty(process.getTags()); - setTags(tags); - setWorkflow(process.getWorkflow()); - setAcl(process.getACL()); - } - - public void isFrequencyQuantityDisplayed(boolean isDisplayed) { - if (isDisplayed){ - UIAssert.assertDisplayed(getFrequencyQuantity(), "Frequency Quantity"); - }else { - try{ - getFrequencyQuantity(); - Assert.fail("Frequency Quantity found"); - } catch (Exception ex){ - LOGGER.info("Frequency Quantity not found"); - } - } - } - - public void isValidityStartDateDisplayed(boolean isDisplayed) { - if (isDisplayed){ - UIAssert.assertDisplayed(getStartDate(), "Cluster Validity Start Date"); - }else { - try{ - getStartDate(); - Assert.fail("Cluster Validity Start Date found"); - } catch (Exception ex){ - LOGGER.info("Cluster Validity Start Date not found"); - } - } - } - - public void isAddInputButtonDisplayed(boolean isDisplayed) { - if (isDisplayed){ - UIAssert.assertDisplayed(getAddInputButton(), "Add Input button."); - }else { - try{ - getAddInputButton(); - Assert.fail("Add Input Button found"); - } catch (Exception ex){ - LOGGER.info("Add Input Button not found"); - } - } - } - - public void isSaveButtonDisplayed(boolean isDisplayed) { - if (isDisplayed){ - UIAssert.assertDisplayed(getSaveProcessButton(), "Save Button"); - }else { - try{ - getSaveProcessButton(); - Assert.fail("Save Process Button found"); - } catch (Exception ex){ - LOGGER.info("Save Process Button not found"); - } - } - } - - private WebElement getSaveProcessButton(){ - return formBox.findElement(By.xpath("//button[contains(.,'Save')]")); - } - - public void isTagsDisplayed(int index, boolean isDisplayed){ - if (isDisplayed){ - UIAssert.assertDisplayed(getTagKey(index), "Tag Key Index - " + index); - UIAssert.assertDisplayed(getTagValue(index), "Tag Value Index - " + index); - }else{ - try{ - getTagKey(index); - Assert.fail("Tag Key Index - " + index + " found"); - } catch (Exception ex){ - LOGGER.info("Tag Key Index - " + index + " not found"); - } - try{ - getTagValue(index); - Assert.fail("Tag Key Value - " + index + " found"); - } catch (Exception ex){ - LOGGER.info("Tag Key Value - " + index + " not found"); - } - } - } - - /*----- Step2 Properties ----*/ - - private Select getTimezone() { - return new Select(formBox.findElement(By.xpath("//select[contains(@class, 'TZSelect')]"))); - } - - public void setTimezone(TimeZone timezone) { - if (timezone == null) { - return; - } - String timeZone = timezone.getID(); - getTimezone().selectByValue(timeZone); - } - - private WebElement getFrequencyQuantity() { - return processBox.findElement(By.xpath("//input[@ng-model='process.frequency.quantity']")); - } - private Select getFrequencyUnit() { - return new Select(processBox.findElement(By.xpath( - "//select[@ng-model='process.frequency.unit']"))); - } - - public String getFrequencyQuantityText(){ - return getFrequencyQuantity().getAttribute("value"); - } - - public String getMaxParallelInstancesText(){ - return getMaxParallelInstances().getFirstSelectedOption().getAttribute("value"); - } - - public String getTimezoneText(){ - return getTimezone().getFirstSelectedOption().getAttribute("value"); - } - - public String getOrderText(){ - return getOrder().getFirstSelectedOption().getAttribute("value"); - } - - public void setFrequencyQuantity(String frequencyQuantity){ - getFrequencyQuantity().sendKeys(frequencyQuantity); - } - public void setFrequencyUnit(String frequencyUnit){ - getFrequencyUnit().selectByVisibleText(frequencyUnit); - } - - public List<String> getTimezoneValues(){ - return getDropdownValues(getTimezone()); - } - - public List<String> getFrequencyUnitValues(){ - return getDropdownValues(getFrequencyUnit()); - } - - public List<String> getMaxParallelInstancesValues(){ - return getDropdownValues(getMaxParallelInstances()); - } - - public List<String> getOrderValues(){ - return getDropdownValues(getOrder()); - } - - public List<String> getRetryPolicyValues(){ - return getDropdownValues(getRetryPolicy()); - } - - public List<String> getRetryDelayUnitValues(){ - return getDropdownValues(getRetryDelayUnit()); - } - - private Select getMaxParallelInstances(){ - return new Select(formBox.findElement(By.xpath("//select[@ng-model='process.parallel']"))); - } - - public void setMaxParallelInstances(int quantity) { - getMaxParallelInstances().selectByValue(String.valueOf(quantity)); - } - - private Select getOrder(){ - return new Select(formBox.findElement(By.xpath("//select[@ng-model='process.order']"))); - } - - public void setOrder(ExecutionType order) { - getOrder().selectByValue(order.value()); - } - - private Select getRetryPolicy(){ - return new Select(formBox.findElement(By.xpath("//select[@ng-model='process.retry.policy']"))); - } - - private Select getRetryDelayUnit(){ - return new Select(formBox.findElement(By.xpath("//select[@ng-model='process.retry.delay.unit']"))); - } - - private WebElement getAttempts(){ - return formBox.findElement(By.id("attemptsField")); - } - - private WebElement getDelayQuantity(){ - return formBox.findElement(By.id("delayQuantity")); - } - - public void setRetry(Retry retry) { - getRetryPolicy().selectByValue(retry.getPolicy().value()); - getAttempts().sendKeys(String.valueOf(retry.getAttempts())); - getDelayQuantity().sendKeys(retry.getDelay().getFrequency()); - getRetryDelayUnit().selectByValue(retry.getDelay().getTimeUnit().name()); - } - - /** - * Enter process info on Page 2 of processSetup Wizard. - */ - public void setProcessPropertiesInfo(ProcessMerlin process) { - setTimezone(process.getTimezone()); - setFrequencyQuantity(process.getFrequency().getFrequency()); - setFrequencyUnit(process.getFrequency().getTimeUnit().toString()); - setMaxParallelInstances(process.getParallel()); - setOrder(process.getOrder()); - setRetry(process.getRetry()); - } - - /*-----Step3 Clusters-------*/ - - public WebElement getStartDate() { - List<WebElement> inputs = driver.findElements( - By.xpath("//input[contains(@ng-model, 'cluster.validity.start.date')]")); - return inputs.get(inputs.size() - 1); - } - - public WebElement getEndDate() { - List<WebElement> inputs = formBox.findElements( - By.xpath("//input[contains(@ng-model, 'cluster.validity.end.date')]")); - return inputs.get(inputs.size() - 1); - } - - public String getValidityEnd() { - return String.format("%s %s:%s", getEndDate().getAttribute("value"), getEndHours().getAttribute("value"), - getEndMinutes().getAttribute("value")); - } - - public WebElement getStartHours() { - List<WebElement> inputs = formBox.findElements(By.xpath("//input[contains(@ng-model, 'hours')]")); - return inputs.get(inputs.size() - 2); - } - - public WebElement getEndHours() { - List<WebElement> inputs = formBox.findElements(By.xpath("//input[contains(@ng-model, 'hours')]")); - return inputs.get(inputs.size() - 1); - } - - public WebElement getStartMinutes() { - List<WebElement> inputs = formBox.findElements(By.xpath("//input[contains(@ng-model, 'minutes')]")); - return inputs.get(inputs.size() - 2); - } - - public WebElement getEndMinutes() { - List<WebElement> inputs = formBox.findElements(By.xpath("//input[contains(@ng-model, 'minutes')]")); - return inputs.get(inputs.size() - 1); - } - - public WebElement getStartMeredian() { - List<WebElement> buttons = formBox.findElements(By.xpath("//td[@ng-show='showMeridian']/button")); - return buttons.get(buttons.size() - 2); - } - - public WebElement getEndMeredian() { - List<WebElement> buttons = formBox.findElements(By.xpath("//td[@ng-show='showMeridian']/button")); - return buttons.get(buttons.size() - 1); - } - - /** - * Retrieves the last cluster select. - */ - public Select getClusterSelect() { - List<WebElement> selects = formBox.findElements(By.xpath("//select[contains(@ng-model, 'cluster.name')]")); - return new Select(selects.get(selects.size() - 1)); - } - - public void clickAddClusterButton() { - int initialSize = getWizardClusterCount(); - formBox.findElement(By.xpath("//button[contains(., 'add cluster')]")).click(); - int finalSize = getWizardClusterCount(); - Assert.assertEquals(finalSize - initialSize, 1, "New cluster block should been added."); - } - - /** - * Removes last cluster on the form. - */ - public void deleteLastCluster() { - int initialSize = getWizardClusterCount(); - List<WebElement> buttons = formBox.findElements(By.xpath("//button[contains(., 'delete')]")); - Assert.assertTrue(buttons.size() > 0, - "Delete button should be present. There should be at least 2 cluster blocks"); - buttons.get(buttons.size() - 1).click(); - int finalSize = getWizardClusterCount(); - Assert.assertEquals(initialSize - finalSize, 1, "One cluster block should been removed."); - } - - /** - * Sets multiple clusters in process. - */ - public void setClusters(Clusters clusters) { - for (int i = 0; i < clusters.getClusters().size(); i++) { - if (i > 0) { - clickAddClusterButton(); - } - setCluster(clusters.getClusters().get(i)); - } - } - - /** - * Fills the last cluster on the form. - */ - public void setCluster(Cluster cluster) { - selectCluster(cluster.getName()); - setClusterValidity(cluster); - } - - /** - * Populates cluster form with values from process.Cluster object. - * @param cluster process process.Cluster object - */ - public void setClusterValidity(Cluster cluster) { - SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy-hh-mm-a"); - String start = format.format(cluster.getValidity().getStart()); - String [] parts = start.split("-"); - getStartDate().clear(); - sendKeysSlowly(getStartDate(), parts[0]); - getStartHours().clear(); - sendKeysSlowly(getStartHours(), parts[1]); - getStartMinutes().clear(); - sendKeysSlowly(getStartMinutes(), parts[2]); - String meredian = getStartMeredian().getText(); - if (!meredian.equals(parts[3])) { - getStartMeredian().click(); - } - String end = format.format(cluster.getValidity().getEnd()); - parts = end.split("-"); - getEndDate().clear(); - sendKeysSlowly(getEndDate(), parts[0]); - getEndHours().clear(); - sendKeysSlowly(getEndHours(), parts[1]); - getEndMinutes().clear(); - sendKeysSlowly(getEndMinutes(), parts[2]); - meredian = getEndMeredian().getText(); - if (!meredian.equals(parts[3])) { - getEndMeredian().click(); - } - } - - public void selectCluster(String clusterName) { - getClusterSelect().selectByValue(clusterName); - } - - public String getClusterName(int indx) { - List<WebElement> blocks = formBox.findElements(By.xpath("//div[contains(@class, 'processCluster')]")); - return new Select(blocks.get(indx).findElement(By.tagName("select"))) - .getFirstSelectedOption().getText(); - } - - public int getWizardClusterCount() { - return formBox.findElements(By.xpath("//div[contains(@class, 'processCluster')]")).size(); - } - - public void setProcessClustersInfo(ProcessMerlin process) { - for (int i = 0; i < process.getClusters().getClusters().size(); i++) { - if (i >= 1) { - clickAddClusterButton(); - } - setCluster(process.getClusters().getClusters().get(i)); - } - } - - public List<String> getClustersFromDropDown() { - return getDropdownValues(getClusterSelect()); - } - - public void clickOnValidityStart() { - getStartDate().click(); - List<WebElement> calendars = formBox.findElements(By.xpath("//ul[@ng-model='date']")); - waitForAngularToFinish(); - Assert.assertTrue(calendars.get(calendars.size() - 2).isDisplayed(), "Calendar should pop up."); - } - - public void clickOnValidityEnd() { - getEndDate().click(); - List<WebElement> calendars = formBox.findElements(By.xpath("//ul[@ng-model='date']")); - waitForAngularToFinish(); - Assert.assertTrue(calendars.get(calendars.size() - 1).isDisplayed(), "Calendar should pop up."); - } - - /* Step 4 - Inputs & Outputs*/ - - private WebElement getAddInputButton() { - return formBox.findElement(By.xpath("//button[contains(., 'add input')]")); - } - - private WebElement getAddOutputButton() { - return formBox.findElement(By.xpath("//button[contains(., 'add output')]")); - } - - private WebElement getDeleteInputButton() { - return formBox.findElement(By.xpath("//button[contains(., 'delete')]")); - } - - private WebElement getInputName(int index) { - return formBox.findElements(By.xpath("//input[@ng-model='input.name']")).get(index); - } - - private Select getInputFeed(int index) { - return new Select(formBox.findElements(By.xpath("//select[@ng-model='input.feed']")).get(index)); - } - - private WebElement getInputStart(int index) { - return formBox.findElements(By.xpath("//input[@ng-model='input.start']")).get(index); - } - - private WebElement getInputEnd(int index) { - return formBox.findElements(By.xpath("//input[@ng-model='input.end']")).get(index); - } - - public void setInputInfo(Inputs inputs){ - for (int i = 0; i < inputs.getInputs().size(); i++) { - clickAddInput(); - sendKeysSlowly(getInputName(i), inputs.getInputs().get(i).getName()); - getInputFeed(i).selectByVisibleText(inputs.getInputs().get(i).getFeed()); - sendKeysSlowly(getInputStart(i), inputs.getInputs().get(i).getStart()); - sendKeysSlowly(getInputEnd(i), inputs.getInputs().get(i).getEnd()); - clickCheckBoxSecurely(getOptionalCheckbox(), inputs.getInputs().get(i).isOptional()); - } - } - - private WebElement getOptionalCheckbox() { - return formBox.findElement(By.xpath("//input[@ng-model='input.optional']")); - } - - public boolean isOptionalSelected() { - return getOptionalCheckbox().isSelected(); - } - - public void clickAddInput(){ - waitForAngularToFinish(); - getAddInputButton().click(); - } - - public void clickAddOutput(){ - waitForAngularToFinish(); - getAddOutputButton().click(); - } - - public void clickDeleteInput(){ - getDeleteInputButton().click(); - } - - private WebElement getDeleteOutputButton() { - return formBox.findElement(By.xpath("//button[contains(., 'delete')]")); - } - - private WebElement getOutputName(int index) { - return formBox.findElements(By.xpath("//input[@ng-model='output.name']")).get(index); - } - - private Select getOutputFeed(int index) { - return new Select(formBox.findElements(By.xpath("//select[@ng-model='output.feed']")).get(index)); - } - - private WebElement getOutputInstance(int index) { - return formBox.findElements(By.xpath("//input[@ng-model='output.outputInstance']")).get(index); - } - - public void clickDeleteOutput(){ - getDeleteOutputButton().click(); - } - - public void setOutputInfo(Outputs outputs){ - for (int i = 0; i < outputs.getOutputs().size(); i++) { - clickAddOutput(); - sendKeysSlowly(getOutputName(i), outputs.getOutputs().get(i).getName()); - getOutputFeed(i).selectByVisibleText(outputs.getOutputs().get(i).getFeed()); - sendKeysSlowly(getOutputInstance(i), outputs.getOutputs().get(i).getInstance()); - } - } - - public void setInputOutputInfo(ProcessMerlin process){ - setInputInfo(process.getInputs()); - setOutputInfo(process.getOutputs()); - } - - public List<String> getInputValues(int index){ - return getDropdownValues(getInputFeed(index)); - } - - public List<String> getOutputValues(int index){ - return getDropdownValues(getOutputFeed(index)); - } - - public String getInputNameText(int index){ - return getInputName(index).getAttribute("value"); - } - - public String getInputFeedText(int index){ - return getInputFeed(index).getFirstSelectedOption().getAttribute("value"); - } - - public String getInputStartText(int index){ - return getInputStart(index).getAttribute("value"); - } - - public String getInputEndText(int index){ - return getInputEnd(index).getAttribute("value"); - } - - public String getOutputNameText(int index){ - return getOutputName(index).getAttribute("value"); - } - - public String getOutputFeedText(int index){ - return getOutputFeed(index).getFirstSelectedOption().getAttribute("value"); - } - - public String getOutputInstanceText(int index){ - return getOutputInstance(index).getAttribute("value"); - } - - public void isInputNameDisplayed(int index, boolean isDisplayed) { - if (isDisplayed){ - UIAssert.assertDisplayed(getInputName(index), "Input Name " + index); - }else { - try{ - getInputName(index); - Assert.fail("Input Name " + index + " found"); - } catch (Exception ex){ - LOGGER.info("Input Name " + index + " not found"); - } - } - } - - public void isOutputNameDisplayed(int index, boolean isDisplayed) { - if (isDisplayed){ - UIAssert.assertDisplayed(getOutputName(index), "Output Name " + index); - }else { - try{ - getOutputName(index); - Assert.fail("Output Name " + index + " found"); - } catch (Exception ex){ - LOGGER.info("Output Name " + index + " not found"); - } - } - } - - - /* Step 5 - Summary */ - - public void clickSave(){ - getSaveProcessButton().click(); - waitForAlert(); - } - - @Override - public ProcessMerlin getEntityFromXMLPreview() { - return new ProcessMerlin(getXMLPreview()); - } - - @Override - public WebElement getEditXMLButton() { - return driver.findElement(By.id("editXmlButton")); - } - - /** - * Method gets text from summary box and parses it to ProcessMerlin object. - * @param draft empty ProcessMerlin object - */ - public ProcessMerlin getProcessFromSummaryBox(ProcessMerlin draft) { - String text = summaryBox.getText().trim(); - draft.setName(getProperty(text, null, "Tags", 2)); - String currentBlock = text.substring(text.indexOf("Tags"), text.indexOf("Access Control List")); - String [] parts; - parts = currentBlock.trim().split("\\n"); - String tags = ""; - for (int i = 1; i < parts.length; i++) { - String tag = parts[i]; - if (!tag.contains("No tags")) { - tag = tag.replace(" ", ""); - tags = tags + (tags.isEmpty() ? tag : "," + tag); - } - } - if (!tags.isEmpty()) { - draft.setTags(tags); - } - - Workflow workflow = new Workflow(); - workflow.setName(getProperty(text, "Workflow", "Engine", 2)); - workflow.setEngine(EngineType.fromValue(getProperty(text, "Engine", "Version", 1))); - workflow.setVersion(getProperty(text, "Version", "Path", 1)); - workflow.setPath(getProperty(text, "Path", "Timing", 1)); - draft.setWorkflow(workflow); - - draft.setTimezone(TimeZone.getTimeZone(getProperty(text, "Timing", "Frequency", 2))); - parts = getProperty(text, "Frequency", "Max. parallel instances", 1).split(" "); - draft.setFrequency(new Frequency(parts[1], Frequency.TimeUnit.valueOf(parts[2]))); - draft.setParallel(Integer.parseInt(getProperty(text, "Max. parallel instances", "Order", 1))); - draft.setOrder(ExecutionType.fromValue(getProperty(text, "Order", "Retry", 1))); - - String aclOwner = getProperty(text, "Owner", "Group", 1); - String aclGroup = getProperty(text, "Group", "Permissions", 1); - String aclPermission = getProperty(text, "Permissions", "Workflow", 1); - draft.setACL(aclOwner, aclGroup, aclPermission); - - Retry retry = new Retry(); - retry.setPolicy(PolicyType.fromValue(getProperty(text, "Retry", "Attempts", 2))); - retry.setAttempts(Integer.parseInt(getProperty(text, "Attempts", "Delay", 1))); - parts = getProperty(text, "Delay", "Clusters", 1).split(" "); - retry.setDelay(new Frequency(parts[2], Frequency.TimeUnit.valueOf(parts[3]))); - draft.setRetry(retry); - - //get clusters - currentBlock = text.substring(text.indexOf("Clusters"), text.indexOf("Inputs")); - int last = 0; - while (last != -1) { - Cluster cluster = new Cluster(); - cluster.setName(getProperty(currentBlock, "Name", "Validity", 1)); - //remove the part which was used - currentBlock = currentBlock.substring(currentBlock.indexOf("Validity")); - //get validity - String start = getProperty(currentBlock, "Validity", "End", 2); - //check if there are other clusters - last = currentBlock.indexOf("Name"); - String innerBlock = currentBlock.substring(currentBlock.indexOf("End"), - last != -1 ? last : currentBlock.length() - 1).trim(); - String end = innerBlock.trim().split("\\n")[1]; - Validity validity = new Validity(); - DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy'-'MM'-'dd' 'HH':'mm'"); - validity.setStart(formatter.parseDateTime(start.replaceAll("\"", "")).toDate()); - validity.setEnd(formatter.parseDateTime(end.replaceAll("\"", "")).toDate()); - cluster.setValidity(validity); - draft.getClusters().getClusters().add(cluster); - } - //get inputs - currentBlock = text.substring(text.indexOf("Inputs"), text.indexOf("Outputs")); - last = 0; - while (last != -1) { - Input input = new Input(); - //get input name - input.setName(getProperty(currentBlock, "Name", "Feed", 1)); - //remove the part which was used - currentBlock = currentBlock.substring(currentBlock.indexOf("Name") + 4); - //get input feed - input.setFeed(getProperty(currentBlock, "Feed", "Instance", 1)); - //get input start - input.setStart(getProperty(currentBlock, "Instance", "End", 2)); - //get input end - last = currentBlock.indexOf("Name"); - String innerBlock = currentBlock.substring(currentBlock.indexOf("End"), - last != -1 ? last : currentBlock.length() - 1).trim(); - parts = innerBlock.trim().split("\\n"); - input.setEnd(parts[1]); - draft.getInputs().getInputs().add(input); - //remove part which was parsed - currentBlock = currentBlock.substring(currentBlock.indexOf("End") + 4); - } - //get outputs - currentBlock = text.substring(text.indexOf("Outputs")); - last = 0; - while (last != -1) { - Output output = new Output(); - output.setName(getProperty(currentBlock, "Name", "Feed", 1)); - //remove the part which was used - currentBlock = currentBlock.substring(currentBlock.indexOf("Feed")); - //get feed - output.setFeed(getProperty(currentBlock, "Feed", "Instance", 1)); - last = currentBlock.indexOf("Name"); - output.setInstance(getProperty(currentBlock, "Instance", "Name", 2)); - draft.getOutputs().getOutputs().add(output); - } - //check compulsory process properties - Assert.assertNotNull(draft.getACL(), "ACL is empty (null)."); - return draft; - } - - /** - * Retrieves property from source text. - */ - private String getProperty(String block, String start, String end, int propertyIndex) { - int s = start != null ? block.indexOf(start) : 0; - s = s == -1 ? 0 : s; - int e = end != null ? block.indexOf(end) : block.length() - 1; - e = e == -1 ? block.length() : e; - String subBlock = block.substring(s, e).trim(); - String [] parts = subBlock.trim().split("\\n"); - return parts.length - 1 >= propertyIndex ? parts[propertyIndex].trim() : null; - } -}
