appium 笔记二:基础层

本文介绍了一种用于UI自动化测试的定位器类设计,通过定义定位类型和元素值实现控件定位。支持多种定位方式如ID、XPath等,并提供XML配置示例用于保存控件定位信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

所谓基础层说得简单一点就是定义存储控件数据的类,这里直接给出源码

package com.datas.api;

/**
 * Created by kitwit on 2017/9/11 0011.
 *
 */

public class Locator {

    private String buttonValue;  //定位地址
    private ByType byType;  //定位方式

    /**
     * 定位类型枚举
     **/
    public enum ByType{
        by, xpath, linkText, id, name, className
    }


    public Locator() {}

    /**
     * Locator构造器,默认定位类型By.id
     * @param element
     */
    public Locator(String buttonValue) {
        this.buttonValue = buttonValue;
        this.byType = ByType.id;
    }



    public Locator(String buttonValue, ByType byType) {
        this.buttonValue = buttonValue;
        this.byType = byType;
    }

    public String getButtonValue(){
        return buttonValue;
    }

//    public ByType getBy() {
//        return byType;
//    }

    public void setBy(ByType byType) {
        this.byType = byType;
    }

    public ByType getByType() {
        return byType;
    }

}


后续用来保存控件的类型和值,本对象类网上参考的可根据需要自行修改
保存控件列表是用的xml文件,形式如下
<?xml version="1.0" encoding="UTF-8"?>
<map>
    <!--locator of page map info -->
    <page pageName="channelPage">
        <!--Locator lists 频道页面的id 统一放在这 -->
        <locator name="back_button"  type="id"  value="org.funlive:id/back_button">返回按钮</locator>
        <locator name="appname"  type="id"  value="org.funlive:id/appname">跳转后频道名字ID</locator>
        <locator name="closed_ad"  type="id"  value="org.funlive:id/close">首页误点击广告页的关闭按钮</locator>
        <locator name="change_btn"  type="id"  value="org.funlive:id/change_btn">央视频道的排序方式更换按钮</locator>
        <locator name="channellist"  type="id"  value="org.funlive:id/channellist">页面排序方式列表排序</locator>
        <locator name="channelgridlist"  type="id"  value="org.funlive:id/channelgridlist">页面排序方式网格排序</locator>
    </page>
</map>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值