定向班第一期_appium 项目实战增强_20190120

演练代码

find的定义

    static WebElement find(By locator){
        //todo: 只是demo,更好的根据弹框列表进行批量检索
        try{
            return Driver.getCurrentDriver().findElement(locator);
        }catch (Exception e){
            System.out.println("not found");
            e.printStackTrace();
            Driver.getCurrentDriver().findElement(text("下次再说")).click();
            return Driver.getCurrentDriver().findElement(locator);
        }
    }

参数化

    @ParameterizedTest
    @CsvSource({
            "pdd, 拼多多",
            "alibaba, 阿里巴巴",
            "sogo, 搜狗"
    })
    void 搜索测试(String keyword, String name){
        String content=searchPage.search(keyword).getAll().get(0);
        assertThat(content, equalTo(name));
    }

数据文件驱动

    @ParameterizedTest
    @CsvFileSource(resources = "/data/SearchTest.csv")
    void 选择(String keyword){
        ArrayList<String> array=searchPage.search(keyword).addSelected();
        assertThat(array, hasItems("com.xueqiu.android:id/followed_btn", "com.xueqiu.android:id/follow_btn"));
    }

基本配置驱动

package offline3.meituan;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class MeiTuanConfig {
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Map<String, String> getHosts() {
        return hosts;
    }

    public void setHosts(Map<String, String> hosts) {
        this.hosts = hosts;
    }

    public String getEnv() {
        return env;
    }

    public void setEnv(String env) {
        this.env = env;
    }

    String username="user1";
    String password="password1";
    Map<String, String> hosts=new HashMap<String, String>(){
        {
            put("testing", "127.0.0.1");
            put("stage", "127.0.0.1");
        }

    };
    String env="testing";


    public static void write(String filePath){
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        try {
            mapper.writeValue(new File(filePath), new MeiTuanConfig());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static MeiTuanConfig load(String filePath){
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        MeiTuanConfig conf=new MeiTuanConfig();
        try {
            conf=mapper.readValue(new File(filePath), MeiTuanConfig.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return conf;
    }
}

配置驱动行为

//todo

测试框架

JUnit4 -> TestNG
JUnit4 -> JUnit5

JUnit5 > TestNG > JUnit4
pytest > unittest

作业1

实现基本的配置文件驱动

作业2

把数据文件驱动的测试用例,改成从全局配置文件中读取数据。数据文件、测试用例贴到回复里。整个源代码提供git地址

TODO

  • testcase order
关闭