LoginSignup
1
2

More than 5 years have passed since last update.

appium

Last updated at Posted at 2018-12-16

目的

WebViewのテストにcalabash iosを導入していたが、これがXcode9以降全く動かなくなったので
諦めて、appiumへ切り替え
* calabash側に聞いたら、rubyのバージョン下げて、って言われて、下げたけど、改善しなかったので、
変わんないよ、って伝えて、諦めた。

使い所

iOSとAndroidアプリのUIテストに使えて、さらにモバイルwebのテストにも使用できるっぽい。
かなり応用が効くと思われる。
*情報を確認しただけで、ちゃんと調べてはいないが、実機でも動作するようです。
当初2017年に調べてたときより大分進化した印象。

インストール

こちらを参考
https://pepese.github.io/blog/appium-basics/

まずは

画面にどういった要素があって、どこをどう動かしたら、画面遷移するのかとかをチェックする必要がある。
そのために、インスペクタを使う。

inspector

viewの要素がなんなのか、チェックするのに使用。
まずは、どういった要素があるかわからないと、UIテストが作れないため。
こちらを参考に
https://qiita.com/Real_analysis/items/4fe0e887833a260eb9b9
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

DesiredCapabilities

どのアプリをinspectorでチェックするかに使用する。
実際テストコードを書く際にも以下を使用する。

{
"platformName": "iOS",
"platformVersion": "11.4",
"deviceName": "iPhone 7",
"automationName": "XCUITest",
"app": "/xxxxx/xxxxxxxxxxxxx/Library/Developer/Xcode/DerivedData/xxxxxxxxxxxxx_customer-hkghxobmuiiemtfdclimixtjjrkw/Build/Products/Debug-iphonesimulator/xxxxxxxxxxxxx_customer.app"
}

こんな感じ。各アプリ、テストしたい端末に応じて、値を調節してやればいい。

Test

sample-codeを参考に動かせば良さげ
https://qiita.com/tabbyz/items/187ef263b6ac3ba7b3bd

どの言語でテストコード書く?

phpunit。社内がphpメインのため

注意点

phpunit-seleniumとappiumのPGが合わないところがある。
githubで質問し、議論した結果
https://github.com/appium/php-client/pull/47

composer.jsonを以下のすることで落ち着いた。

➜ cat composer.json
{
  "name": "ios_unittest_appium",
  "repositories": [
      {
          "type": "vcs",
          "url": "https://github.com/appium/php-client"
      }
  ],
  "require": {
      "appium/php-client": "dev-master"
  },
  "require-dev": {
        "phpunit/phpunit-selenium": "dev-master#6cd8b2acadd13d3f16b0e8cc41f8bbf50f4d1dec"
  }
}

サンプルで実行したコマンド

あるアプリで動かそうとトライしている。多分できそう。

ios_unittest_appium on  master [!] via 🐘 v7.2.9
➜ vendor/phpunit/phpunit/phpunit test/basic/xxxxxxxxxxxxx_xxxxxxxxxxxxxschool_ios_test.php

アプリを引数で渡す。

アプリのパスは作成者によって違うので、開発時は、コマンドライン引数で渡すようにしたほうが良い。
PGを変更して、以下で実行できるようにした。

vendor/phpunit/phpunit/phpunit test/basic/xxxxxxxxxxxxxaaaaersityAppTest.php app="アプリのパス" device="iPhone 7" version="11.4"

app,device,versionパラメータがないと、動かないようになってるので、注意。
パラメータの順番は変えても動くはずです。

webviewを操作していて、現在のURLを取得したい場合

社内環境か、どうか確認しないと、事故になるため。

$aryContext = $this->contexts();

// 2番目のindexがwebのコンテキストになってる
        $this->context($aryContext[1]);

        echo "WEBURL:".$this->url()."\n";
array(2) {
  [0]=>
  string(10) "NATIVE_APP"
  [1]=>
  string(15) "WEBVIEW_79437.1"
}

注意点として、終わったあと、NATIVE_APPに戻さないと、以降の操作ができなくなる。

参考

http://appium.io/docs/en/commands/context/get-contexts/
https://www.packtpub.com/mapt/book/application_development/9781787280168/11/ch11lvl1sec45/switching-between-views---web-and-native

さらに、URLを変えたい場合

このメソッド

echo "WEBURL:".$this->url()."\n";

docを見ると

* @method void|string url() url($url = NULL)

これURL変えられるんじゃね?

試してみた

// 実験
        $this->url("https://xxxxxxxxxxxxx.jp");

見事変わりました。

注意点

sleepを長めに噛まさないと、変わる前に、別の操作が動いてしまう。

appiumをコマンドで起動

jenkinsで動かしたいときに必要になってくる

/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone
`

これでもおけ

/xxxxx/xxxxxxxxxxxxx/.nvm/versions/node/v10.12.0/bin/node /Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone

headlessモード

以下オプションを付けると、headless、つけないと、no-headlessモード

isHeadless="true"

例:

vendor/phpunit/phpunit/phpunit test/basic/xxxxxxxxxxxxxaaaaersityAppTest.php app="/xxxxx/xxxxxxxxxxxxx/Library/Developer/Xcode/DerivedData/xxxxxxxxxxxxxaaaaersityForiOS-csvlqndgfufymzfomxrwdrtwpalv/Build/Products/Debug-iphonesimulator/xxxxxxxxxxxxx.app" device="iPhone 7" version="11.4" isHeadless="true"

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2