日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Appium录制脚本520-2

發(fā)布時(shí)間:2025/3/21 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Appium录制脚本520-2 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.錄制自動(dòng)化腳本

場(chǎng)景:啟動(dòng)雪球,點(diǎn)擊我的,登陸雪球,選擇手機(jī)及其他登陸,輸入手機(jī)號(hào)

2.使用Java進(jìn)行測(cè)試Appium測(cè)試

2.1創(chuàng)建Java工程

file-創(chuàng)建maven工程-填寫GroupId(團(tuán)隊(duì)名)&ArtifactId(工程名)-finish

2.2Java安裝Appium客戶端

maven中安裝Java客戶端,只需要在pom.xml中加入java-client依賴即可

2.3添加測(cè)試代碼

test-java-目錄下創(chuàng)建XueqiuDemo.java文件,并將錄制生成的Java代碼復(fù)制進(jìn)去。 代碼發(fā)現(xiàn)如下錯(cuò)誤,需要導(dǎo)入junit依賴,去maven搜索junit依賴,添加到pom.xml。


pom.xml代碼

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><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> </project>

/test/java/XueqiuDemo.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;@Beforepublic 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);}@Testpublic 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");}@Afterpublic void tearDown() {driver.quit();} }

FAQ

1.元素找不到

網(wǎng)絡(luò)不好,或信號(hào)比較差,往往頁(yè)面加載時(shí)間比較長(zhǎng),此時(shí)需要添加隱式等待。
初次執(zhí)行用例或網(wǎng)絡(luò)比較差,提示找不到元素。是因?yàn)轫?yè)面沒有加載完,就開始尋找元素。

此時(shí)只需要添加隱私等待即可

driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);

2.獲取maven依賴

以java-client為例:maven依賴地址:https://mvnrepository.com/,查找java-client,并將代碼復(fù)制到pom.xml。

轉(zhuǎn)載于:https://www.cnblogs.com/csj2018/p/9737205.html

總結(jié)

以上是生活随笔為你收集整理的Appium录制脚本520-2的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。