使用Ionic 4-应用程序运行e2e测试时发生意外行为

时间:2019-05-08 12:38:49

标签: selenium angular7 ionic4 e2e-testing appium-android

我正在运行我的ionic 4应用程序的e2e测试。因此,我正在使用android手机(-v 6.0.1)和appium(-v 1.13.0)在设备上运行量角器测试。

我对使用appium进行测试非常陌生,因此我一直遵循此Tutorial

在对项目进行少量调整后,我运行了appium,并且量角器从给定的protractor.config.ts开始,但是由于某些原因,创建会话后的响应始终是立即超时,例如:

[HTTP] <-- POST /wd/hub/session 200 17115 ms - 1480
[HTTP]
[HTTP] --> POST /wd/hub/session/:session-id/timeouts
[HTTP] {"script":11000}

该应用程序很快就会在手机上可见,但是会立即关闭,而不进行任何测试。


protractor.config.ts:

import { Config } from 'protractor';
import * as tsNode from 'ts-node';


const serverAddress = 'http://localhost:4723/wd/hub';
const testFilePatterns: Array<string> = [
  'e2e/src/app.e2e-spec.ts'
];

const androidPixel2XLCapability = {
  automationName: 'Appium',
  autoWebview: true,
  deviceReadyTimeout: 30000,
  androidDeviceReadyTimeout: 30000,
  browserName: '',
  platformName: 'Android',
  deviceName: 'pixel2xl',
  app: '/path/platforms/android/app/build/outputs/apk/debug/app-debug.apk',
  'app-package': 'io.ionic.hello',
  'app-activity': 'MainActivity',
  autoAcceptAlerts: true,
  autoGrantPermissions: true,
  chromedriverExecutable: 'e2e/chromedriver.exe'
};

export let config: Config = {
  newCommandTimeout: 30000,
  specs: testFilePatterns,
  baseUrl: '',
  multiCapabilities: [
    androidPixel2XLCapability
  ],
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
  },
  seleniumAddress: serverAddress,
  onPrepare: () => {
    tsNode.register({
      project: 'tsconfig.json'
    });
  }
};

app.e2e-spec.ts:

import { AppPage } from './PageObjects/app.po';

describe('TabsPage', () => {
  let page: AppPage;

  beforeEach(() => {
    page = new AppPage();

  });

  it('should be defined', () => {
    expect(page.rootElement()).toBeDefined();
  });

});

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2018",
      "dom"
    ],
    "outDir": "./dist/out-tsc",
    "module": "es2015",
    "target": "es5",
    "baseUrl": "./",
    "typeRoots": [
      "node_modules/@types"
    ],
  }
}

tsconfig.e2e.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "jasminewd2",
      "node"
    ]
  },
  "include": [
    "./*.config.ts"
  ],
  "exclude": [
    "./test"
  ]
}

package.json

{
  "scripts": {
    "appium": "appium",
    "e2e": "tsc -p e2e/tsconfig.e2e.json && protractor out-tsc/app/protractor.config.js --verbose"
  }
}

运行方式:

$ npm run e2e

> project-admin@0.0.1 e2e C:\Projects\project
> tsc -p e2e/tsconfig.e2e.json && protractor out-tsc/app/protractor.config.js --verbose

[14:28:26] I/launcher - Running 1 instances of WebDriver
[14:28:26] I/hosted - Using the selenium server at http://localhost:4723/wd/hub
Started


No specs found
Finished in 0.004 seconds

[14:28:45] I/launcher - 0 instance(s) of WebDriver still running
[14:28:45] I/launcher -  #01 passed

appium日志:

