Automation 的 ReportFlow

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

Automation 的 ReportFlow的相关文章

iOS instruments之ui automation的简单使用(高手绕道)

最近使用了几次instruments中的automation工具,现记录下automation的简单使用方法,希望对没接触过自动化测试又有需求的人有所帮助.  UI 自动测试是iOS 中重要的附加功能,它由名为"Automation"的新的工具对象支持.Automation工具的脚本是用JavaScript语言编写,主要用于分析应用的性能和用户行为,模仿/击发被请求的事件,利用它可以完成对被测应用的简单的UI测试及相关功能测试. 一. 简单的录制脚本 打开xcode,这里用我为我家亲爱

20160220 - JavaScript for OS X Automation 调试技巧

在JXA代码中加入如下代码后,可使用 Safari Web Inspector 调试: //debugger; 使用 Safari Web Inspector 查看 Array 或 Object 并不比交互命令行清晰.可以使用以下命令进行交互调试: osascript -l JavaScript -i JavaScript for OS X Automation 控制 Mac OS UIElements 自动化操作时,没有可视化的控件树,寻找控件不一定方便,可使用如下命令即可得到控件树数组,此时

传递给Appium服务器以开启相应安卓Automation会话的Capabilities的几点说明【转】

Desired Capabilities是由客户端发送给Appium服务器端的用来告诉服务器去启动哪种我们想要的会话的一套键值对集合.当中也有一些键值对是用来在自动化的过程中修改服务器端的行为方式的.比如,我们可以把键为platformName的capability的值设置成iOS来告诉服务器我们想要开启的是一个iOS的会话,而非Anddroid的会话.或者我们可以把键为safariAllowPopups 的capability的值设置成true来确保在Safari自动化会话的过程中,我们可以使

关于UI Automation框架

微软提供的UI Automation框架给开发windows平台的自动化测试带来了很大的便利,这里就总结一下相关的代码. 首先,直接使用UI Automation框架,完成一个NotePad的about窗口中的 “OK” button的点击: 1 AutomationElement root = AutomationElement.RootElement; 2 AutomationElement about_notepad_windows = root.FindFirst( 3 TreeScop

使用UI Automation实现自动化测试 --微软提供的控件Pattern

微软提供的控件Pattern System.Windows.Automation 命名空间 System.Windows.Automation.BasePattern 为控件模式类提供基实现 System.Windows.Automation.DockPattern 表示在某个停靠容器内公开其停靠属性的控件 System.Windows.Automation.ExpandCollapsePattern 表示以可视方式进行展开(以显示内容)和折叠(以隐藏内容)的控件. System.Windows

基于UI Automation的自动化测试框架 .

http://blog.csdn.net/roger_ge/article/details/5531941 第一部分:前言 自动化测试或许是众多测试同行都在研究或准备研究的领域.结合自己的能力和公司的状况,选择合适的自动化工具.搭建正确而又高效的框架或许是个永远讨论不完的话题,正如应了那句话,没有最好,只有更好. 个人所在的公司当前开展的很多项目都是基于Win7和WPF开发的,之前想尝试用QTP对之进行录制和回放操作,不幸的是,需要额外的WPF插件支持:另外QTP的脚本语言是VBScript,虽

免费电子书:微软Azure基础之Azure Automation

(此文章同时发表在本人微信公众号"dotNET每日精华文章") Azure Automation是Azure内置的一项自动化运维基础功能,微软为了让大家更快上手使用这项功能,特意推出了一本免费电子书供大家下载阅读. 随着Azure在各国的不断落地和推广,微软也加大了Azure技术的布道工作.最近微软就开始发布一套名为"微软Azure基础(Microsoft Azure Essentials)"的系列电子书,第一本涉及Azure的基础知识,而第二本就详细讲述了Azur

UI Automation

Introduction UI Automation是Microsoft .NET 3.0框架下提供的一种用于自动化测试的技术,是在MSAA基础上建立的,MSAA就是Microsoft Active Accessibility.UI Automation在某些方面超过了MSAA,UI自动化提供了Windows Vista中,微软Windows XP的全部功能,和Windows Server 2003. 在UI Automation中,所有的窗体.控件都表现为一个AutomationElement

ETL Automation完整安装方法_(元数据存放在mysql数据库)

安装前介质准备: DBI-1.636.tar.gz DBD-mysql-4.037.tar.gz ETL.tar Perl下载地址: 第一部分 Mysql数据库安装 链接如:http://jingyan.baidu.com/article/a378c9609eb652b3282830fd.html 第二部分 Perl模块安装 1) 检查当前perl版本命令:perl -v 查看已安装perl模块命令:perldoc perllocal 2) DBI模块为DBI-1.636.tar.gz 方法与D