- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我讨厌在测试中使用“ sleep 者”(Thread.sleep(millis)
),但如果没有 sleep 者,一些测试就会失败。
我的 Android
应用程序中有一个 ListView
,我想点击列表中的第一项(在我们的例子中是沙特阿拉伯)。
public AndroidDriver androidDriver;
...
androidDriver = new AndroidDriver(serverAddress, capabilities);
androidDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driverWait = new WebDriverWait(androidDriver, 30);
// at this moment everything is initialized and working properly,
// Appium server is up and running
driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.###.debug:id/countries_list_view")));
WebElement countriesList = driver.findElement(By.id("com.###.debug:id/countries_list_view"));
List<WebElement> countries = countriesList.findElements(By.id("com.###.debug:id/list_item_container"));
WebElement country = countries.get(0);
// country isn't null, and it corresponds to a real ListView row
driverWait.until(ExpectedConditions.elementToBeClickable(country));
Thread.sleep(1000); // <---- country isn't clicked without this
country.click();
Calabash/Cucumber
测试中存在同样的问题(需要显式等待)。
我已经尝试了不同的方式来等待应该被点击的元素
driverWait.until(ExpectedConditions.visibilityOfElementLocated(By));
driverWait.until(ExpectedConditions.visibilityOf(WebElement));
driverWait.until(ExpectedConditions.elementToBeClickable(By));
driverWait.until(ExpectedConditions.presenceOfElementLocated(By));
而且没有一个在工作。当我尝试点击 ListView
第一项时,ListView
存在并且所有列表元素都在屏幕上。
我试图通过使用 Appium Inspector
获取列表行 XPath
来找到 ListView
第一行。结果是一样的 - 没有 Thread.sleep
就不会点击 View 。
在测试中使用 Thread.sleep
是非常糟糕的做法,并且会使我的测试不稳定。在这种情况下,我不能依赖测试结果,因为即使应用程序正常运行,它们也可能会失败。有一篇关于在 Selenium 测试中使用“等待”和“ sleep ”的文章 (Selenium WebDriver wait)。
Thread.sleep
调用在自动化领域的频率如何? (我主要是 Android 开发人员,在移动自动化方面经验不足)。更新:我尽量不混淆隐式和显式等待,如 JeffC提到了,但没有帮助。
这是我的测试:
@Test
public void selectCountryLanguageAndStartApplication() throws Exception {
countryLanguagePage.loaded();
countryLanguagePage.selectFirstCountry();
countryLanguagePage.pleaseSelectCountryTextIsHidden();
countryLanguagePage.startClick();
}
...
/**
* Verify the page has loaded
*/
public static void loaded() {
driver.findElement(By.id("com.###.debug:id/countries_list_view"));
}
我正在验证是否在每次测试中都加载了页面。如果我只使用隐式等待——测试有时会失败;如果我只使用显式等待 - 这是一样的,测试有时会失败。
我在 Appium tutorial 中找到了他们使用 implicit结合明确的1 , 2 .根据 docs 看起来很奇怪.
工作解决方案:我修改了一点loaded
方法
public static void loaded() {
driver.findElement(By.id("com.###.debug:id/countries_list_view"));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
sleep 带来了测试的“稳定性”,我可以找到元素并在明确等待或不等待它们的情况下按下它们。
这是否意味着我应该在新的 Activity
启动时添加“ sleep ”(对我来说唯一可行的解决方案)?或者我正在以错误的方式等待 Activity 初始化?
最佳答案
你可以试试这个:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By));
或
while(!driver.findElement(By).isDisplayed())
{
//Thread.sleep(10);
}
我认为 Thread.sleep
调用很好用(如果您的测试涉及计时,这几乎是必需的)但在大多数情况下,有更好的方法来处理它们将用于的大多数事情。
希望对您有所帮助,
利亚姆
关于android - Appium+Selenium Android : ListView item not clicked without Thread. 休眠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33611579/
我在识别“Appium”中突出显示的元素时收到以下消息。 Appium: 1.7.1设备:iPhone X(12.0 和模拟器)Java 客户端: 1.6.1Xcode:V 10 交互不适用于此元素。
我在 IOS 和 Android 的移动自动化中使用了 Appium。我想知道提供 Calabash 的优势,以及这两种工具生成的脚本是否有共同点? 我已经点击了这个链接:Appium VS Cala
由于 swipe() 已弃用,我无法从左向右滑动屏幕。我的应用程序中有 4 个横幅,我想滑动以查看所有横幅。 最佳答案 这适用于所有方向: 枚举: public enum DIRECTION {
在进行 Appium 测试时,我单击退出应用程序的按钮,如何检查应用程序是否正在运行或我们返回主屏幕。是否有任何方法可以仅通过包名称查找元素列表。 最佳答案 import io.appium.java
我试过命令: npm -install -g appium@1.6 但是当我重新启动 Appium 时,它仍然是 1.5.3 版本。 最佳答案 有两种不同类型的 appium 工具可用 Appium
Mac书空气 Java 1.8 Appium桌面版1.8.1 大家好, 我正在构建一个 TestNG 框架,并且我想以编程方式启动我的 appium 桌面服务器以进行测试。所以我决定做的是创建一个 j
打开终端 (cmd) 并运行 appium-doctor 后,我收到以下警告: WARN AppiumDoctor ✖ opencv4nodejs cannot be found. WARN Appi
这里是移动自动化的新手。我正在尝试使用 Touch Action 执行以下代码来执行滑动操作以导航到第 2 页,但滑动不起作用。 AndroidDriver driver=new AndroidDri
我有一个 iOS 应用程序,它在单个页面上有很多输入字段。我想自动执行这些输入,我知道如何滚动到这些元素和所有内容,但我对部分显示的元素有疑问。 有两种情况下部分显示的元素会导致问题: 第一种情况是当
我正在使用 eclipse 学习 appium,但在启动我的模拟器时卡住了。我尝试了不同的方法,例如在文件夹结构中四处移动文件,但我一直收到 文件不存在或不可访问 我尝试搜索答案,但没有任何帮助。 p
我的应用程序需要多个应用程序权限。我需要通过允许或拒绝不同的权限来检查我的应用程序的行为。如何从 appium 启用/禁用应用程序权限以创建多个场景? 例如,假设我的应用程序需要权限:permissi
我正在使用 Appium 版本 V1.15.0 并且已经使用默认主机:0.0.0.0 和端口:4723 成功启动服务器 但是现在当我尝试启动服务器时,它显示了这个错误“Error Starting A
我在一家提供 wifi 的公司工作。我有一些接入点设置,我想编写一些模拟连接到这些接入点的自动化测试。 所以我的测试将是这样的: 发射装置 转到设备上的 wifi 设置 选择要连接的wifi 验证设备
我在用 : Xcode 10.1 Os Version : 12.1 iPhone 6 我确实按照所有必需的步骤来设置构建和所有内容,但是在尝试使用 xcode build 构建项目时仍然出现错误。
我正在使用 appium 工具测试我的应用程序。在测试过程中,android应用程序在启动器事件附近崩溃,仅在8以下版本的某些设备上显示以下错误。如何解决? An unknown server-sid
我试图运行测试ipa。但是 appium 在循环中重新启动应用程序并产生此错误。 [INST STDERR] Instruments Trace Error : Target failed to ru
我想知道是否有人知道在运行 Appium 测试时使用什么 Java/Groovy 库/工具来嗅探、记录和处理 native 应用程序的 HTTP 流量?有没有人在特定情况下使用 Browser Mob
我在测试中担任 SD。我是 Appium 自动化工具的新手,这个工具对我来说设置环境非常棘手。 我引用了以下链接:http://unmesh.me/category/appium/ 这个链接帮助我安装
正在测试 Android 和 iOS 应用程序。这是我的应用程序的配置屏幕,出现一个 OTP 用例,停止对应用程序的进一步测试。用例是。 当用户在应用程序的起始页面输入手机号码时,指令为 。点击发送按
我已经安装了 appium doctor 并且在 mac 上没有错误地安装了它。但是,当我使用命令“appium-doctor -h”进行检查时。它给出了以下异常。你能告诉我这里出了什么问题吗: ap
我是一名优秀的程序员,十分优秀!