List of usage examples for org.openqa.selenium By cssSelector
public static By cssSelector(String cssSelector)
From source file:com.continuuity.test.GenericTest.java
License:Apache License
@BeforeClass public static void setUp() throws Exception { getDriver();//from w w w . j av a 2 s . co m globalDriver.get(Constants.LOGIN_URL); driverWait(1); globalDriver.findElement(By.cssSelector("#username")).sendKeys("admin"); globalDriver.findElement(By.cssSelector("#password")).sendKeys("admin"); globalDriver.findElement(By.cssSelector("#create-provider-form")).submit(); }
From source file:com.continuuity.test.page.CreatePage.ServicesInstancePage.java
License:Apache License
public Map<ProvisionerAction, ServiceAction> getProvisionerActions() { Map<ProvisionerAction, ServiceAction> provisionerActions = Maps.newHashMap(); List<WebElement> actions = globalDriver.findElements(By.cssSelector(".action-entry")); for (WebElement actionEntry : actions) { Select actionSelect = new Select(actionEntry.findElement(CATEGORY)); ProvisionerAction category = ProvisionerAction .valueOf(actionSelect.getFirstSelectedOption().getText().toUpperCase()); Select actionType = new Select(actionEntry.findElement(TYPE)); String type = actionType.getFirstSelectedOption().getText(); List<WebElement> automatorDetails = actionEntry.findElements(By.cssSelector(".automator-field input")); Map<String, String> fields = Maps.newHashMap(); for (WebElement automator : automatorDetails) { String value = automator.getAttribute(Constants.VALUE); if (!value.equals("")) { fields.put(automator.getAttribute("name"), automator.getAttribute(Constants.VALUE)); }/*from ww w. j a v a2 s .c o m*/ } provisionerActions.put(category, new ServiceAction(type, fields)); } return provisionerActions; }
From source file:com.continuuity.test.pagetest.ClustersInstanceTest.java
License:Apache License
@Test public void test_04_nodes() throws ParseException { List<WebElement> serviceSets = globalDriver.findElements(By.cssSelector(".serviceset-name:not(.ng-hide)")); for (int i = 0; i < serviceSets.size(); i++) { serviceSets.get(i).click();//from w w w . ja va2 s .com } Set<TestNode> expectedTestNodes = getExpectedTestNodes(); Set<TestNode> actualTestNodes = getActualTestNodes(); assertEquals("Size is not correct.", expectedTestNodes.size(), actualTestNodes.size()); assertEquals("Nodes are not correct.", expectedTestNodes, actualTestNodes); }
From source file:com.continuuity.test.pagetest.ClustersInstanceTest.java
License:Apache License
private Set<TestNode> getActualTestNodes() throws ParseException { Set<TestNode> idTestNodes = Sets.newHashSet(); List<WebElement> tableRows = globalDriver.findElements(By.cssSelector(".node-entry")); for (int i = 0; i < tableRows.size(); i++) { WebElement tableRow = tableRows.get(i); List<WebElement> tableCells = TEST_UTIL.geTdsFromTr(tableRow); String hostname = tableCells.get(0).getAttribute(Constants.INNER_HTML); String nodeId = tableCells.get(1).getAttribute(Constants.INNER_HTML); String ip = tableCells.get(3).getAttribute(Constants.INNER_HTML); String username = tableCells.get(4).getAttribute(Constants.INNER_HTML); String password = tableCells.get(5).getAttribute(Constants.INNER_HTML); Set<TestNode.Action> actions = getActualActions(tableCells.get(2)); idTestNodes.add(new TestNode(hostname, nodeId, actions, ip, username, password)); }/*from ww w . j a va 2 s .c om*/ return idTestNodes; }
From source file:com.continuuity.test.pagetest.ClustersInstanceTest.java
License:Apache License
private Set<TestNode.Action> getActualActions(WebElement tableCell) throws ParseException { Set<TestNode.Action> results = Sets.newHashSet(); WebElement actionTable = tableCell.findElement(By.cssSelector(Constants.ACTION_TABLE_CLASSNAME)); List<WebElement> tableRows = TEST_UTIL.getRows(actionTable); for (int i = 0; i < tableRows.size(); i++) { List<WebElement> tableCells = TEST_UTIL.geTdsFromTr(tableRows.get(i)); ProvisionerAction action = ProvisionerAction .valueOf(tableCells.get(0).getAttribute(Constants.INNER_HTML)); String service = tableCells.get(1).getAttribute(Constants.INNER_HTML); long submitTime = DATE_FORMAT.parse(tableCells.get(2).getAttribute(Constants.INNER_HTML)).getTime() / 1000;/* w w w .j av a 2 s . co m*/ long duration = getDuration(tableCells.get(3).getAttribute(Constants.INNER_HTML)); String status = tableCells.get(4).getAttribute(Constants.INNER_HTML); results.add(new TestNode.Action(action, service, submitTime, duration, status)); } return results; }
From source file:com.continuuity.test.pagetest.ClustersTest.java
License:Apache License
@Test public void test_04_nonactiveClusters() throws Exception { // Click cluster header to make it visible. globalDriver.findElement(By.cssSelector(".delete-cluster-header")).click(); WebElement delTable = globalDriver.findElement(DEL_CLUSTER).findElement(TABLE); assertEquals("nonactive clusters is not correct.", CLUSTER_READER.getClusters(NON_ACTIVE), getActualClusters(delTable)); }
From source file:com.continuuity.test.pagetest.CreateClustertemplateTest.java
License:Apache License
@Test public void test_01_submitHadoopDistributed() throws Exception { globalDriver.get(Constants.CLUSTERTEMPLATE_CREATE_URI); ClusterTemplate clusterTemplate = EXAMPLE_READER.getClusterTemplate(Constants.CLUSTERTEMPLATE_PATH) .get("hadoop-distributed"); WebElement inputName = globalDriver.findElement(By.cssSelector("#inputName")); inputName.sendKeys(clusterTemplate.getName()); WebElement inputDescription = globalDriver.findElement(By.cssSelector("#inputDescription")); inputDescription.sendKeys(clusterTemplate.getDescription()); List<WebElement> leaseDurationInputs = globalDriver .findElements(By.cssSelector("#lease-duration-table .number-input")); for (WebElement input : leaseDurationInputs) { input.sendKeys("0"); }/*from w w w . j a v a2s . co m*/ globalDriver.findElement(By.cssSelector("#general .next-tab-button")).click(); Global.driverWait(1); Set<String> compatibleServices = clusterTemplate.getCompatibilities().getServices(); Select serviceSelect = new Select( globalDriver.findElement(By.cssSelector("#compatibility .service-select"))); WebElement addServiceBtn = globalDriver.findElement(By.cssSelector("#compatibility .add-service-btn")); for (String service : compatibleServices) { serviceSelect.selectByVisibleText(service); addServiceBtn.click(); } Set<String> compatibleHardwaretypes = clusterTemplate.getCompatibilities().getHardwaretypes(); Select hardwaretypeSelect = new Select( globalDriver.findElement(By.cssSelector("#compatibility .hardwaretype-select"))); WebElement addHardwaretypeBtn = globalDriver .findElement(By.cssSelector("#compatibility .add-hardwaretype-btn")); for (String hardwaretype : compatibleHardwaretypes) { hardwaretypeSelect.selectByVisibleText(hardwaretype); addHardwaretypeBtn.click(); } Set<String> compatibleImagetypes = clusterTemplate.getCompatibilities().getImagetypes(); Select imagetypeSelect = new Select( globalDriver.findElement(By.cssSelector("#compatibility .imagetype-select"))); WebElement addImagetypeBtn = globalDriver.findElement(By.cssSelector("#compatibility .add-imagetype-btn")); for (String imagetype : compatibleImagetypes) { imagetypeSelect.selectByVisibleText(imagetype); addImagetypeBtn.click(); } globalDriver.findElement(By.cssSelector("#compatibility .next-tab-button")).click(); Global.driverWait(1); new Select(globalDriver.findElement(By.cssSelector("#defaults .provider-select"))) .selectByVisibleText(clusterTemplate.getClusterDefaults().getProvider()); Select defaulthardwaretype = new Select( globalDriver.findElement(By.cssSelector("#defaults .hardwaretype-select"))); Select defaultimagetype = new Select( globalDriver.findElement(By.cssSelector("#defaults .imagetype-select"))); List<WebElement> defaultHardwareOptions = defaulthardwaretype.getOptions(); List<WebElement> defaultImageOptions = defaultimagetype.getOptions(); Set<String> defaultHardwareItems = Sets.newHashSet(); for (WebElement item : defaultHardwareOptions) { if (item.getText().length() != 0) { defaultHardwareItems.add(item.getText()); } } Set<String> defaultImageItems = Sets.newHashSet(); for (WebElement item : defaultImageOptions) { if (item.getText().length() != 0) { defaultImageItems.add(item.getText()); } } defaulthardwaretype.selectByVisibleText(clusterTemplate.getClusterDefaults().getHardwaretype()); defaultimagetype.selectByVisibleText(clusterTemplate.getClusterDefaults().getImagetype()); globalDriver.findElement(By.cssSelector("#inputDnsSuffix")) .sendKeys(clusterTemplate.getClusterDefaults().getDnsSuffix().toString()); globalDriver.findElement(By.cssSelector("#inputConfig")) .sendKeys(clusterTemplate.getClusterDefaults().getConfig().toString()); Set<String> defaultServices = clusterTemplate.getClusterDefaults().getServices(); Select defaultServiceSelect = new Select( globalDriver.findElement(By.cssSelector("#defaults .service-select"))); List<WebElement> defaultServiceSelectOptions = defaultServiceSelect.getOptions(); Set<String> defaultServiceSelectItems = Sets.newHashSet(); for (WebElement item : defaultServiceSelectOptions) { if (item.getText().length() != 0) { defaultServiceSelectItems.add(item.getText()); } } assertEquals(compatibleHardwaretypes, defaultHardwareItems); assertEquals(compatibleImagetypes, defaultImageItems); assertEquals(defaultServices, defaultServiceSelectItems); WebElement addServicebtn = globalDriver.findElement(By.cssSelector("#defaults .add-service-btn")); for (String service : defaultServices) { defaultServiceSelect.selectByVisibleText(service); addServicebtn.click(); } globalDriver.findElement(By.cssSelector("#defaults .next-tab-button")).click(); Global.driverWait(1); globalDriver.findElement(By.cssSelector(".add-must-coexist-group")).click(); Global.driverWait(1); Set<String> mustcoexistgroup1 = clusterTemplate.getConstraints().getLayoutConstraint() .getServicesThatMustCoexist().iterator().next(); Select mustCoExistSelect = new Select( globalDriver.findElement(By.cssSelector("#must-coexist-modal .must-coexist-select"))); addServiceBtn = globalDriver.findElement(By.cssSelector("#must-coexist-modal .add-service-btn")); for (WebElement close : globalDriver.findElements(By.cssSelector("#cant-coexist-modal .service-delete"))) { close.click(); } for (String serviceEntry : mustcoexistgroup1) { mustCoExistSelect.selectByVisibleText(serviceEntry); addServiceBtn.click(); } globalDriver.findElement(By.cssSelector("#must-coexist-modal .add-group-btn")).click(); Global.driverWait(1); Set<Set<String>> cantcoexistgroups = clusterTemplate.getConstraints().getLayoutConstraint() .getServicesThatMustNotCoexist(); for (Set<String> cantcoexistentry : cantcoexistgroups) { globalDriver.findElement(By.cssSelector(".add-cant-coexist-group")).click(); Global.driverWait(1); for (WebElement close : globalDriver .findElements(By.cssSelector("#cant-coexist-modal .service-delete"))) { close.click(); } Select cantcoexistSelect = new Select( globalDriver.findElement(By.cssSelector("#cant-coexist-modal .cant-coexist-select"))); addServiceBtn = globalDriver.findElement(By.cssSelector("#cant-coexist-modal .add-service-btn")); for (String serviceEntry : cantcoexistentry) { cantcoexistSelect.selectByVisibleText(serviceEntry); addServiceBtn.click(); } globalDriver.findElement(By.cssSelector("#cant-coexist-modal .add-group-btn")).click(); Global.driverWait(1); } Map<String, ServiceConstraint> serviceConstraints = clusterTemplate.getConstraints() .getServiceConstraints(); Select serviceNameSelect = new Select( globalDriver.findElement(By.cssSelector("#service-constraint-modal .service-select"))); Select serviceHardwaretypeSelect = new Select( globalDriver.findElement(By.cssSelector("#service-constraint-modal .hardwaretype-select"))); addHardwaretypeBtn = globalDriver .findElement(By.cssSelector("#service-constraint-modal .add-hardwaretype-btn")); Select serviceImagetypeSelect = new Select( globalDriver.findElement(By.cssSelector("#service-constraint-modal .imagetype-select"))); addImagetypeBtn = globalDriver.findElement(By.cssSelector("#service-constraint-modal .add-imagetype-btn")); WebElement minConstraint = globalDriver .findElement(By.cssSelector("#service-constraint-modal .constraint-min")); WebElement maxConstraint = globalDriver .findElement(By.cssSelector("#service-constraint-modal .constraint-max")); WebElement addServiceConstraintBtn = globalDriver .findElement(By.cssSelector(".add-service-constraint-btn")); WebElement addServiceConstraintModal = globalDriver .findElement(By.cssSelector(".add-serviceconstraint-modal")); for (Map.Entry<String, ServiceConstraint> entry : serviceConstraints.entrySet()) { addServiceConstraintModal.click(); Global.driverWait(1); minConstraint.clear(); maxConstraint.clear(); String key = entry.getKey(); ServiceConstraint constraint = entry.getValue(); serviceNameSelect.selectByVisibleText(key); if (constraint.getRequiredHardwareTypes() != null) { for (String hardwaretype : constraint.getRequiredHardwareTypes()) { serviceHardwaretypeSelect.selectByVisibleText(hardwaretype); addHardwaretypeBtn.click(); } } if (constraint.getRequiredImageTypes() != null) { for (String imagetype : constraint.getRequiredImageTypes()) { serviceImagetypeSelect.selectByVisibleText(imagetype); addImagetypeBtn.click(); } } minConstraint.sendKeys(String.valueOf(constraint.getMinCount())); maxConstraint.sendKeys(String.valueOf(constraint.getMaxCount())); addServiceConstraintBtn.click(); Global.driverWait(1); } globalDriver.findElement(By.cssSelector("#create-clustertemplate-form")).submit(); Global.driverWait(1); assertEquals(Constants.CLUSTERTEMPLATES_URL, globalDriver.getCurrentUrl()); }
From source file:com.continuuity.test.pagetest.CreateClustertemplateTest.java
License:Apache License
@Test public void test_02_submitServiceError() throws Exception { globalDriver.get(Constants.CLUSTERTEMPLATE_CREATE_URI); assertFalse(globalDriver.findElement(By.cssSelector("#notification")).isDisplayed()); WebElement inputName = globalDriver.findElement(By.cssSelector("#inputName")); inputName.sendKeys("asdf"); WebElement inputDescription = globalDriver.findElement(By.cssSelector("#inputDescription")); inputDescription.sendKeys("asdf"); globalDriver.findElement(By.cssSelector("#create-clustertemplate-form")).submit(); assertTrue(globalDriver.findElement(By.cssSelector("#notification")).isDisplayed()); }
From source file:com.continuuity.test.pagetest.CreateClusterTest.java
License:Apache License
@Test public void test_01_createCluster() throws Exception { JsonObject cluster = CLUSTER_READER.getCreateCluster(); globalDriver.findElement(By.cssSelector("#inputName")).sendKeys(cluster.get("name").getAsString()); globalDriver.findElement(By.cssSelector("#inputNumMachines")) .sendKeys(cluster.get("numMachines").getAsString()); new Select(globalDriver.findElement(By.cssSelector("#inputConfiguration"))) .selectByVisibleText(cluster.get("clusterTemplate").getAsString()); globalDriver.findElement(By.cssSelector(".toggle-advanced-header")).click(); globalDriver.findElement(By.cssSelector(".initial-days")).clear(); globalDriver.findElement(By.cssSelector(".initial-days")).sendKeys("0"); globalDriver.findElement(By.cssSelector("#create-cluster-form")).submit(); Global.driverWait(1);/*from www . ja v a 2s.co m*/ assertEquals(Constants.USER_CLUSTERS, globalDriver.getCurrentUrl()); }
From source file:com.continuuity.test.pagetest.CreateClusterTest.java
License:Apache License
@Test public void test_02_submitClusterError() throws Exception { JsonObject cluster = CLUSTER_READER.getCreateCluster(); globalDriver.get(Constants.CLUSTER_CREATE_URL); WebElement inputName = globalDriver.findElement(By.cssSelector("#inputName")); inputName.sendKeys("asdf"); globalDriver.findElement(By.cssSelector("#create-cluster-form")).submit(); assertTrue(globalDriver.findElement(By.cssSelector("#secondary-notification")).isDisplayed()); new Select(globalDriver.findElement(By.cssSelector("#inputConfiguration"))) .selectByVisibleText(cluster.get("clusterTemplate").getAsString()); globalDriver.findElement(By.cssSelector("#create-cluster-form")).submit(); assertTrue(globalDriver.findElement(By.cssSelector("#notification")).isDisplayed()); }