[debug] [Chromedriver] Chromedriver version: '2.28.455520'
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8001/wd/hub/status] with no body
[debug] [WD Proxy] Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.17134\"}}}"
[debug] [WD Proxy] Determined that the downstream protocol for proxy is MJSONWP
[debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8001/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"de.ionic.hello","androidUseRunningApp":true,"androidDeviceSerial":"16315522500630"},"loggingPrefs":{"browser":"ALL"}}}
[debug] [Chromedriver] Webview version: 'Chrome/55.0.2883.91'
[debug] [WD Proxy] Got response with status 200: {"sessionId":"7aaf6dc008c6015c2451a536bc9afd44","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.28.455520 (cc17746adff54984afff480136733114c6b3704b)"},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":true,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"pageLoadStrategy":"normal","platform":"ANDROID","rotatable":false,"takesHeapSnapshot":true,"takesScreenshot":true,"unexpectedAlertBehaviour":"","version":"55.0.2883.91","webStorageEnabled":true}}
[debug] [Chromedriver] Changed state to 'online'
[Appium] New AndroidDriver session created successfully, session b7849bb0-e2fe-4378-8701-b47d8355c713 added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1557318522799 (14:28:42 GMT+0200 (GMT+02:00))
[debug] [MJSONWP (b7849bb0)] Cached the protocol value 'MJSONWP' for the new session b7849bb0-e2fe-4378-8701-b47d8355c713
[debug] [MJSONWP (b7849bb0)] Responding to client with driver.createSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"automationName":"Appium","autoWebview":true,"deviceReadyTimeout":30000,"androidDeviceReadyTimeout":30000,"browserName":"","platformName":"Android","deviceName":"pixel2xl","app":"/Projects/project/platforms/android/app/build/outputs/apk/debug/app-debug.apk","app-package":"de.ionic.hello","app-activity":"MainActivity","autoAcceptAlerts":true,"autoGrantPermissions":true,"chromedriverExecutable":"e2e/chromedriver.exe","count":1},"automationName":"Appium","autoWebview":true,"deviceReadyTimeout":30000,"androidDeviceReadyTimeout":30000,"browserName":"","platformName":"Android","deviceName":"16315522500630","app":"/Projects/project/platforms/android/app/build/outputs/apk/debug/app-debug.apk","app-package":"de.ionic.hello","app-activity":"MainActivity","autoAcceptAlerts":true,"autoGrantPermis...
[HTTP] <-- POST /wd/hub/session 200 16433 ms - 1480
[HTTP]
[HTTP] --> POST /wd/hub/session/b7849bb0-e2fe-4378-8701-b47d8355c713/timeouts
[HTTP] {"script":11000}
[MJSONWP (b7849bb0)] Driver proxy active, passing request on via HTTP proxy
[debug] [WD Proxy] Matched '/wd/hub/session/b7849bb0-e2fe-4378-8701-b47d8355c713/timeouts' to command name 'timeouts'
[debug] [Protocol Converter] Will send the following request bodies to /timeouts: [{"type":"script","ms":11000}]
[debug] [WD Proxy] Proxying [POST /wd/hub/session/b7849bb0-e2fe-4378-8701-b47d8355c713/timeouts] to [POST http://127.0.0.1:8001/wd/hub/session/7aaf6dc008c6015c2451a536bc9afd44/timeouts] with body: {"type":"script","ms":11000}
[debug] [WD Proxy] Got response with status 200: {"sessionId":"7aaf6dc008c6015c2451a536bc9afd44","status":0,"value":null}
[WD Proxy] Replacing sessionId 7aaf6dc008c6015c2451a536bc9afd44 with b7849bb0-e2fe-4378-8701-b47d8355c713
[HTTP] <-- POST /wd/hub/session/b7849bb0-e2fe-4378-8701-b47d8355c713/timeouts 200 43 ms - 76
[HTTP]
[HTTP] --> DELETE /wd/hub/session/b7849bb0-e2fe-4378-8701-b47d8355c713
[HTTP] {}
[debug] [MJSONWP (b7849bb0)] Calling AppiumDriver.deleteSession() with args: ["b7849bb0-e2fe-4378-8701-b47d8355c713"]
[debug] [BaseDriver] Event 'quitSessionRequested' logged at 1557318523271 (14:28:43 GMT+0200 (GMT+02:00))
[Appium] Removing session b7849bb0-e2fe-4378-8701-b47d8355c713 from our master session list
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Stopping chromedriver for context WEBVIEW_de.ionic.hello
[debug] [Chromedriver] Changed state to 'stopping'
[debug] [WD Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:8001/wd/hub/session/7aaf6dc008c6015c2451a536bc9afd44] with no body
[debug] [WD Proxy] Got response with status 200: "{\"sessionId\":\"7aaf6dc008c6015c2451a536bc9afd44\",\"status\":0,\"value\":null}"
[debug] [Chromedriver] Changed state to 'stopped'
[debug] [ADB] Running 'C:\Users\user\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 16315522500630 shell am force-stop de.ionic.hello'
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Running 'C:\Users\user\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 16315522500630 shell input keyevent 3'
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting IDs of all 'uiautomator' processes
[debug] [ADB] Running 'C:\Users\user\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 16315522500630 shell pgrep -f uiautomator'
[ADB] No 'uiautomator' process has been found
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Running 'C:\Users\user\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 16315522500630 shell am force-stop io.appium.unlock'
[debug] [AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[debug] [BaseDriver] Event 'quitSessionFinished' logged at 1557318525815 (14:28:45 GMT+0200 (GMT+02:00))
[debug] [MJSONWP (b7849bb0)] Received response: null
[debug] [MJSONWP (b7849bb0)] But deleting session, so not returning
[debug] [MJSONWP (b7849bb0)] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/b7849bb0-e2fe-4378-8701-b47d8355c713 200 2546 ms - 76
[HTTP]

我不明白为什么创建会话后的HTTP响应是:[HTTP] --> POST /wd/hub/session/b7849bb0-e2fe-4378-8701-b47d8355c713/timeouts。我希望这只是我错过的设置,但是我尝试在protractor.config.ts文件中尝试各种超时组合,并且仍然会出现此响应。

感谢您的任何建议/帮助!

编辑

我已经将allScriptsTimeout: 600000添加到了protractor.config.ts中的导出配置中,该配置将响应更改为:

[HTTP] --> POST /wd/hub/session/b7849bb0-e2fe-4378-8701-b47d8355c713/timeouts
[HTTP] {"script":600000}

但结果仍然相同。

0 个答案:

没有答案