• 代理是mitmproxy么,测试数据是怎么维护的呢?

  • selenium 定位问题 at April 30, 2019

    应该是滚动条的问题,代码里那个xpath感觉以后会很难维护。。

  • 来了,老弟!!

  • 这么恐怖的么😂

  • 没结婚的我,还以为会是伤感和不舍😅 😅

  • 怎么有种要和老婆分开两周的感觉😂 😂 😂

  • 接口覆盖率一般是怎么保证和统计的呢?

  • 提供一个python3版本的:HTMLTestRunner.py,

  • github地址:Github地址
    Driver


    package Utils;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import java.io.File;
    import java.io.IOException;
    import java.util.concurrent.TimeUnit;

    /**
    * @ClassName: Driver
    * @Description: Driver驱动类
    * @Create: 2019-02-18 16:46
    * @Return:
    **/

    public class Driver{

    static private WebDriver driver;
    /**
    * start()
    * **/

    public static void start() throws IOException {
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    GlobalConfig config = GlobalConfig.load("/data/config.yaml");
    for (String key : config.capabilities.keySet()) {
    Object value = config.capabilities.get(key);
    desiredCapabilities.setCapability(key, value);
    }
    switch (config.brower.toLowerCase()){
    case "chrome":
    String chrome_driverPath = new File("./").getCanonicalPath() + "/src/main/resources/driver/chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", chrome_driverPath);
    driver = new ChromeDriver();
    break;
    case "firefox":
    String firefox_driverPath = new File("./").getCanonicalPath() + "/src/main/resources/driver/geckodriver.exe";
    System.setProperty("webdriver.chrome.driver", firefox_driverPath);
    driver = new ChromeDriver();
    break;
    case "ie":
    String ie_driverPath = new File("./").getCanonicalPath() + "/src/main/resources/driver/IEDriverServer.exe";
    System.setProperty("webdriver.chrome.driver", ie_driverPath);
    driver = new InternetExplorerDriver();
    break;
    default:
    String default_driverPath = new File("./").getCanonicalPath() + "/src/main/resources/driver/chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", default_driverPath);
    driver = new ChromeDriver();
    break;
    }
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
    driver.get(config.url);
    driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
    }

    public static WebDriver getCurrentDriver(){
    return driver;
    }

    }

    yaml文件:

    ---
    url: https://testerhome.com/
    brower: chrome #[chrome firefox ie]
    timeout: 6

    BasePage

    package page;

    import Utils.Driver;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.interactions.Actions;

    import java.util.List;
    import java.util.concurrent.TimeUnit;

    /**
    * @ClassName: BasePage
    * @Description: 基础页
    * @Create: 2019-02-18 16:42
    * @Return:
    **/

    public class BasePage {
    WebDriver driver = Driver.getCurrentDriver();
    public void click(By by){
    driver.findElement(by).click();
    }

    public void waitTime(int num){
    driver.manage().timeouts().implicitlyWait(num, TimeUnit.SECONDS);
    }
    public void sendkeys(By by, String key) {
    driver.findElement(by).sendKeys(key);
    }

    public void clear(By by) {
    driver.findElement(by).clear();
    }

    public String getPageSource(){
    return driver.getPageSource();
    }

    public void actionSendENTER() {
    Actions action = new Actions(driver);
    action.sendKeys(Keys.ENTER).perform();
    }

    public WebElement findElement(By by){
    try{
    WebElement element = driver.findElement(by);
    return element;
    }catch (Exception e){
    e.printStackTrace();
    return null;
    }
    }

    public List<WebElement> findElements(By by){
    try{
    List<WebElement> elements = driver.findElements(by);
    return elements;
    }catch (Exception e){
    e.printStackTrace();
    return null;
    }
    }
    }

    TestCase:

    import Utils.Driver;
    import org.junit.jupiter.api.AfterAll;
    import org.junit.jupiter.api.BeforeAll;
    import org.junit.jupiter.api.Test;
    import page.IndexPage;
    import java.io.IOException;
    import static org.hamcrest.CoreMatchers.equalTo;
    import static org.hamcrest.MatcherAssert.assertThat;

    /**
    * @ClassName: Testerhome
    * @Description: testerhome
    * @Create: 2019-02-18 17:41
    * @Return:
    **/

    public class Testerhome {

    static IndexPage indexPage;
    String expect_info = "访问被拒绝,你可能没有权限或未登录。";

    @BeforeAll
    public static void setup() throws IOException {
    indexPage = IndexPage.start();
    }

    @Test
    public void test(){
    String error = indexPage.gotoLeaguePage().gotoLeagueHogwartsPage().gotoLoginPage().getData();
    assertThat(error,equalTo(expect_info));
    }

    @AfterAll
    public static void teardown(){
    Driver.getCurrentDriver().quit();
    }
    }
  • [项目地址]:(https://github.com/wangqunsong/AppiumXueQiu)
    数据文件
    1.登录数据文件LoginTest.csv:

    "15600534760","xxxxxxxx","用户名或密码错误"
    "1560053476","xxxxxxx","手机号码填写错误"

    2.搜索数据文件SearchTest.csv:

    xiaomi
    alibaba
    pdd
    qd

    3.添加/删除自选数据文件:select.csv:

    小米
    百度
    拼多多
    阿里巴巴

    4.通用配置文件GlobalConfig.yml

    ---
    appium:
    app: "httP://******.apk"
    url: http://127.0.0.1:4723/wd/hub
    wait: 6
    capabilities:
    platformName: android
    deviceName: 192.168.235.101:5555
    appPackage: com.xueqiu.android
    appActivity: .view.WelcomeActivityAlias
    autoGrantPermissions: true

    5.测试用例:

    public class ZiXuanTest {

    static MainPage mainPage; //主页面
    static ZiXuanPage ziXuanPage; //自选页

    @BeforeAll
    static void beforeAll(){
    mainPage = MainPage.start();
    ziXuanPage = mainPage.gotoZiXuan();

    }

    @ParameterizedTest
    @Order(1)
    @DisplayName("增加自选")
    @CsvFileSource(resources = "/data/xueqiu/select.csv")
    public void add_Stock_Test(String stock_name){
    ArrayList<String> arraystockname;
    ziXuanPage.addStock(stock_name);
    arraystockname = ziXuanPage.getStockList();
    assertTrue(arraystockname.contains(stock_name));
    }

    @ParameterizedTest
    @Order(2)
    @DisplayName("删除自选")
    @CsvFileSource(resources = "/data/xueqiu/select.csv")
    public void del_Stock_Test(String stock_name){
    ArrayList<String> arrayList;
    ziXuanPage.cancleStock(stock_name);
    arrayList = ziXuanPage.getStockList();
    assertTrue(!arrayList.contains(stock_name));
    }
    }

愿你善良待人