Skip to content

Commit

Permalink
PA-99 Fixed app failing to launch on BlueSky
Browse files Browse the repository at this point in the history
Also resoved eslint warnings
  • Loading branch information
simongranger committed May 23, 2019
1 parent cefb0ce commit 863b8b1
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 65 deletions.
29 changes: 11 additions & 18 deletions lib/basedevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,31 @@ class BaseDevice {
}

closeApp () {
let msg = `closeApp is not supported on this platform`;
logger.errorAndThrow(msg);
logger.errorAndThrow(`closeApp is not supported on this platform`);
}

endSession () {
let msg = `endSession is not supported on this platform`;
logger.errorAndThrow(msg);
logger.errorAndThrow(`endSession is not supported on this platform`);
}

installApp (appPath) {
let msg = `installApp is not supported on this platform`;
logger.errorAndThrow(msg);
installApp (appPath) { // eslint-disable-line no-unused-vars
logger.errorAndThrow(`installApp is not supported on this platform`);
}

isAppInstalled (channelId) {
let msg = `isAppInstalled is not supported on this platform`;
logger.errorAndThrow(msg);
isAppInstalled (channelId) { // eslint-disable-line no-unused-vars
logger.errorAndThrow(`isAppInstalled is not supported on this platform`);
}

launchApp () {
let msg = `launchApp is not supported on this platform`;
logger.errorAndThrow(msg);
logger.errorAndThrow(`launchApp is not supported on this platform`);
}

removeApp (channelId) {
let msg = `removeApp is not supported on this platform`;
logger.errorAndThrow(msg);
removeApp (channelId) { // eslint-disable-line no-unused-vars
logger.errorAndThrow(`removeApp is not supported on this platform`);
}

startSession (caps) {
let msg = `startSession is not supported on this platform`;
logger.errorAndThrow(msg);
startSession (caps) { // eslint-disable-line no-unused-vars
logger.errorAndThrow(`startSession is not supported on this platform`);
}

}
Expand Down
59 changes: 36 additions & 23 deletions lib/bluesky.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,72 @@
import logger from './logger';
import BaseDevice from './basedevice';
import { sleep } from 'asyncbox';

class BlueSky extends BaseDevice {

constructor () {
super();
let channelId;
let caps;
let shell;
this.channelId;
this.caps;
this.shell;
}

closeApp () {
async closeApp () {
logger.info(`BlueSky: Close App`);
this.shell.exec(`curl -d '' http://${this.caps.youiEngineAppAddress}:8060/keypress/home`);
await this.shell.exec(`curl -d '' http://${this.caps.youiEngineAppAddress}:8060/keypress/home`);
let activeApp;
do {
await sleep (1000);
activeApp = await this.shell.exec(`curl http://${this.caps.youiEngineAppAddress}:8060/query/active-app`);
} while (!(activeApp.includes(`<app>Roku</app>`)));
}

endSession () {
async endSession () {
logger.info(`BlueSky: End Session`);
if (this.caps.fullReset) {
this.removeApp(this.channelId);
await this.removeApp(this.channelId);
} else {
this.closeApp();
await this.closeApp();
}
}

installApp (appPath) {
async installApp (appPath) {
logger.info(`BlueSky: Installing and launching app`);
if (this.isAppInstalled(this.channelId)) {
this.removeApp(this.channelId);
if (await this.isAppInstalled(this.channelId)) {
await this.removeApp(this.channelId);
}
this.shell.exec(`curl -v -# -f -i --user '${this.caps.username}:${this.caps.password}' --digest --progress-bar -F 'mysubmit=Install' -F 'archive=@${appPath}' -F 'passwd=' http://${this.caps.youiEngineAppAddress}/plugin_install | grep '<font color' | sed 's/<font color=\'red\'>//' `);
this.launchApp();
// eslint-disable-next-line no-useless-escape
await this.shell.exec(`curl -v -# -f -i --user '${this.caps.username}:${this.caps.password}' --digest --progress-bar -F 'mysubmit=Install' -F 'archive=@${appPath}' -F 'passwd=' http://${this.caps.youiEngineAppAddress}/plugin_install | grep '<font color' | sed 's/<font color=\'red\'>//' `);
await this.launchApp();
}
isAppInstalled (channelId = this.channelId) {

async isAppInstalled (channelId = this.channelId) {
logger.info(`BlueSky: Check if App is installed`);
// Check if app is installed
let devAppInstalled = false;
let installedApps = this.shell.exec(`curl http://${this.caps.youiEngineAppAddress}:8060/query/apps`);
let installedApps = await this.shell.exec(`curl http://${this.caps.youiEngineAppAddress}:8060/query/apps`);
if (installedApps.includes(`id="${channelId}"`)) {
devAppInstalled = true;
}
return devAppInstalled;
}

launchApp () {
async launchApp () {
logger.info(`BlueSky: Launch app`);
this.shell.exec(`curl -d '' http://${this.caps.youiEngineAppAddress}:8060/launch/${this.channelId}`);
let activeApp;
do {
await sleep(5000);
await this.shell.exec(`curl -d '' http://${this.caps.youiEngineAppAddress}:8060/launch/${this.channelId}`);
activeApp = await this.shell.exec(`curl http://${this.caps.youiEngineAppAddress}:8060/query/active-app`);
} while (!(activeApp.includes(`id="${this.channelId}"`)));
}

removeApp (channelId = this.channelId) {
async removeApp (channelId) { // eslint-disable-line no-unused-vars
logger.info(`BlueSky: Delete app`);
this.shell.exec(`curl --user ${this.caps.username}:${this.caps.password} --digest --progress-bar --show-error -F 'mysubmit=Delete' -F 'archive=' --output /tmp/dev_server_out --write-out '%{http_code}' 'http://${this.caps.youiEngineAppAddress}/plugin_install'`);
await this.shell.exec(`curl --user ${this.caps.username}:${this.caps.password} --digest --progress-bar --show-error -F 'mysubmit=Delete' -F 'archive=' --output /tmp/dev_server_out --write-out '%{http_code}' 'http://${this.caps.youiEngineAppAddress}/plugin_install'`);
}

startSession (caps) {
async startSession (caps) {
logger.info(`BlueSky: Start Session`);
this.caps = caps;
this.shell = require('shelljs');
Expand All @@ -62,12 +75,12 @@ class BlueSky extends BaseDevice {
this.channelId = caps.channelId;
}
// Check if app is installed
let devAppInstalled = this.isAppInstalled(this.channelId);
let devAppInstalled = await this.isAppInstalled(this.channelId);

if (caps.fullReset || !devAppInstalled) {
this.installApp(caps.app);
await this.installApp(caps.app);
} else {
this.launchApp();
await this.launchApp();
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ class YouiEngineDriver extends BaseDriver {
break;
case "yimac":
this.device = new YiMac();
this.device.startSession(caps);
await this.device.startSession(caps);
break;
case "bluesky":
this.device = new BlueSky();
this.device.startSession(caps);
await this.device.startSession(caps);
break;
case "yitvos":
case "yitvos": {
let shell = require('shelljs');
if (shell.exec(`instruments -s devices | grep '${caps.udid}'`).includes('(Simulator)')) {
this.device = new TvOsSimulator();
Expand All @@ -115,12 +115,12 @@ class YouiEngineDriver extends BaseDriver {
}
await this.device.startSession(caps, this);
break;
}
case "noproxy":
case "connecttoapp":
break;
default:
let msg = `Unsupported platformName: ${caps.platformName}`;
logger.errorAndThrow(msg);
logger.errorAndThrow(`Unsupported platformName: ${caps.platformName}`);
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/tvos.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class TvOs extends BaseDevice {

constructor () {
super();
let bundleId;
let caps;
let iosdeploy;
let driver;
this.bundleId;
this.caps;
this.iosdeploy;
this.driver;
}

async execScript (script) {
Expand Down
8 changes: 4 additions & 4 deletions lib/tvossimulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class TvOsSimulator extends BaseDevice {

constructor () {
super();
let bundleId;
let caps;
let shell;
let sim;
this.bundleId;
this.caps;
this.shell;
this.sim;
}

execScript (script) {
Expand Down
22 changes: 11 additions & 11 deletions lib/yimac.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ class YiMac extends BaseDevice {

constructor () {
super();
let caps;
let shell;
this.caps;
this.shell;
}

closeApp () {
async closeApp () {
logger.info(`YiMac: Close App`);
let process_name = this.caps.app.substring(this.caps.app.lastIndexOf("/") + 1);
this.shell.exec(`killall ${process_name}`);
await this.shell.exec(`killall ${process_name}`);
}

endSession () {
async endSession () {
logger.info(`YiMac: End Session`);
this.closeApp();
await this.closeApp();
}

launchApp () {
async launchApp () {
logger.info(`YiMac: Launch app`);
let spawn = require('child_process').spawn,
ls = spawn(this.caps.app);
ls = await spawn(this.caps.app);

let showXcodeLog = this.caps.showXcodeLog; //For some reason stderr statement sees this.caps as undefined?!

Expand All @@ -48,12 +48,12 @@ class YiMac extends BaseDevice {
});
}

startSession (caps) {
async startSession (caps) {
logger.info(`YiMac: Start Session`);
this.caps = caps;
this.shell = require('shelljs');
this.closeApp();
this.launchApp();
await this.closeApp();
await this.launchApp();
}

}
Expand Down

0 comments on commit 863b8b1

Please sign in to comment.