Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 42DB6200B35 for ; Tue, 5 Jul 2016 09:22:54 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 41534160A60; Tue, 5 Jul 2016 07:22:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6358F160A4F for ; Tue, 5 Jul 2016 09:22:53 +0200 (CEST) Received: (qmail 37460 invoked by uid 500); 5 Jul 2016 07:22:52 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 37444 invoked by uid 99); 5 Jul 2016 07:22:52 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jul 2016 07:22:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 186AFEAD93; Tue, 5 Jul 2016 07:22:52 +0000 (UTC) From: vladimir-kotikov To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-paramedic pull request #11: Appium tests Content-Type: text/plain Message-Id: <20160705072252.186AFEAD93@git1-us-west.apache.org> Date: Tue, 5 Jul 2016 07:22:52 +0000 (UTC) archived-at: Tue, 05 Jul 2016 07:22:54 -0000 Github user vladimir-kotikov commented on a diff in the pull request: https://github.com/apache/cordova-paramedic/pull/11#discussion_r69516761 --- Diff: lib/appium/AppiumRunner.js --- @@ -0,0 +1,491 @@ +#!/usr/bin/env node + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* jshint node: true */ + +"use strict"; + +var fs = require("fs"); +var path = require("path"); +var util = require("./helpers/util"); +var logger = require("../utils").logger; +var wd = require("wd"); +var wdHelper = require("./helpers/wdHelper"); +var screenshotHelper = require("./helpers/screenshotHelper"); +var kill = require("tree-kill"); +var child_process = require("child_process"); +var expectTelnet = require("expect-telnet"); +var shell = require("shelljs"); +var Jasmine = require("jasmine"); +var unorm = require("unorm"); +var elementTree = require("elementtree"); +var q = require("q"); +var Reporters = require("../Reporters"); + +var KILL_SIGNAL = "SIGINT"; +var SMALL_BUFFER_SIZE = 1024 * 1024; +var BIG_BUFFER_SIZE = 50 * 1024 * 1024; +var APPIUM_SERVER_PATH = getAppiumServerPath(); + +function AppiumRunner(options) { + this.options = options; + this.findTests(); + this.setGlobals(); +} + +function getAppiumServerPath() { + return path.resolve(process.cwd(), "cordova-paramedic/node_modules/appium/build/lib/main.js"); +} + +function getFullAppPath(appPath) { + var fullPath = appPath; + if (!path.isAbsolute(appPath)) { + fullPath = path.join(__dirname, "../..", appPath); + } + return fullPath; +} + +function getPackagePath(options) { + if (options.sauce) { + return options.sauceAppPath; + } + + var fullAppPath = getFullAppPath(options.appPath); + + switch (options.platform) { + case "android": + return path.join(fullAppPath, "/platforms/android/build/outputs/apk/android-debug.apk"); + case "ios": + var searchDir = options.device ? + path.join(getFullAppPath(options.appPath), "/platforms/ios/build/device/") : + path.join(getFullAppPath(options.appPath), "/platforms/ios/build/emulator/"); + var fileMask = options.device ? "*.ipa" : "*.app"; + var files = shell.ls(searchDir + fileMask); + logger.normal("paramedic-appium: Looking for app package in " + searchDir); + if (files && files.length > 0) { + logger.normal("paramedic-appium: Found app package: " + files[0]); + return files[0]; + } + throw new Error("Could not find the app package"); + } +} + +function getPluginDirs(appPath) { + return shell.ls(path.join(appPath, "/plugins/cordova-plugin-*")); +} + +function getConfigPath(appPath) { + return path.join(appPath, "config.xml"); +} + +function parseElementtreeSync(filename) { + var contents = fs.readFileSync(filename, util.DEFAULT_ENCODING); + if (!contents) { + throw new Error("The config file is empty: " + filename); + } + // Skip the Byte Order Mark (BOM) + contents = contents.substring(contents.indexOf("<")); + + return new elementTree.ElementTree(elementTree.XML(contents)); +} + +function addCspSource(appPath, directive, source) { + var cspInclFile = path.join(appPath, "www/csp-incl.js"); + var indexFile = path.join(appPath, "www/index.html"); + var cspFile = fs.existsSync(cspInclFile) ? cspInclFile : indexFile; + var cspContent = fs.readFileSync(cspFile, util.DEFAULT_ENCODING); + var cspTagOpening = " -1 || + error.message.indexOf("Bad app") > -1; + } + return false; +} + +function killProcess(procObj, killSignal, callback) { + if (procObj && procObj.alive) { + procObj.alive = false; + setTimeout(function () { + kill(procObj.process.pid, killSignal, callback); + }, 1000); + } else { + callback(); + } +} + +function installAppiumServer(success, fail) { + logger.normal("paramedic-appium: Installing Appium server..."); + shell.pushd(path.join(__dirname, "../..")); + shell.exec("npm install appium", { async: true, silent: !global.VERBOSE }, function (code, stdout) { + if (code !== 0) { + fail("Couldn't install Appium server:\n" + stdout); + } else { + success(); + } + }); + shell.popd(); +} + +function addCallback(reporter, callback) { --- End diff -- It might be better to place this function into 'Reporters.js' (a static method?) --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org For additional commands, e-mail: dev-help@cordova.apache.org