我正在使用带有打字稿+摩卡咖啡+柴的Appium进行测试。
我在一个标签上有四个字段,我正在尝试通过测试访问第四个文本字段,并不断出现错误。
查看;
<Label text="Asset Name"></Label>
<TextField automationText="name" hint="Asset Name" [(ngModel)]="_assetItem.name" class="input"></TextField>
<Label text="Purchase Price"></Label>
<TextField automationText="gross" hint="Asset Purchase Price" [(ngModel)]="_assetItem.gross_cents" class="input"></TextField>
<Label text="Comment"></Label>
<TextField automationText="comment" hint="Asset Comment" [(ngModel)]="_assetItem.comment" class="input"></TextField>
</StackLayout>
</ScrollView>
测试;
import { AppiumDriver, createDriver, SearchOptions, nsCapabilities } from "nativescript-dev-appium";
import { assert } from "chai";
const addContext = require('mochawesome/addContext');
describe("Asset Create", () => {
let driver: AppiumDriver;
before(async function(){
nsCapabilities.testReporter.context = this;
driver = await createDriver(); // wait for the driver instance to be created
});
after(async function () {
await driver.quit(); // destroy the driver instance
console.log("Quit driver!");
});
afterEach(async function () {
if (this.currentTest.state === "failed") {
await driver.logTestArtifacts(this.currentTest.title);
}
});
describe("After login", () => {
before(async function () {
// Enter user
const nameField = await driver.findElementByAccessibilityId("email");
await nameField.sendKeys("test");
// Enter password
const passwordField = await driver.findElementByAccessibilityId("password");
await passwordField.sendKeys("password");
// Login
const btnLoginTap = await driver.findElementByAccessibilityId("btnLogin");
await btnLoginTap.click();
});
it.only("creates new asset", async function () {
const btnManualNavTap = await driver.findElementByAccessibilityId("btnNewAsset");
await btnManualNavTap.click();
const nameField = await driver.findElementByAccessibilityId("name");
await nameField.sendKeys("PI");
const grossField = await driver.findElementByAutomationText("gross");
await grossField.sendKeys("5800");
const commentField = await driver.findElementByAutomationText("comment");
await commentField.sendKeys("Used as a camera");
错误;
Exited from appium
0 passing (42s)
1 failing
1) Asset Create
After login
creates new asset:
Error: [element.sendKeys("Used as a camera")] Error response status: 12,
InvalidElementState - An element command could not be completed because the
element is in an invalid state (e.g. attempting to click a disabled element).
Selenium error: Cannot set the element to 'Used as a camera'. Did you interact
with the correct element?
at exports.newError (node_modules/wd/lib/utils.js:152:13)
at /home/map7/code/asset_management/node_modules/wd/lib/callbacks.js:36:19
at /home/map7/code/asset_management/node_modules/wd/lib/webdriver.js:196:5
at Request._callback (node_modules/wd/lib/http-utils.js:89:7)
at Request.self.callback (node_modules/request/request.js:185:22)
at Request.EventEmitter.emit (domain.js:442:20)
at Request.<anonymous> (node_modules/request/request.js:1161:10)
at Request.EventEmitter.emit (domain.js:442:20)
at IncomingMessage.<anonymous> (node_modules/request/request.js:1083:12)
at IncomingMessage.EventEmitter.emit (domain.js:442:20)
at endReadableNT (_stream_readable.js:1085:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ e2e: `node ./node_modules/nativescript-dev-appium/check-dev-deps.js && tsc -p e2e && mocha --opts ./e2e/config/mocha.opts "--runType" "device.samsung"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/map7/.npm/_logs/2019-11-14T02_53_23_647Z-debug.log
~/code/asset_management (asset_tabs✗) %
但是,如果我删除了购买价格和注释标签,则它发现该元素没有问题。当我观看测试时,它不会用键盘覆盖它,但是当我使用手机时,它会覆盖它。测试是通过模拟器运行的,但这可能是探针吗?
我尝试在单击文本字段之前隐藏键盘,但这无济于事。
更新
尝试使用此代码滚动;
const tabContentBasic = await driver.findElementByAutomationText("tabContentBasic");
tabContentBasic.scroll(Direction.down, 200, 0)
这是我的基本标签
<TabContentItem>
<ScrollView orientation="vertical">
<StackLayout orientation="vertical" automationText="tabContentBasic">
<Label text="Date of Purchase"></Label>
<TextField automationText="date" hint="Date of Purchase" [(ngModel)]="_assetItem.date_of_purchase" class="input"></TextField>
<Label text="Asset Name"></Label>
<TextField automationText="name" hint="Asset Name" [(ngModel)]="_assetItem.name" class="input"></TextField>
<Label text="Purchase Price"></Label>
<TextField automationText="gross" hint="Asset Purchase Price" [(ngModel)]="_assetItem.gross_cents" class="input"></TextField>
<Label text="Comment"></Label>
<TextField automationText="comment" hint="Asset Comment" [(ngModel)]="_assetItem.comment" class="input"></TextField>
</StackLayout>
</ScrollView>
</TabContentItem>