zoukankan      html  css  js  c++  java
  • 自动化框架FluentLenium学习

    github地址:https://github.com/FluentLenium/FluentLenium

    常用的页面控件操作方法(element需要先通过css selector找到):

    [button]              button.click();

    1 @FindBy(css = "#searchBtn")
    2 private FluentWebElement searchBtn;

    [input]              fill("input[name='name']").with(name);

    [checkbox]          find("input[type=checkbox]").click();

    [radionbutton]      find("input[type=radio]").click();

    [file upload]      element.getElement().sendKeys(filePath);

    [selector]                 fillSelect("select[name='year']").withText("2014");

    [select checkbox]      //下拉复选框

    这种情况没有直接的方法使用,一般是点击两次达到复选的结果,封装的方法如下:

    1 protected void multiSelect(String selector, List<String> texts) {
    2     find(selector + " + div .multiselect").click();
    3     for (String text : texts) {
    4         await().atMost(5, TimeUnit.SECONDS).until(selector + " + div .multiselect-container").areDisplayed();
    5         find(selector + " + div .multiselect-container").find(".checkbox", withText(text)).click();
    6     }
    7 }

     [时间控件]

    如果时间控件是可以直接输入的话,可以用[input]控件的方法.

    但是如果不能直接输入,必须得点击选择的话,可以使用js来赋值,如下:

    1 executeScript("document.getElementsByName('startTime')[0].value=" + """ + startTime + """ + ";");

     [下载]

    下载需要先设置Firefox浏览器的属性,如下:

    1 FirefoxProfile firefoxProfile = new FirefoxProfile();
    2 String userHome = System.getProperty("user.home");
    3 firefoxProfile.setPreference("browser.download.dir", userHome + "/Downloads");
    4 firefoxProfile.setPreference("browser.download.folderList", 2);
    5 firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf, " +
    6         "application/octet-stream, application/vnd.ms-excel, text/csv, application/zip");
    7 firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    8 return new FirefoxDriver(firefoxProfile);
  • 相关阅读:
    react 采坑记录
    理解JS 模块化
    MongoDB使用教程
    scss
    gulp 使用教程
    node.js 简单入门
    jQuery
    jQuery
    php+mysql+bootstrap 实现成绩管理系统
    SVN的commit功能用bat实现
  • 原文地址:https://www.cnblogs.com/shevche/p/4194588.html
Copyright © 2011-2022 走看看