尝试访问按钮元素时,waitForElement不是JSON响应

时间:2019-04-02 11:03:31

标签: appium nativescript e2e-testing

首先,我对NativeScript和e2e测试还很陌生,但是我试图让一些简单的测试在我的演示应用程序上运行。我完成了整个安装过程,安装了所有内容,并创建了一个e2e(默认)文件夹和文件。

我有这个演示应用程序布局,基本上我只有一个按钮:

<ActionBar title="My App" class="action-bar">
</ActionBar>

<GridLayout class="page">
     <StackLayout>
        <Button automationText="testButton" text="Button"></Button>
     </StackLayout>
</GridLayout>

这些是我的测试

import { AppiumDriver, createDriver, SearchOptions } from "nativescript-dev-appium";
import { assert } from "chai";

describe("sample scenario", () => {
    const defaultWaitTime = 5000;
    let driver: AppiumDriver;

    before(async () => {
        driver = await createDriver();
    });

    after(async () => {
        await driver.quit();
        console.log("Quit driver!");
    });

    afterEach(async function () {
        if (this.currentTest.state === "failed") {
           // await driver.logTestArtifacts(this.currentTest.title);
        }
    });

    it("should find an element by text", async () => {
        const btn = await driver.findElementByText("Button");
        assert.isTrue(btn.exists());
    });

    it("should find an element by automation text", async () => {
         const btn = await driver.findElementByAutomationText("testButton");
         assert.isTrue(btn.exists());
    });
});

我必须对此行发表评论,否则,我的测试将无法完成(我必须使用ctrl C手动停止它们):

// await driver.logTestArtifacts(this.currentTest.title);

我在运行它:

$ npm build ios
$ npm run e2e -- --runType sim.iPhone6

我能够运行愚蠢的测试assertTrue(true),但是当我尝试访问元素,按钮时,事情就出错了:

    should find an element by text:
 [waitForElementByXPath("//*[@label='Button' or @value='Button' or @hint='Button']",5000)] [elements("xpath","//*[@label='Button' or @value='Button' or @hint='Button']")] Not JSON response
  Error: [elements("xpath","//*[@label='Button' or @value='Button' or @hint='Button']")] Not JSON response
  at exports.newError (node_modules/wd/lib/utils.js:151:13)

并且:

 should find an element by automation text:
 [waitForElementByAccessibilityId("testButton",5000)] [elements("accessibility id","testButton")] Not JSON response
  Error: [elements("accessibility id","testButton")] Not JSON response
  at exports.newError (node_modules/wd/lib/utils.js:151:13)

我还试图查看驱动程序是否只是空的或类似的东西,但是isIOS和isAndroid可以正常工作。

我不知道这是否与它有关,但是在杀死驱动程序时也会弹出此错误:

Error: [quit()] Unexpected data in simpleCallback.

如果有人可以帮助,那就太好了!谢谢!

1 个答案:

答案 0 :(得分:0)

{N} Appium Github repo上似乎登录了类似的问题,问题似乎出在环境设置上,至少在他们没有安装carthage的情况下。

您是否经过setup process here并确保一切都准备就绪?