项目作者: el-cms

项目描述 :
An example of Appium integration in a Nativescript-vue project
高级语言: JavaScript
项目地址: git://github.com/el-cms/nativescript-vue-appium-example.git
创建时间: 2018-09-25T21:53:25Z
项目社区:https://github.com/el-cms/nativescript-vue-appium-example

开源协议:MIT License

下载


Nativescript-vue + Appium: configuration example

An example of Appium integration in a Nativescript-vue project, based
on the work of @SvetoslavTsenov on
his PR
on nativescript-vue-ui-tests.

NOTE: This has not been tested on iOS, so feel free to complete the
guide with your feedback. Also, it’s possible (probable) that I get some
things wrong in my understanding of the whole thing.

Pre-requisites

Your system should be configured to run nativescript apps in an Android emulator. But if you’re here,
that’s probably already good.

Environment

I successfully managed to have this running with:

  • node 8.11.3
  • tns 4.2.4
  • nativescript-vue 2.0.0
  • appium 1.9.1 (installed globally): npm install -g appium
  • nativescript-dev-appium 4.0.8: npm install -D nativescript-dev-appium

Configuration files:

  1. e2e
  2. ├── config
  3. ├── appium.capabilities.json // Appium targets configurations (devices)
  4. └── mocha.opts // Mocha configuration
  5. ├── resources // Empty folder, I guess it should contain files used during tests
  6. ├── sample.tests.js // The actual tests
  7. └── setup.js // Additional testing configuration

appium.capabilities.json

It’s a file you’ll have to edit to fit your current setup. There are 3 sections
in it for now:

  1. {
  2. // This is a configuration section, you have to reference it when you
  3. // run the suites: it tells Appium how the target is configured
  4. "android19": {
  5. "platformName": "Android",
  6. // This is important, it's the android version (not the API version)
  7. "platformVersion": "4.4",
  8. // This is the name of the virtual device, adapt it
  9. "deviceName": "Nexus_5X_API_19_x86",
  10. "noReset": false,
  11. // You should change this value to match the one in package.json
  12. // and app.gradle
  13. "appPackage": "org.nativescript.application",
  14. // I guess this is the main activity to open when launching the app
  15. "appActivity": "com.tns.NativeScriptActivity",
  16. // path to the apk to test. Leave it blank and appium will select
  17. // the first it finds.
  18. "app": ""
  19. },
  20. "ios-simulator103iPhone6": {
  21. "platformName": "iOS",
  22. "platformVersion": "10.3",
  23. "deviceName": "iPhone Simulator",
  24. "bundleId": "org.nativescript.application",
  25. "app": ""
  26. },
  27. "sim.iPhone8.iOS11.3": {
  28. "platformName": "iOS",
  29. "platformVersion": "11.3",
  30. "deviceName": "iPhone 8",
  31. "appiumVersion": "1.8.1",
  32. "bundleId": "org.nativescript.application",
  33. "noReset": true,
  34. "fullReset": false,
  35. "app": ""
  36. }
  37. }

setup.js

This file contains two additional hooks to launch and stop Appium when
the test suite is launched. I had to use them, but it may be unnecessary
for some of you (feedback on this would be great)

Npm scripts

A few scripts are created in package.json to launch the suites:

  • build.android: shortcut for tns build android --bundle
  • build.ios: shortcut for tns build ios --bundle
  • e2e: This one fails when launched alone, but is used as a shortcut
    in the last two.
  • e2e.<variants>: Runs the tests on a freshly built apk

If you look at the e2e scripts, you’ll notice they use the different
configuration sections declared in appium.capabilities.json

If you have several devices to test your app, you may create one new
script per configuration, or do something clever with parameters…

Usage

  1. # Install dependencies
  2. npm install
  3. # Build an apk for production
  4. tns build <platform> --bundle
  5. # Or, with the shortcuts in package.json:
  6. npm run build.<platform>
  7. # Test the built file
  8. # Your emulator/device should be accessible/running.
  9. # Variant can be "android" and "ios" in ths example
  10. npm run e2e.<variant>
  11. # Build, watch for changes and run the application
  12. tns run <platform> --bundle