Skip to content

Commit

Permalink
US-9500 Added install/remove/launch commands for tvOS
Browse files Browse the repository at this point in the history
The close app method is still missing and requires investigation.
  • Loading branch information
simongranger committed Dec 13, 2018
1 parent be3de3e commit 975eaa4
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 26 deletions.
10 changes: 10 additions & 0 deletions lib/commands/general.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { youiEngineDriverReturnValues } from '../utils';
import logger from '../logger';
import bluesky from '../bluesky';
import tvos from '../tvos';

let commands = {};

Expand All @@ -9,6 +10,9 @@ commands.installApp = async function () {
case 'bluesky':
await bluesky.installApp(this.caps.username, this.caps.password, this.caps.app, this.caps.youiEngineAppAddress);
break;
case 'yitvos':
await tvos.installApp(this.caps.app);
break;
default:
let msg = 'platform (' + this.caps.platformName + ') does not support this command';
logger.errorAndThrow(msg);
Expand All @@ -20,6 +24,9 @@ commands.removeApp = async function (appID) {
case 'bluesky':
await bluesky.removeApp(this.caps.username, this.caps.password, this.caps.youiEngineAppAddress, appID);
break;
case 'yitvos':
await tvos.removeApp(appID);
break;
default:
let msg = 'platform (' + this.caps.platformName + ') does not support this command';
logger.errorAndThrow(msg);
Expand All @@ -42,6 +49,9 @@ commands.launchApp = async function () {
case 'bluesky':
await bluesky.launchApp(this.caps.youiEngineAppAddress);
break;
case 'yitvos':
await tvos.launchApp(this.caps.app);
break;
default:
let msg = 'platform (' + this.caps.platformName + ') does not support this command';
logger.errorAndThrow(msg);
Expand Down
29 changes: 3 additions & 26 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import IOSDriver from 'appium-ios-driver';
import XCUITestDriver from 'appium-xcuitest-driver';
import MacDriver from 'appium-mac-driver';
import bluesky from './bluesky';

import tvos from './tvos';


// Add commands from the following location that should be mapped to existing drivers:
Expand Down Expand Up @@ -97,7 +97,7 @@ class YouiEngineDriver extends BaseDriver {
} else if (appPlatform === "bluesky") {
bluesky.startSession(caps);
} else if (appPlatform === "yitvos") {
this.startYITVOSSession(caps);
tvos.startSession(caps);
}
}

Expand Down Expand Up @@ -130,7 +130,7 @@ class YouiEngineDriver extends BaseDriver {
if (appPlatform === "yimac") {
this.endYIMacSession(this.caps);
} else if (appPlatform === "yitvos") {
this.endYITVOSSession(this.caps);
tvos.endSession(this.caps);
} else if (appPlatform === "bluesky") {
bluesky.endSession(this.caps);
}
Expand Down Expand Up @@ -325,29 +325,6 @@ class YouiEngineDriver extends BaseDriver {
shell.exec("killall " + process_name);
}

startYITVOSSession (caps) {
logger.info("Launching tvOS app");
let shell = require('shelljs');
if (caps.udid) {
shell.exec("ios-deploy --id " + caps.udid + " --uninstall --justlaunch --bundle " + caps.app);
} else {
shell.exec("ios-deploy --uninstall --justlaunch --bundle " + caps.app);
}
}

endYITVOSSession (caps) {
// If multiple apps with our socket are installed, it will connect to the first app installed.
// For this reason, every app should be uninstalled after running.
logger.info("Deleting app");
let shell = require('shelljs');
let bundleid = shell.exec(`osascript -e 'id of app "${caps.app}"'`);
if (caps.udid) {
shell.exec("ios-deploy --id " + caps.udid + " --uninstall_only --bundle_id " + bundleid);
} else {
shell.exec("ios-deploy --uninstall_only --bundle_id " + bundleid);
}
}

validateAppLocation (app) {
const fs = require('fs');
const path = require('path');
Expand Down
85 changes: 85 additions & 0 deletions lib/tvos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import logger from './logger';
import commands from './commands/index';


let udid = null;
let bundleid;
let tvos = {};

tvos.startSession = function (caps) {
logger.info(`tvOS: Start Session`);

if (caps.udid) {
this.udid = caps.udid;
}
else {
this.udid = null; // We need this to update the state in the case where the udid is removed from the caps in the same Appium session.
}
// Check if app is installed
let shell = require('shelljs');
this.bundleid = shell.exec(`osascript -e 'id of app "${caps.app}"'`).replace(/(\r\n|\n|\r)/gm,"");
let devAppInstalled = this.isAppInstalled(this.bundleid);
if (caps.fullReset || !devAppInstalled) {
this.installApp(caps.app);
} else {
this.launchApp(caps.app);
}
};

tvos.endSession = function (caps) {
logger.info(`tvOS: End Session`);
// If multiple apps with our socket are installed, it will connect to the first app installed.
// For this reason, every app should be uninstalled after running.
if (caps.fullReset) {
this.removeApp(this.bundleid);
} else {
//TODOthis.closeApp(caps.youiEngineAppAddress);
}
};

tvos.removeApp = function (bundleid) {
logger.info(`Deleting app`);
let remove_script = `ios-deploy --uninstall_only --bundle_id ${bundleid}`;
this.execScript(remove_script);
};

tvos.installApp = function (app) {
logger.info(`tvOS: Installing and launching app`);
let install_script = `ios-deploy --uninstall --justlaunch --bundle ${app}`;
this.execScript(install_script);
};

tvos.launchApp = function (app) {
logger.info(`tvOS: Launching app`);
let install_script = `ios-deploy --noinstall --justlaunch --bundle ${app}`;
this.execScript(install_script);
};

tvos.isAppInstalled = function (bundleid) {
logger.info(`tvOS: Check if App is installed`);
var install_script = `ios-deploy --exists --bundle_id ${bundleid}`;
return this.execScript(install_script).includes('true');
};

tvos.execScript = function (script) {
logger.info(`tvOS: execScript`);
logger.info(`execScript: ${script}`);
let shell = require('shelljs');
if (this.udid) {
script += ` --id ${this.udid}`;
logger.info(`script: ${script}`);
}
try {
return shell.exec(script);
} catch (err) {
logger.debug(`Stdout: '${err.stdout}'. Stderr: '${err.stderr}'.`);
throw new Error(`Could not run '${script}': '${err.message}'`);
return false;
}
};

// bluesky.closeApp = function (youiEngineAppAddress) {
// // TODO
// };

export default tvos;

0 comments on commit 975eaa4

Please sign in to comment.