From d260e47a2387c1ec7dba8be7dad7089320b3c51d Mon Sep 17 00:00:00 2001 From: sebv Date: Wed, 7 May 2014 15:25:23 +0800 Subject: [PATCH] first ci sauce tests --- .travis.yml | 37 +++++++++---- ci/{env => android_env} | 0 ci/before_script_extra.sh | 24 +++++++-- ci/git-config.sh | 9 ++++ ci/git-push.sh | 17 ++++++ ci/install-ant.sh | 9 ---- ci/{ => installers}/install-android.sh | 2 +- ci/installers/install-ant.sh | 8 +++ ci/{ => installers}/install-maven.sh | 4 +- ci/{ => installers}/install-node.sh | 2 +- ci/script.sh | 53 +++++++++++++++---- ci/show-env.sh | 8 --- ci/tools/build-upload-tool.js | 16 ++++++ ci/tools/travis-yml-tool.js | 30 +++++++++++ ci/travis-functional.yml | 23 ++++++++ ci/upload_build_to_sauce.sh | 23 +++++--- package.json | 2 +- reset.sh | 16 +++--- .../android/apidemos/basic-specs.js | 24 ++++----- test/functional/common/setup-base.js | 22 ++++++-- test/functional/ios/testapp/location-specs.js | 3 +- test/functional/selendroid/basic-specs.js | 21 +++++--- test/helpers/env.js | 23 ++++++-- test/helpers/session.js | 25 +++++---- 24 files changed, 306 insertions(+), 95 deletions(-) rename ci/{env => android_env} (100%) create mode 100755 ci/git-config.sh create mode 100755 ci/git-push.sh delete mode 100755 ci/install-ant.sh rename ci/{ => installers}/install-android.sh (98%) create mode 100755 ci/installers/install-ant.sh rename ci/{ => installers}/install-maven.sh (63%) rename ci/{ => installers}/install-node.sh (93%) delete mode 100755 ci/show-env.sh create mode 100644 ci/tools/build-upload-tool.js create mode 100644 ci/tools/travis-yml-tool.js create mode 100644 ci/travis-functional.yml diff --git a/.travis.yml b/.travis.yml index 1a7349622..ce3e822a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,20 +3,39 @@ osx_image: mavericks notifications: email: false rvm: - - 2.1.1 +- 2.1.1 +branches: + only: + - master +git: + submodules: false env: global: - - secure: KNDEn/ryhd0yRGzpJSfHRKBzBIC73RKaHWFDkqD4E+iUXepwBfF2bBfningf8f++9qLNscumYZOHjQ0PWf/YALQCr5B2vHsGN+eHWc331d8f5sU/b6oyCAxsayI32lr/mNVCuHd44+ManMcKUH6831Q1qwa15o5w4dDPtJKuv6Y= - - secure: gZ9B0mE58AYdjVxvj5z27c+0pNJqrRzJiXdSe8T0UswR3gFxhOYoW1ikFTcij1NcQhdzDwGIDDJl30D6Z69Y73W3wagowkELasPeNcKobWqerof5lG8A6Qud90jXedABdXw9FEGnY47mG3/ZWwyx1KyOVkIlxoabkCqUwd7xaio= + - SAUCE_REST_ROOT=https://saucelabs.com/rest/v1 + - APPIUM_HOST='ondemand.saucelabs.com' + - APPIUM_PORT=80 + - SAUCE_USERNAME=appium + - secure: GXGFbQptLEsKlaWnpOL2EB9hqQ4XBT6tqg7REt5j1h1jYBsfHQHSgSLt1jpzOF5kooXVbw2K7IrZyNVBXEUHR00Hp6O72FBOd+SSj8uPCJBLjAOaJWs0ZtujqGHwHpe6gadFfn0L7q0ffoV5OJVeNHHcuw4f9BaA78fTFNfm1jE= + - secure: WLRP9RJIHWPer189swCqMCnexS8XpVQ8FRMSXNxLXp5fUaERVzU7/ncGFeqcM8GWGIU12PP8TJUaMRa58vTGgApW6POMdAPiauepfzoru+n/S4Xrw64hmd4oK0GEZI3wgnkPofUn6TzQeXRmVG496PNzbV8KfqF4mTAesZOLSFA= matrix: - CI_CONFIG=unit - - CI_CONFIG=build + - CI_CONFIG=build_ios + - CI_CONFIG=build_android + - CI_CONFIG=build_selendroid + - CI_CONFIG=build_gappium before_script: - gem install --no-rdoc --no-ri appium_doc_lint -- ./ci/install-node.sh -- ./ci/show-env.sh -- npm install -g jshint grunt-cli +- "./ci/git-config.sh" +- "./ci/installers/install-node.sh" +- "echo Node.js version: `node -v`" +- npm install -g jshint grunt-cli mocha - npm install -- ./ci/before_script_extra.sh +- "./ci/before_script_extra.sh" script: -- ./ci/script.sh \ No newline at end of file +- "./ci/script.sh" + + + + + + diff --git a/ci/env b/ci/android_env similarity index 100% rename from ci/env rename to ci/android_env diff --git a/ci/before_script_extra.sh b/ci/before_script_extra.sh index 2e8a9541d..38a08ff2d 100755 --- a/ci/before_script_extra.sh +++ b/ci/before_script_extra.sh @@ -1,9 +1,23 @@ #!/bin/bash -set +e -if [[ $CI_CONFIG == 'build' ]]; then - ./ci/install-ant.sh - ./ci/install-maven.sh - ./ci/install-android.sh +set -e +if [[ $CI_CONFIG == 'build_ios' ]]; then + ./ci/installers/install-ant.sh + ./ci/installers/install-maven.sh + sudo grunt authorize +elif [[ $CI_CONFIG == 'build_android' ]]; then + ./ci/installers/install-ant.sh + ./ci/installers/install-maven.sh + ./ci/installers/install-android.sh + sudo grunt authorize +elif [[ $CI_CONFIG == 'build_selendroid' ]]; then + ./ci/installers/install-ant.sh + ./ci/installers/install-maven.sh + ./ci/installers/install-android.sh + sudo grunt authorize +elif [[ $CI_CONFIG == 'build_gappium' ]]; then + ./ci/installers/install-ant.sh + ./ci/installers/install-maven.sh + ./ci/installers/install-android.sh npm install -g cordova sudo grunt authorize fi diff --git a/ci/git-config.sh b/ci/git-config.sh new file mode 100755 index 000000000..8929175e8 --- /dev/null +++ b/ci/git-config.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +git config --global user.email "appium-ci@appium.io" +git config --global user.name "appium-ci" +PUSH_URL=$(git config --get remote.origin.url | sed s/git:/https:/) +echo "https://${GH_TOKEN}:@github.com" > ${HOME}/.git-credentials +git config credential.helper "store --file=${HOME}/.git-credentials" +git remote set-url --push origin ${PUSH_URL} +git config --global push.default simple diff --git a/ci/git-push.sh b/ci/git-push.sh new file mode 100755 index 000000000..ef2c7ffef --- /dev/null +++ b/ci/git-push.sh @@ -0,0 +1,17 @@ +#!/bin/sh +set -e + +CI_BRANCH=ci-${BRANCH_CAT}-${TRAVIS_BRANCH} +UPLOAD_INFO_FILE=ci/build-upload-info.json + + +# preparing test branch +git branch -f ${CI_BRANCH} +git checkout ${CI_BRANCH} +cp .travis.yml .travis.yml.master +node ci/tools/travis-yml-tool.js .travis.yml.master ci/travis-functional.yml > .travis.yml +git add ${UPLOAD_INFO_FILE} +git commit -a -m "ci ${BRANCH_CAT} branch for build #${TRAVIS_JOB_NUMBER}" + +# pushing +git push -f origin ${CI_BRANCH}:${CI_BRANCH} diff --git a/ci/install-ant.sh b/ci/install-ant.sh deleted file mode 100755 index a473a0423..000000000 --- a/ci/install-ant.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set +e - -mkdir -p $HOME/tools/ant -cd $HOME/tools/ant -wget -P /tmp http://ftp.tc.edu.tw/pub/Apache/ant/binaries/apache-ant-1.9.3-bin.tar.gz -tar xzf /tmp/apache-ant-1.9.3-bin.tar.gz -echo 'export PATH=$HOME/tools/ant/apache-ant-1.9.3/bin:$PATH' > $HOME/tools/ant/env - diff --git a/ci/install-android.sh b/ci/installers/install-android.sh similarity index 98% rename from ci/install-android.sh rename to ci/installers/install-android.sh index 9f368cccb..0dccdfe8d 100755 --- a/ci/install-android.sh +++ b/ci/installers/install-android.sh @@ -1,5 +1,5 @@ #!/bin/bash -set +e +set -e COMPONENTS=build-tools-19.0.3,android-19,android-18,android-16,extra-android-support diff --git a/ci/installers/install-ant.sh b/ci/installers/install-ant.sh new file mode 100755 index 000000000..6b25880c7 --- /dev/null +++ b/ci/installers/install-ant.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +mkdir -p $HOME/tools/ant +cd $HOME/tools/ant +wget -P /tmp http://www.us.apache.org/dist/ant/binaries/apache-ant-1.9.4-bin.tar.gz +tar xzf /tmp/apache-ant-1.9.4-bin.tar.gz +echo 'export PATH=$HOME/tools/ant/apache-ant-1.9.4/bin:$PATH' > $HOME/tools/ant/env diff --git a/ci/install-maven.sh b/ci/installers/install-maven.sh similarity index 63% rename from ci/install-maven.sh rename to ci/installers/install-maven.sh index 8578d6bdc..4f063f478 100755 --- a/ci/install-maven.sh +++ b/ci/installers/install-maven.sh @@ -1,8 +1,8 @@ #!/bin/bash -set +e +set -e mkdir -p $HOME/tools/maven cd $HOME/tools/maven -wget -P /tmp http://apache.cdpa.nsysu.edu.tw/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz +wget -P /tmp http://www.us.apache.org/dist/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz tar xzf /tmp/apache-maven-3.1.1-bin.tar.gz echo 'export PATH=$HOME/tools/maven/apache-maven-3.1.1/bin:$PATH' > $HOME/tools/maven/env diff --git a/ci/install-node.sh b/ci/installers/install-node.sh similarity index 93% rename from ci/install-node.sh rename to ci/installers/install-node.sh index 5db975b39..b71ad0008 100755 --- a/ci/install-node.sh +++ b/ci/installers/install-node.sh @@ -1,5 +1,5 @@ #!/bin/bash -set +e +set -e git clone https://github.com/visionmedia/n.git /tmp/n cd /tmp/n make install diff --git a/ci/script.sh b/ci/script.sh index e526a4699..14ab68a07 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -1,17 +1,50 @@ #!/bin/bash -set +e - -unset SUDO_UID - -source ./ci/env -./ci/show-env.sh +set -e if [[ $CI_CONFIG == 'unit' ]]; then cd docs appium_doc_lint || exit 1 cd - npm test -elif [[ $CI_CONFIG == 'build' ]]; then - ./reset.sh --hardcore --dev --ios --android --selendroid --gappium --verbose - ./ci/upload_build_to_sauce.sh -fi \ No newline at end of file +elif [[ $CI_CONFIG == 'build_ios' ]]; then + unset SUDO_UID + echo OS X version: `sw_vers -productVersion` + echo Xcode version: `xcodebuild build -version` + echo Xcode path: `xcode-select --print-path` + ./reset.sh --hardcore --no-npmlink --dev --ios --verbose + ./ci/upload_build_to_sauce.sh + BRANCH_CAT=ios ./ci/git-push.sh +elif [[ $CI_CONFIG == 'build_android' ]]; then + source ./ci/android_env + echo JAVA_HOME: $JAVA_HOME + ./reset.sh --hardcore --no-npmlink --dev --android --verbose + #./ci/upload_build_to_sauce.sh + #BRANCH_CAT=android ./ci/git-push.sh +elif [[ $CI_CONFIG == 'build_selendroid' ]]; then + source ./ci/android_env + echo JAVA_HOME: $JAVA_HOME + ./reset.sh --hardcore --no-npmlink --dev --selendroid + #./ci/upload_build_to_sauce.sh + #BRANCH_CAT=selendroid ./ci/git-push.sh +elif [[ $CI_CONFIG == 'build_gappium' ]]; then + source ./ci/android_env + echo OS X version: `sw_vers -productVersion` + echo Xcode version: `xcodebuild build -version` + echo Xcode path: `xcode-select --print-path` + echo JAVA_HOME: $JAVA_HOME + ./reset.sh --hardcore --no-npmlink --dev --gappium + #./ci/upload_build_to_sauce.sh + #BRANCH_CAT=gappium ./ci/git-push.sh +elif [[ $CI_CONFIG == 'functional' ]]; then + TARBALL=sauce-storage:$(node ./ci/tools/build-upload-tool.js \ + ./ci/build-upload-info.json filename) + SAUCE=1 \ + VERBOSE=1 \ + TARBALL="${TARBALL}" \ + DEVICE="ios71" \ + VERSION="7.1" \ + ./node_modules/.bin/mocha \ + --recursive \ + -g "@skip-ios71|@skip-ios7|@skip-ios-all" -i \ + $MOCHA_FILES +fi diff --git a/ci/show-env.sh b/ci/show-env.sh deleted file mode 100755 index 1672512cd..000000000 --- a/ci/show-env.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set +e -echo OS X version: `sw_vers -productVersion` -echo Xcode version: `xcodebuild build -version` -echo Xcode path: `xcode-select --print-path` -echo Node.js version: `node -v` -echo JAVA_HOME: $JAVA_HOME - diff --git a/ci/tools/build-upload-tool.js b/ci/tools/build-upload-tool.js new file mode 100644 index 000000000..ac9106e84 --- /dev/null +++ b/ci/tools/build-upload-tool.js @@ -0,0 +1,16 @@ +'use strict'; + +var args = process.argv.slice(2), + assert = require('assert'); + +var fs = require("fs"); +var data = JSON.parse(fs.readFileSync(args[0])); +assert(data.filename); + +switch (args[1]) { + case 'filename': + console.log(data.filename); + break; + default: + console.log(data); +} diff --git a/ci/tools/travis-yml-tool.js b/ci/tools/travis-yml-tool.js new file mode 100644 index 000000000..7133c7b85 --- /dev/null +++ b/ci/tools/travis-yml-tool.js @@ -0,0 +1,30 @@ +'use strict'; + +var args = process.argv.slice(2), + assert = require('assert'), + _ = require('underscore'); + +var fs = require("fs"); +var source = fs.readFileSync(args[0], 'UTF8'); +var target = fs.readFileSync(args[1], 'UTF8'); + +// replace secure lines +var secureLines = source.match(/^\s*- secure.*/gm).join('\n'); +secureLines = secureLines.replace(/^\s*-/mg, ' -'); +assert(secureLines); +target = target.replace(/(^\s*- secure.*\r?\n)+/m, ' # \n'); +target = target.replace(/^ # .*$/m, secureLines); + +_([ + 'SAUCE_REST_ROOT', 'APPIUM_HOST', + 'APPIUM_PORT', 'SAUCE_USERNAME', +]).each(function(varName) { + var regex = new RegExp('- ' + varName + '=.*'); + var line = source.match(regex)[0]; + regex = new RegExp('- ' + varName + '=.*','g'); + target = target.replace(regex, line); +}); +console.log(target); + + + diff --git a/ci/travis-functional.yml b/ci/travis-functional.yml new file mode 100644 index 000000000..7e51c532c --- /dev/null +++ b/ci/travis-functional.yml @@ -0,0 +1,23 @@ +language: node_js +node_js: +- '0.10' +notifications: + email: false +git: + submodules: false +branches: + only: + - /^ci-.*$/ +env: + global: + - CI_CONFIG=functional + - SAUCE_REST_ROOT=auto + - APPIUM_HOST=auto + - APPIUM_PORT=auto + - SAUCE_USERNAME=auto + # + matrix: + - MOCHA_FILES=test/functional/ios/testapp/find-element-specs.js + - MOCHA_FILES=test/functional/ios/testapp/get-attribute-specs.js +script: +- "./ci/script.sh" diff --git a/ci/upload_build_to_sauce.sh b/ci/upload_build_to_sauce.sh index 09afaad0a..8b22a832e 100755 --- a/ci/upload_build_to_sauce.sh +++ b/ci/upload_build_to_sauce.sh @@ -1,11 +1,22 @@ #!/bin/sh -GIT_COMMIT=git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/\1/" -tar cfj - --exclude=node_modules --exclude=submodules . | \ +set -e + +BZ2_FILE=appium-ci-${TRAVIS_BRANCH}-${TRAVIS_JOB_NUMBER}-${TRAVIS_COMMIT:0:10}.tar.bz2 +UPLOAD_INFO_FILE=ci/build-upload-info.json + +# zipping/uploading +tar \ + cfj - \ + --exclude=.git \ + --exclude=submodules . | \ curl \ - --verbose \ + -k \ --progress-bar \ -u $SAUCE_USERNAME:$SAUCE_ACCESS_KEY \ - -X POST "https://saucelabs.com/rest/v1/storage/${SAUCE_USERNAME}/appium-dev-${GIT_COMMIT}.bjz?overwrite=true" \ + -X POST "${SAUCE_REST_ROOT}/storage/${SAUCE_USERNAME}/${BZ2_FILE}?overwrite=true" \ -H "Content-Type: application/octet-stream" \ - --data-binary @- > /tmp/curl.out -cat /tmp/curl.out + --data-binary @- \ + -o $UPLOAD_INFO_FILE + +# checking/printing result file +node ci/tools/build-upload-tool.js $UPLOAD_INFO_FILE diff --git a/package.json b/package.json index 53adaff22..4056500c5 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "devDependencies": { "mocha": "~1.18.2", "underscore-cli": "~0.2.17", - "wd": "~0.2.18", + "wd": "0.2.21", "yiewd": "~0.4.4", "monocle-js": "~0.6.1", "assert": "~1.1.1", diff --git a/reset.sh b/reset.sh index b2e31be7a..6553e7ee2 100755 --- a/reset.sh +++ b/reset.sh @@ -25,6 +25,7 @@ grunt="$(npm bin)/grunt" # might not have grunt-cli installed with -g verbose=false chromedriver_version=false chromedriver_install_all=false +npmlink=true if test -d .git ; then is_git_checkout=true else @@ -50,6 +51,7 @@ do "--chromedriver-version") chromedriver_version=$2;; "--chromedriver-install-all") chromedriver_install_all=true;; "--udid") udid=$2;; + "--no-npmlink") npmlink=false;; esac if [[ -n "$2" ]] && [[ "$2" != --* ]]; then @@ -178,12 +180,14 @@ reset_ios() { build/WebViewApp/ fi if $include_dev ; then - echo "* Cloning/npm linking appium-atoms" - run_cmd ./bin/npmlink.sh -l appium-atoms - echo "* Cloning/npm linking appium-instruments" - run_cmd ./bin/npmlink.sh -l appium-instruments - echo "* Cloning/npm linking appium-uiauto" - run_cmd ./bin/npmlink.sh -l appium-uiauto + if $npmlink ; then + echo "* Cloning/npm linking appium-atoms" + run_cmd ./bin/npmlink.sh -l appium-atoms + echo "* Cloning/npm linking appium-instruments" + run_cmd ./bin/npmlink.sh -l appium-instruments + echo "* Cloning/npm linking appium-uiauto" + run_cmd ./bin/npmlink.sh -l appium-uiauto + fi if $ios7_active ; then if $hardcore ; then echo "* Clearing out old UICatalog download" diff --git a/test/functional/android/apidemos/basic-specs.js b/test/functional/android/apidemos/basic-specs.js index 4d1f91ec3..6dff9ba0c 100644 --- a/test/functional/android/apidemos/basic-specs.js +++ b/test/functional/android/apidemos/basic-specs.js @@ -128,19 +128,19 @@ describe("apidemo - basic -", function () { describe('activity style: no period', function () { var session; - after(function () { session.tearDown(); }); + after(function () { session.tearDown(this.currentTest.state === 'passed'); }); it('should still find activity', function (done) { session = initSession(_.defaults({appActivity: 'ApiDemos'}, desired)); - session.setUp().nodeify(done); + session.setUp(this.parent.title + " " + this.title).nodeify(done); }); }); describe('activity style: fully qualified', function () { var session; - after(function () { session.tearDown(); }); + after(function () { session.tearDown(this.currentTest.state === 'passed'); }); it('should still find activity', function (done) { session = initSession(_.defaults({appActivity: 'com.example.android.apis.ApiDemos'}, desired)); - session.setUp().nodeify(done); + session.setUp(this.parent.title + " " + this.title).nodeify(done); }); }); @@ -149,11 +149,11 @@ describe("apidemo - basic -", function () { describe('activity style: non-existent', function () { var session; - after(function () { session.tearDown(); }); + after(function () { session.tearDown(this.currentTest.state === 'passed'); }); it('should throw an error', function (done) { session = initSession(_.defaults({appActivity: '.Blargimarg'}, desired), opts); try3Times(function () { - return session.setUp() + return session.setUp(this.parent.title + " " + this.title) .catch(function (err) { throw err.data; }) .should.be.rejectedWith(/Activity used to start app doesn't exist/); }).nodeify(done); @@ -162,12 +162,12 @@ describe("apidemo - basic -", function () { describe('bad app path', function () { var session; - after(function () { session.tearDown(); }); + after(function () { session.tearDown(this.currentTest.state === 'passed'); }); it('should throw an error', function (done) { var badAppPath = path.resolve(__dirname, "../../../sample-code/apps/ApiDemos/bin/ApiDemos-debugz.apk"); session = initSession(_.defaults({'app': badAppPath}, desired), opts); try3Times(function () { - return session.setUp() + return session.setUp(this.parent.title + " " + this.title) .catch(function (err) { throw err.data; }) .should.be.rejectedWith(/Error locating the app/); }).nodeify(done); @@ -217,24 +217,24 @@ describe("apidemo - basic -", function () { }); } - afterEach(function () { session.tearDown(); }); + afterEach(function () { session.tearDown(this.currentTest.state === 'passed'); }); it('should load an app with using absolute path', function (done) { var appPath = path.resolve(desired.app); session = initSession(_.defaults({'app': appPath}, desired)); - session.setUp().nodeify(done); + session.setUp(this.parent.title + " " + this.title).nodeify(done); }); it('should load an app with using relative path', function (done) { var appPath = path.relative(process.cwd(), desired.app); session = initSession(_.defaults({'app': appPath}, desired)); - session.setUp().nodeify(done); + session.setUp(this.parent.title + " " + this.title).nodeify(done); }); it('should load a zipped app via url', function (done) { var appUrl = 'http://appium.s3.amazonaws.com/ApiDemos-debug.apk'; session = initSession(_.defaults({'app': appUrl}, desired)); - session.setUp().nodeify(done); + session.setUp(this.parent.title + " " + this.title).nodeify(done); }); }); diff --git a/test/functional/common/setup-base.js b/test/functional/common/setup-base.js index edc5e22f3..dd9baef1c 100644 --- a/test/functional/common/setup-base.js +++ b/test/functional/common/setup-base.js @@ -16,11 +16,25 @@ module.exports = function (context, desired, opts) { var session = initSession(desired, opts); if (env.FAST_TESTS) { - before(function (done) { session.setUp().nodeify(done); }); - after(function (done) { session.tearDown().nodeify(done); }); + var allPassed = true; + before(function (done) { + session + .setUp(context.title) + .nodeify(done); + }); + after(function (done) { session.tearDown(allPassed).nodeify(done); }); + afterEach(function () { + allPassed = allPassed && this.currentTest.state === 'passed'; + }); } else { - beforeEach(function (done) { session.setUp().nodeify(done); }); - afterEach(function (done) { session.tearDown().nodeify(done); }); + beforeEach(function (done) { + session + .setUp(this.currentTest.parent.title + " " + this.currentTest.title) + .nodeify(done); + }); + afterEach(function (done) { + session.tearDown(this.currentTest.state === 'passed').nodeify(done); + }); } return session.promisedBrowser; diff --git a/test/functional/ios/testapp/location-specs.js b/test/functional/ios/testapp/location-specs.js index cd6ba8541..43a3820f0 100644 --- a/test/functional/ios/testapp/location-specs.js +++ b/test/functional/ios/testapp/location-specs.js @@ -59,7 +59,8 @@ describe('testapp - location services -', function () { locationServicesAuthorized: true }); it('should not work without bundleId', function (done) { - initSession(newDesired, {'no-retry': true, 'no-reset': true}).setUp() + initSession(newDesired, {'no-retry': true, 'no-reset': true}) + .setUp(this.parent.title + " " + this.title) .then(function (err) { err.cause.value.message.should.contain("bundleId"); throw err; diff --git a/test/functional/selendroid/basic-specs.js b/test/functional/selendroid/basic-specs.js index 0c8e2f981..90bf87292 100644 --- a/test/functional/selendroid/basic-specs.js +++ b/test/functional/selendroid/basic-specs.js @@ -2,6 +2,7 @@ process.env.DEVICE = process.env.DEVICE || "selendroid"; var setup = require("../common/setup-base") + , env = require('../../../helpers/env') , initSession = require('../../helpers/session').initSession , path = require('path') , Q = require("q") @@ -131,11 +132,15 @@ describe('selendroid - basic -', function () { describe('app activities with no dot', function () { var session; - after(function () { session.tearDown(); }); + after(function () { session.tearDown(this.currentTest.state === 'passed'); }); it('should not launch app', function (done) { - session = initSession(_.defaults({appActivity: 'ApiDemos'}, desired), {'no-retry': true}); - session.setUp() + var newDesired = _.defaults({'app-activity': 'ApiDemos'}, desired); + if (env.SAUCE) { + newDesired.name = this.currentTest.parent.title + " " + this.currentTest.title; + } + session = initSession(newDesired, {'no-retry': true}); + session.setUp(this.parent.title + " " + this.title) .should.be.rejected .nodeify(done); }); @@ -144,11 +149,15 @@ describe('selendroid - basic -', function () { describe('fully qualified app activities', function () { var session; - after(function () { session.tearDown(); }); + after(function () { session.tearDown(this.currentTest.state === 'passed'); }); it('should still launch app', function (done) { - session = initSession(_.defaults({appActivity: 'com.example.android.apis.ApiDemos'}, desired)); - session.setUp() + var newDesired = _.defaults({'app-activity': 'com.example.android.apis.ApiDemos'}, desired); + if (env.SAUCE) { + newDesired.name = this.currentTest.parent.title + " " + this.currentTest.title; + } + session = initSession(newDesired); + session.setUp(this.parent.title + " " + this.title) .nodeify(done); }); }); diff --git a/test/helpers/env.js b/test/helpers/env.js index 4518aecc7..c471ea4ee 100644 --- a/test/helpers/env.js +++ b/test/helpers/env.js @@ -19,6 +19,7 @@ if (env.SAUCE) { } env.APPIUM_USERNAME = process.env.SAUCE_USERNAME; env.APPIUM_PASSWORD = process.env.SAUCE_ACCESS_KEY; + env.SAUCE_REST_ROOT = process.env.SAUCE_REST_ROOT; } env.LAUNCH_TIMEOUT = JSON.parse(process.env.LAUNCH_TIMEOUT || 60000); @@ -40,9 +41,10 @@ function iphoneOrIpadSimulator(device, version) { switch (version) { case '6.1': case '7.0': - return isIpad ? 'iPad Simulator' : 'iPhone Simulator'; case '7.1': - return isIpad ? 'iPad Retina' : 'iPhone Retina 4-inch'; + return isIpad ? 'iPad Simulator' : 'iPhone Simulator'; + // case '7.1': + // return isIpad ? 'iPad Retina' : 'iPhone Retina 4-inch'; default: throw new Error("invalid version"); } @@ -141,7 +143,22 @@ if (env.VERSION) { env.CAPS.platformVersion = "7.0"; } -// app path root +// max retry +if (process.env.MAX_RETRY) env.MAX_RETRY = parseInt(process.env.MAX_RETRY, 10); + +//dev tarball +env.TARBALL = process.env.TARBALL; + +// add the tarball to caps +if (env.SAUCE && env.TARBALL) { + env.CAPS['appium-version'] = { + 'appium-url': env.TARBALL, + //'npm-install': true, + 'download-app': false, + 'appium-startup-args': 'minimal' + //'appium-startup-args': '-m' + }; +} // rest enf points env.TEST_END_POINT = 'http://localhost:' + env.APPIUM_PORT + '/test/'; diff --git a/test/helpers/session.js b/test/helpers/session.js index 7d5f2e5f4..9fbf4625a 100644 --- a/test/helpers/session.js +++ b/test/helpers/session.js @@ -38,8 +38,13 @@ module.exports.initSession = function (desired, opts) { }); return { - setUp: function () { + setUp: function (name) { + if (env.VERBOSE) { + console.log("env.APPIUM_HOST -->", env.APPIUM_HOST); + console.log("env.APPIUM_PORT -->", env.APPIUM_PORT); + } browser = wd.promiseChainRemote(env.APPIUM_HOST, env.APPIUM_PORT, env.APPIUM_USERNAME, env.APPIUM_PASSWORD); + if(env.SAUCE_REST_ROOT) browser.sauceRestRoot = env.SAUCE_REST_ROOT; if (env.VERBOSE) { var MAX_DATA_LENGTH = 500; browser.on('status', function (info) { @@ -54,13 +59,14 @@ module.exports.initSession = function (desired, opts) { } deferred.resolve(browser); var caps = _.defaults(desired, env.CAPS); - if (env.SAUCE) { - caps.name = this.currentTest.parent.title + " " + this.currentTest.title; - } if (env.VERBOSE) console.log("caps -->", caps); if (env.VERBOSE) console.log("opts -->", opts); - + + if (env.SAUCE) { + desired.name = name; + } + function init(remainingAttempts) { if (env.VERBOSE) console.log("remainingAttempts -->", remainingAttempts); return browser @@ -77,6 +83,7 @@ module.exports.initSession = function (desired, opts) { }); } var attempts = opts['no-retry'] ? 1 : 3; + if (env.MAX_RETRY) attempts = Math.min(env.MAX_RETRY, attempts); return browser.chain() .then(function () { if (env.IOS && env.RESET_IOS && !opts['no-reset']) { @@ -91,11 +98,7 @@ module.exports.initSession = function (desired, opts) { .then(function () { initialized = true; }) .setImplicitWaitTimeout(5000); }, - tearDown: function () { - var passed = false; - if (this.currentTest) { - passed = this.currentTest.state = 'passed'; - } + tearDown: function (passed) { return browser.chain() .then(function () { if (initialized && !opts['no-quit']) { @@ -108,7 +111,7 @@ module.exports.initSession = function (desired, opts) { }).then(function () { if (env.SAUCE) return browser.sauceJobStatus(passed); }) - .catch(function () { console.warn("didn't manange to set sauce status."); }) + .catch(function (err) { console.warn("didn't manange to set sauce status. error:", err); }) .sleep(2000); }, promisedBrowser: deferred.promise