我正在尝试使用“ Mocha”和“ Appium”来测试我的本机角度应用程序。简单的测试用例已成功执行,但是在找到UI元素时遇到了问题。
错误:“错误:[waitForElementByClassName(“ android.widget.Button”,5000)]元素条件未满足!”
sample.e2e-spec.ts
import { AppiumDriver, createDriver, SearchOptions, nsCapabilities } from "nativescript-dev-appium";
import { assert } from "chai";
const addContext = require('mochawesome/addContext');
describe("sample scenario", async () => {
let driver: AppiumDriver;
before(async function(){
driver = await createDriver();
nsCapabilities.testReporter.context = this;
});
after(async function () {
console.log("Quit driver!");
});
afterEach(async function () {
if (this.currentTest.state === "failed") {
await driver.logTestArtifacts(this.currentTest.title);
}
});
it("should find an element by type", async function () {
let button = await driver.findElementByClassName(driver.locators.button);
console.log('button ',button);
const message = "customLogOut";
console.log('button.text()',button.text());
assert.equal(-1,-1); // simple condition working fine.
assert.equal(await button.text(),message);
});
});
appium.capabilities.json
{
"android18": {
"platformName": "Android",
"platformVersion": "9.0",
"deviceName": "Pixel_2_XL_API_27",
"avd": "Pixel_2_XL_API_27",
"lt": 60000,
"newCommandTimeout": 720,
"noReset": false,
"fullReset": false,
"app": "../platforms/android/app/build/outputs/apk/debug/app-debug.apk"
}
}
app.component.html
<Button col="1" automationText="customLogOut" id="customLogOut" row='3' tap="" text="customLogOut"></Button>
答案 0 :(得分:0)
对于单元测试应用程序,需要将其安装在模拟器或设备上。我有三个虚拟设备,并且我已将该应用程序安装在另一台设备上,并在未通过UI元素的另一台设备上对其进行测试。因此使用“ tns运行android --device“