ReportFlow: // click the Grid icon and switch to grid page public void changeToGrid() // click the Add/Locate icon in the grid page/or in the controller, and then add investment public void addInvestmentToGrid(final String fundName, final String ticker, boolean isGridMode) public void addInvestment(final String fundName, final String ticker, final boolean isGridMode) // wait for the investment exists in the grid or in the controller public void waitForInvestmentExistInGrid(final String fundName, final boolean isGridMode) // click the ColumnManagement icon to enter the ColumnManament popover public void openColumnSetManagement() // click the cancel button in the Column Management popover public void closeColumnSetManagementByCancel() // remove the Column item in the Column Management popover and then click Done button public void deleteColumnSet(final String columnName) // click the posth columnset through clicking the columnset input box in the grid view public String openColumnset(final int pos) // click the list input box, then select and click the last investment list in Grid or in Controller public String openRandomInvestmentList(String testCaseId, boolean isGridMode) // click the list input box, then select and click the target list in the Grid or in the Controller public void openInvestmentList(String listName, boolean isGridMode) // click the checkbox to select it in the save list/column dialog after modifying the list and column public void selectedCheckBox(WebElement element , boolean checked) // create new investment list; this method has a wait time after clicking Enter public void createInvestmentList(final String newName, final boolean isGridMode) // click the Grid icon and switch to grid page public void changeToGrid(){ WebElement gridIcon = reportPage.getICONGrid(); //get the grid icon SeleniumUtil.jsClick(driver, gridIcon); SeleniumUtil.waitForElementVisible(driver, By.cssSelector("div#grid div#primary-header div.grid-header"),"Fail to switch to Grid."); // wait for the grid header to be visible SeleniumUtil.waitForElementVisible(driver, By.cssSelector("div#grid div#grid-content div.grid-view"),"Fail to switch to Grid."); // wait for the grid content/view to be visible } // click the Add/Locate icon in the grid page/or in the controller, and then add investment. This method will //also wait for the investment added/existing in the grid or in the controller public void addInvestmentToGrid(final String fundName, final String ticker, boolean isGridMode) { if(isGridMode){ reportPage.getAddLocateIconInGridMode().click(); } else { reportPage.getAddLocateIcon().click(); } addInvestment(fundName, ticker, isGridMode); } public void addInvestment(final String fundName, final String ticker, final boolean isGridMode) { WebElement inputEl = reportPage.getAddLocateInput(); inputEl.clear(); inputEl.sendKeys(fundName); final ReportPage page = reportPage; Function<WebDriver, Boolean> waitFn = new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { try { List<WebElement> nameList = page.getAddLocateResultNameList(); List<WebElement> tickerList = page.getAddLocateResultTickerList(); int size = nameList.size(); for(int i = 0; i < size; i++){ WebElement nameEl = nameList.get(i); WebElement tickerEl = tickerList.get(i); String nameStr = nameEl.getText().trim(); if(ticker == null){ if(nameStr.contains(fundName.trim())){ nameEl.click(); waitForInvestmentExistInGrid(nameStr, isGridMode); return true; } } else { String tickerStr = tickerEl.getText().split("\\|")[0].trim(); if(nameStr.contains(fundName.trim()) && tickerStr.equals(ticker)){ nameEl.click(); waitForInvestmentExistInGrid(nameStr, isGridMode); return true; } } } } catch (Exception e) { } return false; } }; SeleniumUtil.createWait(driver).withMessage("Fail to add investment.").until(waitFn); } // wait for the investment exists in the grid or in the controller public void waitForInvestmentExistInGrid(final String fundName, final boolean isGridMode) { final ReportPage page = reportPage; Function<WebDriver, Boolean> waitFn = new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { try { List<WebElement> list; if(isGridMode){ list = page.getInvestmentListInGridMode(); // get the investment list in the grid } else { list = page.getInvestmentList(); // get the investment list in the controller } for(WebElement el : list){ if(el.getText().contains(fundName)){ return true; } } } catch (Exception e) { } return false; } }; SeleniumUtil.createWait(driver).withMessage(fundName + " is not in Grid.").until(waitFn); } // click the ColumnManagement icon to enter the ColumnManament popover public void openColumnSetManagement(){ WebElement iconColumnManagement = reportPage.getICONColumnManagement(); SeleniumUtil.jsClick(driver, iconColumnManagement); SeleniumUtil.sleep(2); } // click the cancel button in the Column Management popover public void closeColumnSetManagementByCancel(){ WebElement cancleBtn = reportPage.getCancleBtn(); SeleniumUtil.jsClick(driver, cancleBtn); SeleniumUtil.sleep(2); } // remove the Column item in the Column Management popover and then click Done button public void deleteColumnSet(final String columnName) { openColumnSetManagement(); // enter into ColumnManament popover SeleniumUtil.sleep(2); List<WebElement> itemList = reportPage.getColumnManagementItemList(); for(WebElement el : itemList){ WebElement nameEl = el.findElement(By.cssSelector("div.name")); if(nameEl.getText().equals(columnName)){ el.findElement(By.cssSelector("span.removeMe")).click(); break; } } Function<WebDriver, Boolean> waitFn = new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { try{ List<String> list = getColumnNamesFromColumnset(); return !list.contains(columnName); } catch(Exception e){ } return false; } }; SeleniumUtil.createWait(driver).withMessage("can‘t delete column:" + columnName).until(waitFn); reportPage.getBtnDone().click(); } // click the posth columnset through clicking the columnset input box in the grid view public String openColumnset(final int pos) { WebElement columnsetEl = reportPage.getTXTColumnset(); columnsetEl.click(); Function<WebDriver, List<WebElement>> waitFn = new Function<WebDriver, List<WebElement>>() { @Override public List<WebElement> apply(WebDriver driver) { try { List<WebElement> columnsetList = reportPage.getDLGColumnsetList(); if (columnsetList.size() > pos) { return columnsetList; } return null; } catch (Exception e) { return null; } } }; List<WebElement> list = SeleniumUtil.createWait(driver).until(waitFn); String columnsetName = list.get(pos).getText(); list.get(pos).click(); return columnsetName; } // click the list input box, then select and click the last investment list in Grid or in Controller public String openRandomInvestmentList(String testCaseId, boolean isGridMode) { logger.info("start:openRandomInvestmentList"); WebElement nameInputEl; if(isGridMode){ nameInputEl = reportPage.getListNameDisplayInGridMode(); } else { nameInputEl = reportPage.getListNameDisplay(); } SeleniumUtil.sleep(3); SeleniumUtil.jsClick(driver, nameInputEl); List<WebElement> list = SeleniumUtil.waitForAllElementsVisible(driver, By.cssSelector("div.popover-list div.entity-row")); WebElement targetEl = list.get(list.size() -1); //select the last investment list SeleniumUtil.scrollIntoView(driver, targetEl); String curListName = targetEl.getAttribute("name"); if(!targetEl.isDisplayed()){ SeleniumUtil.scrollIntoView(driver, targetEl); } SeleniumUtil.jsClick(driver, targetEl); return curListName; } // click the list input box, then select and click the target list in the Grid or in the Controller, // you should pass the list name as the target public void openInvestmentList(String listName, boolean isGridMode){ WebElement nameInputEl; if(isGridMode){ nameInputEl = reportPage.getListNameInputInGridMode(); } else { nameInputEl = reportPage.getListNameInput(); } SeleniumUtil.sleep(3); if(!SeleniumUtil.isElementVisible(driver, By.cssSelector("div[name=‘" + listName + "‘]"))){ if(SeleniumUtil.getBrowserName(driver).equals("firefox")){ SeleniumUtil.waitForPageToLoad(driver); JavascriptExecutor js = ((JavascriptExecutor) driver); js.executeScript("$(‘div.controller-list>input‘).click();"); }else{ SeleniumUtil.jsClick(driver, nameInputEl); } } WebElement targetEl = SeleniumUtil.waitForElementVisible(driver, By.cssSelector("div[name=‘" + listName + "‘]")); targetEl.click(); } // click the checkbox to select it in the save list/column dialog after modifying the list and column public void selectedCheckBox(WebElement element , boolean checked){ String classValue = element.getAttribute("class"); if(classValue.contains("selected") && checked){ return; } else{ element.click(); } } // create new investment list; this method has a wait time after clicking Enter public void createInvestmentList(final String newName, final boolean isGridMode) { WebElement saveEl = reportPage.getBTNSave(); SeleniumUtil.jsClick(driver, saveEl); SeleniumUtil.sleep(2); WebElement nameInputEl; if(isGridMode){ nameInputEl = reportPage.getListNameInputInGridMode(); } else { nameInputEl = reportPage.getListNameInput(); } nameInputEl.clear(); nameInputEl.sendKeys(newName); nameInputEl.sendKeys(Keys.ENTER); Function<WebDriver, Boolean> waitFn = new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { try { WebElement nameInputEl; if(isGridMode){ nameInputEl = reportPage.getListNameInputInGridMode(); } else { nameInputEl = reportPage.getListNameInput(); } return newName.equals(nameInputEl.getAttribute("value")); } catch (Exception e) { return false; } } }; // wait for the list is added successfully SeleniumUtil.createWait(driver).withMessage("Fail to input name.").until(waitFn); // wait for the message displayed SeleniumUtil.waitForElementNotVisible(driver, By.cssSelector("span.message-content")); } ------------------------------------------------ ReportPage // the input box in the top-left of the grid view public WebElement getListNameInputInGridMode(); // the list name showing in the input box in the top-left of the grid view public WebElement getListNameDisplayInGridMode() // the differences between getListNameInputInGridMode and getListNameDisplayInGridMode are: // getListNameInputInGridMode().value == getListNameDisplayInGridMode()
Automation 的 ReportFlow
时间: 2024-11-09 10:20:31