• 作业:Github地址: https://github.com/wangkuixing/appium_demo

    yaml文件:

    ---
    xueqiu:
    username: 13823342696
    password: 123456
    stock: pdd
    input:
    - sz000001
    - sh601318
    expect:
    - 平安银行
    - 中国平安

    LoginTest:

    public class LoginTest {

    static MainPage mainPage;
    static ProfilePage profilePage;

    @BeforeAll
    static void beforeAll(){
    mainPage=MainPage.start();
    profilePage=mainPage.gotoProfile();
    }

    //配置驱动
    @Test
    public void nomobileNo1(){
    GlobalConfig config=new GlobalConfig().load("/data/globalConfig.yaml");
    LoginPage loginPage=profilePage.gotoLogin();
    loginPage.passwordFail(config.xueqiu.username, config.xueqiu.password);
    String message=loginPage.getMessage();
    profilePage=loginPage.gotoProfile();
    assertThat(message, equalTo("用户名或密码错误"));
    }


    @ParameterizedTest
    @CsvSource({
    "18688296242, xxxxxxxx",
    })
    public void loginSuceess(String username, String password){
    LoginPage loginPage=profilePage.gotoLogin();
    loginPage.passwordSuccess(username, password);
    }
    }

    ZixuanTest:

    public class ZixuanTest {

    static MainPage mainPage;
    static SearchPage searchPage;
    static StockPage stockPage;
    static ZixuanPage zixuanPage;

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

    }

    //配置驱动
    @ParameterizedTest
    @MethodSource("Getyaml")
    void addZixuantest1(String stockid, String stockname){
    System.out.println(stockid);
    System.out.println(stockname);
    mainPage.gotoMyself();
    searchPage=mainPage.gotoSearch();
    searchPage=searchPage.search(stockid);
    stockPage=searchPage.gotoStock(stockname);
    stockPage.addZixuan();
    searchPage=stockPage.gotoSearch();
    mainPage=searchPage.cancel();
    zixuanPage=mainPage.gotoZixuan();
    ArrayList<String> array=zixuanPage.judgeStockname();
    System.out.println(array);
    assertTrue(array.contains(stockname));
    }

    //配置驱动
    @ParameterizedTest
    @MethodSource("Getyaml")
    void removeZixuan1(String stockid, String stockname) throws InterruptedException {

    Thread.sleep(10000);

    zixuanPage=mainPage.gotoZixuan();
    zixuanPage.removeAdd(stockname);
    }


    static Stream<Arguments> Getyaml() {
    GlobalConfig config = new GlobalConfig().load("/data/globalConfig.yaml");
    return Stream.of(Arguments.of(config.xueqiu.input.get(0),config.xueqiu.expect.get(0)),
    Arguments.of(config.xueqiu.input.get(1),config.xueqiu.expect.get(1)));
    }
    }

  • awk '{print $1}' /tmp/nginx.log |sort |uniq -c |sort -n |tail -5

  • 作业github地址:https://github.com/wangkuixing/appium_demo

    1. MainPage


    public class MainPage extends BasePage{
    By profile=By.id("user_profile_icon");

    public static MainPage start(){
    Driver.start();
    return new MainPage();
    }

    public MainPage gotoMyself(){
    try {
    Thread.sleep(10000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    Driver.getCurrentDriver().findElement(By.xpath("//*[contains(@resource-id, 'tab_name') and @text='雪球']")).click();
    return new MainPage();
    }

    public ProfilePage gotoProfile(){
    Driver.getCurrentDriver().findElement(profile).click();
    return new ProfilePage();

    }

    public SearchPage gotoSearch(){
    Driver.getCurrentDriver().findElement(By.id("home_search")).click();
    return new SearchPage();
    }

    public ZixuanPage gotoZixuan(){
    find(text("自选")).click();
    return new ZixuanPage();
    }
    }

    2. SearchPage

    package page;

    public class SearchPage extends BasePage{
    public SearchPage search(String keyword){
    find(By.className("android.widget.EditText")).sendKeys(keyword);
    return this;
    }

    public MainPage cancel(){
    find(By.id("action_close")).click();
    return new MainPage();
    }

    public ArrayList<String> getAll(){
    ArrayList<String> array=new ArrayList<>();
    for(WebElement e: Driver.getCurrentDriver().findElements(By.id("stockName"))){
    array.add(e.getText());
    }
    return array;
    }

    public SearchPage getStock(){
    return this;

    }

    public ArrayList<String> addSelected(){
    ArrayList<String> array=new ArrayList<String>();
    WebElement select=find(By.xpath("//*[contains(@resource-id, 'follow') and contains(@resource-id, '_btn')]"));
    //array.add(select.getAttribute("id"));
    select.click();
    WebElement select2=find(By.xpath("//*[contains(@resource-id, 'follow') and contains(@resource-id, '_btn')]"));
    //array.add(select.getAttribute("resource-id"));
    select2.click();
    return array;

    }

    public SearchPage removeSelected(){
    return this;

    }

    public StockPage gotoStock(String stockname){
    //By searchresult=By.xpath("//android.widget.RelativeLayout[@instance=8]");
    // By searchresult=By.xpath("//*[@resource-id='stockName' and @text='"+stockname+"']");
    By searchresult=By.id("stockName");
    find(searchresult).click();
    return new StockPage();
    }
    }

    3. StockPage

    public class StockPage extends BasePage{

    By fanhui=By.xpath("//android.widget.ImageView[@instance=0]");

    public StockPage addZixuan(){
    WebDriverWait wait=new WebDriverWait(Driver.getCurrentDriver(),10);
    wait.until(ExpectedConditions.presenceOfElementLocated(text("加自选")));
    find(text("加自选")).click();
    return this;
    }

    public SearchPage gotoSearch(){
    find(fanhui).click();
    return new SearchPage();
    // 后退方法:无法处理下次再说的那个弹窗
    // try {
    // Driver.getCurrentDriver().navigate().back();
    // return new SearchPage();
    // }catch(Exception e){
    // Driver.getCurrentDriver().findElement(text("下次再说")).click();
    // Driver.getCurrentDriver().navigate().back();
    // return new SearchPage();
    }
    }

    4. ZixuanPage

    public class ZixuanPage extends BasePage{

    //取自选股票name到array中
    public ArrayList<String> judgeStockname(){
    ArrayList<String> array=new ArrayList<>();
    for (WebElement e: Driver.getCurrentDriver().findElements(By.id("portfolio_stockName"))){
    array.add(e.getText());
    }
    return array;
    // find(text(stockname)).isEnabled();
    // return this;
    }

    public ZixuanPage removeAdd(String stockname){
    //长按longPress
    WebElement added=find(text(stockname));
    PointOption po=new PointOption();
    po.withCoordinates(added.getLocation().getX(),added.getLocation().getY());
    TouchAction action = new TouchAction(Driver.getCurrentDriver());
    action.longPress(po).release().perform();
    find(text("删除")).click();
    return this;
    }
    }

    5. ZixuanTest

    public class ZixuanTest {

    static MainPage mainPage;
    static SearchPage searchPage;
    static StockPage stockPage;
    static ZixuanPage zixuanPage;

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

    }

    @ParameterizedTest
    @CsvSource({
    "sz000001, 平安银行",
    "sh601318, 中国平安"
    })
    void addZixuantest(String stockid, String stockname){
    mainPage.gotoMyself();
    searchPage=mainPage.gotoSearch();
    searchPage=searchPage.search(stockid);
    stockPage=searchPage.gotoStock(stockname);
    stockPage.addZixuan();
    searchPage=stockPage.gotoSearch();
    mainPage=searchPage.cancel();
    zixuanPage=mainPage.gotoZixuan();
    ArrayList<String> array=zixuanPage.judgeStockname();
    System.out.println(array);
    assertTrue(array.contains(stockname));

    }

    @ParameterizedTest
    @CsvSource({
    "sz000001, 平安银行",
    "sh601318, 中国平安"
    })
    void removeZixuan(String stockid, String stockname) throws InterruptedException {

    Thread.sleep(10000);

    zixuanPage=mainPage.gotoZixuan();
    zixuanPage.removeAdd(stockname);
    }

    }


  • mac环境appium启动成功,但是连接android手机的时候一直报上面这个错,一直调用adb shell kill,用appium-desktop都正常,请问是什么原因呢?而且同一个手机我用windows电脑连接都ok

  • 参数化:
    @DataProvider
    public Object[][] buyProCount(){
    return new Object[][]{
    {-1,10,0,""},
    {10,5,0,""},
    {1,-1,-1,"<库存<0,返回-1>"},
    {1,10,0,"<库存不足,返回0>"},
    {2,5,1,"<购买成功,返回1>"},
    };
    }

    测试代码:
    Login login = new Login();
    Shopping shopping = new Shopping();

    /**
    * 测试shopping.buys方法
    */
    @BeforeClass
    public void BeforeClass(){
    login.userLogin("wangkx","123");
    }

    @Test(dataProvider = "buyProCount",dataProviderClass = BuysParams.class)
    public void testBuys(int proId, int count, int expect, String description){
    int actual = shopping.buys(proId,count);
    Assert.assertEquals(actual,expect);
    System.out.printf("商品ID:"+ proId +";"+ "商品数量:" + count +";" + "执行结果:" + description + "\n");
    }

    @AfterClass
    public void AfterClass(){
    login.userLogin("","");
    }

    执行结果:

  • 作业:
    1、
    netstat -ntp |sed 1,2d |awk '{print $6}' |sort |uniq

    2、
    curl -s https://testerhome.com 2>/dev/null |grep -b1 "fa fa-diamond" |grep -o 'href="/topics/[0-9]' |awk -F '/' '{print $3}' | while read line ;do a=`curl -s "https://testerhome.com/topics/$line" 2>/dev/null |grep 'data-type="Reply' |grep -o 'data-count="[0-9]' |awk -F '"' '{print $2 }'`;echo topics/$line:$a ;done

    输出:
    topics/17292:2 0 1 1
    topics/17232:1 0 0 0 1 1
    topics/17117:2 1 0 0 0 0 0 0 0 0 0 0 0
    ...
    topics/16790:2 0 0 0 1 0 0
    topics/16605:0 0 0 0 0 1 0 0 0 1 0 0
    topics/16436:0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

  • count=$(curl -s "https://testerhome.com/topics/17117" |grep 'data-type="Reply' |grep 'data-count="[0-9]*' |awk -F '"' '{print $4}') ;echo haha is $count
    输出的是:
    haha is 2 1 0 0 0 0 0 0 0 0 0 0 0

    count=$(curl -s "https://testerhome.com/topics/17117" |grep 'data-type="Reply' |grep 'data-count="[0-9]*' |awk -F '"' '{print $4}') ;echo "haha is $count"
    输出的是:
    haha is 2
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0

    为什么echo后面的内容带了双引号“”,和没带双引号会有区别呢?