1.录制自动化脚本

场景:启动雪球,点击我的,登陆雪球,选择手机及其他登陆,输入手机号

2.使用Java进行测试Appium测试

2.1创建Java工程

file-创建maven工程-填写GroupId(团队名)&ArtifactId(工程名)-finish

2.2Java安装Appium客户端

maven中安装Java客户端,只需要在pom.xml中加入java-client依赖即可

2.3添加测试代码

test-java-目录下创建XueqiuDemo.java文件,并将录制生成的Java代码复制进去。
代码发现如下错误,需要导入junit依赖,去maven搜索junit依赖,添加到pom.xml。


pom.xml代码
```#xml

4.0.0

<groupId>csj</groupId>
<artifactId>Study520</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

```
/test/java/XueqiuDemo.java代码
```#java
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;

public class XueqiuDemo {

private AndroidDriver driver;

@Before
public void setUp() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "android");
desiredCapabilities.setCapability("deviceName", "domo");
desiredCapabilities.setCapability("appPackage", "com.xueqiu.android");
desiredCapabilities.setCapability("appActivity", ".view.WelcomeActivityAlias"); URL remoteUrl = new URL("http://localhost:4723/wd/hub"); driver = new AndroidDriver(remoteUrl, desiredCapabilities);
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
} @Test
public void sampleTest() {
MobileElement el1 = (MobileElement) driver.findElementById("com.xueqiu.android:id/user_profile_icon");
el1.click();
MobileElement el2 = (MobileElement) driver.findElementById("com.xueqiu.android:id/tv_login");
el2.click();
MobileElement el3 = (MobileElement) driver.findElementById("com.xueqiu.android:id/tv_login_by_phone_or_others");
el3.click();
MobileElement el4 = (MobileElement) driver.findElementById("com.xueqiu.android:id/register_phone_number");
el4.sendKeys("123456789");
} @After
public void tearDown() {
driver.quit();
}

}


# FAQ
## 1.元素找不到
网络不好,或信号比较差,往往页面加载时间比较长,此时需要添加隐式等待。
初次执行用例或网络比较差,提示找不到元素。是因为页面没有加载完,就开始寻找元素。
<img src="https://img2018.cnblogs.com/blog/1418970/201810/1418970-20181002151514310-1418133742.png" width="700" />
此时只需要添加隐私等待即可
```#java
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);

2.获取maven依赖

以java-client为例:maven依赖地址:https://mvnrepository.com/,查找java-client,并将代码复制到pom.xml。

最新文章

  1. oracle实例恢复之检查点队列
  2. QTP操作word文档
  3. 开源:ASP.NET MVC+EF6+Bootstrap开发框架
  4. Leetcode House Robber II
  5. C# easyui datagrid 复选框填充。
  6. Java Applet使用
  7. [html][转]常用返回顶部代码
  8. HibernateTemplate的find(String querystring)返回值具体解释
  9. rabbitMQ入门
  10. 【Java&amp;Android开源库代码剖析】のAndroid-Universal-Image-Loader-part1
  11. mysql常用的提权方法
  12. linux_http协议
  13. 团队作业4——第一次项目冲刺(Alpha版本)
  14. (二叉树 递归) leetcode 889. Construct Binary Tree from Preorder and Postorder Traversal
  15. instrument 之 core animation
  16. sourceTree 代码未同步合并
  17. 基于前台vue,后台是spring boot的压缩图片上传
  18. c程序的期望
  19. springboot 整合 mybatis
  20. Python数据分析_Pandas_窗函数

热门文章

  1. iOS UIlabel怎么加载html字符串 富文本的用法
  2. DevExpress v17.2新版亮点——Data Access
  3. 【数据库】MFC ODBC(四)
  4. Android中判断字符是否为中文、韩文、日文
  5. hdu-5810 Balls and Boxes(概率期望)
  6. uDig配图与GeoServer添加Style
  7. 如何在magento添加推荐分类
  8. Word2007:如何在竖版(纵向)页面中间插入横版(横向)页面
  9. Unity 3D换装系统教程/Demo
  10. 【问题】C4D中设置了界面颜色,如何恢复默认?