Skip to content

Commit

Permalink
update testsuite to use 1.0-style caps
Browse files Browse the repository at this point in the history
- and fix various issues with specific tests
  • Loading branch information
jlipps committed Apr 4, 2014
1 parent cd0e4aa commit ce8adcf
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 43 deletions.
2 changes: 1 addition & 1 deletion bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ run_ios_tests() {
echo "Did not find /Applications/Xcode-$1.app, using default"
fi
echo
DEVICE=$2 VERSION=$1 time $appium_mocha -g $3 -i \
DEVICE=$2 time $appium_mocha -g $3 -i \
test/functional/common \
test/functional/ios
}
Expand Down
4 changes: 3 additions & 1 deletion lib/appium.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ Appium.prototype.getDeviceTypeFromAutomationName = function (automation) {
};

Appium.prototype.getDeviceTypeFromBrowserName = function (browser) {
if (_.contains(["chrome", "chromium", "browser"], browser)) {
if (browser === "safari") {
return DT_SAFARI;
} else if (_.contains(["chrome", "chromium", "browser"], browser)) {
return DT_CHROME;
}
};
Expand Down
4 changes: 3 additions & 1 deletion lib/devices/android/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ ChromeAndroid.prototype.init = function () {
ChromeAndroid.prototype.configure = function (args, caps, cb) {
logger.info("Looks like we want chrome on android");
this._deviceConfigure(args, caps);
var app = this.appString().toLowerCase();
var bName = this.args.browserName || "";
var app = this.appString().toLowerCase() ||
bName.toString().toLowerCase();
if (app === "chromium") {
this.args.androidPackage = "org.chromium.chrome.testshell";
this.args.androidActivity = "org.chromium.chrome.testshell.Main";
Expand Down
4 changes: 2 additions & 2 deletions test/functional/android/apidemos/alerts-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var env = require('../../../helpers/env')
, net = require('net')
, io = require('socket.io-client');

describe("apidemos - alerts -", function () {
describe("apidemos - alerts - @skip-android-all -", function () {

setup(this, desired);

Expand Down Expand Up @@ -55,4 +55,4 @@ describe("apidemos - alerts -", function () {
done();
}
});
});
});
3 changes: 1 addition & 2 deletions test/functional/android/apidemos/desired.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
var getAppPath = require('../../../helpers/app').getAppPath;

module.exports = {
app: getAppPath('ApiDemos', 'android'),
device: 'Android'
app: getAppPath('ApiDemos', 'android')
};
9 changes: 8 additions & 1 deletion test/functional/common/webview-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ var env = require('../../helpers/env')
// possible apps: safari, chrome, iwebview, WebViewApp, custom app
module.exports = function (app) {
app = app || 'WebViewApp';
var browserName = "";
var isChrome = app === "chrome" || app === "chromium";
var testEndpoint = isChrome ? env.CHROME_TEST_END_POINT : env.TEST_END_POINT;

if (isChrome || app === "safari") {
browserName = app;
app = "";
}

function _skip(reason, done) {
console.warn("skipping: " + reason);
done();
Expand All @@ -24,9 +30,10 @@ module.exports = function (app) {
return setupBase(context, {
nonSyntheticWebClick: true
, app: app
, browserName: browserName
, safariIgnoreFraudWarning: true
, enablePerformanceLogging: true
});
}, {'no-reset': true});
};

var loadWebView = function (driver, urlToLoad, titleToSpin) {
Expand Down
18 changes: 9 additions & 9 deletions test/functional/ios/file-movement-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ describe('pullFile', function () {
before(function (done) {
var pv = env.CAPS.platformVersion || '7.1';
var simRoots = iOSSettings.getSimRootsWithVersion(pv);
if (simRoots.length < 1) {
return done(new Error("Didn't find any simulator directories"));
}
var basePath = path.resolve(simRoots[0], 'Applications')
.replace(/\s/g, '\\ ');

var findCmd = 'find ' + basePath + ' -name "testapp.app"';
exec(findCmd, function (err, stdout) {
if (err) throw (err);
if (err) return done(err);
if (!stdout) return done(new Error("Could not find testapp.app"));
var appRoot = stdout.replace(/\n$/, '');
fullPath = path.resolve(appRoot, fileName);
fs.writeFile(fullPath, fileContent, function (err) {
if (err) throw (err);
});
done();
fs.writeFile(fullPath, fileContent, done);
});
});
after(function (done) {
if (fullPath) {
fs.unlink(fullPath, function (err) {
if (err) throw err;
done();
});
fs.unlink(fullPath, done);
} else {
done();
}
});
it('should be able to fetch a file from the app directory', function (done) {
Expand Down
4 changes: 1 addition & 3 deletions test/functional/ios/prefs-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ chai.should();

var desired = {
app: 'settings'
, device: 'iPhone Simulator'
};

describe("prefs @skip-ios7", function () {
Expand Down Expand Up @@ -130,8 +129,7 @@ describe('safari prefs @skip-ios7', function () {
describe('safari ios7 prefs @skip-ios6', function () {

var desired = {
app: 'safari'
, device: 'iPhone Simulator'
browserName: 'safari'
};

var checkSafariSetting = function (setting, expected, cb) {
Expand Down
2 changes: 1 addition & 1 deletion test/functional/ios/safari/screenshot-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("safari - screenshot -", function () {

describe('screenshots (' + env.DEVICE + ')', function () {
var driver;
setup(this, {app: 'safari'}).then(function (d) { driver = d; });
setup(this, {browserName: 'safari'}).then(function (d) { driver = d; });

it('should get a local screenshot', function (done) {
var localScreenshotFile = '/tmp/test_screenshot_appium.png';
Expand Down
2 changes: 1 addition & 1 deletion test/functional/ios/safari/windows-frame-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("safari - windows-frame -", function () {

describe('windows and frames (' + env.DEVICE + ')', function () {
var driver;
setup(this, {app: 'safari'}).then(function (d) { driver = d; });
setup(this, {browserName: 'safari'}).then(function (d) { driver = d; });

it('getting current window should work initially', function (done) {
driver
Expand Down
2 changes: 1 addition & 1 deletion test/functional/selendroid/webview-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ process.env.DEVICE = process.env.DEVICE || "selendroid";
var androidWebviewTests = require('../../helpers/android-webview');
// if it doesn't work run: adb uninstall io.selendroid.testapp

describe('selendroid - web_view -', androidWebviewTests);
describe('selendroid - web_view -', androidWebviewTests.windows);
56 changes: 42 additions & 14 deletions test/helpers/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ env.EMU = !env.REAL_DEVICE;
// device selection
env.DEVICE = (process.env.DEVICE || 'ios').toLowerCase();

function iphoneOrIpadSimulator(device) {
return device.match(/ipad/i) ? 'iPad Simulator' : 'iPhone Simulator';
function iphoneOrIpadSimulator(device, version) {
var isIpad = device.match(/ipad/i);
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';
default:
throw new Error("invalid version");
}
}

switch (env.DEVICE) {
Expand All @@ -46,48 +55,57 @@ switch (env.DEVICE) {
case 'ios6_ipad':
env.CAPS = {
browserName: ''
, device: iphoneOrIpadSimulator(env.DEVICE),
app: path.resolve(__dirname, "../../sample-code/apps/" + process.env.APP +
"/build/Release-iphonesimulator/" + process.env.APP + ".app")
, deviceName: iphoneOrIpadSimulator(env.DEVICE, "6.1"),
app: process.env.APP ? path.resolve(__dirname, "../../sample-code/apps/" + process.env.APP + "/build/Release-iphonesimulator/" + process.env.APP + ".app") : ''
};
break;
case 'ios7':
case 'ios7_iphone':
case 'ios7_ipad':
env.CAPS = {
browserName: ''
, deviceName: iphoneOrIpadSimulator(env.DEVICE, "7.0")
, app: process.env.APP ? path.resolve(__dirname, "../../sample-code/apps/" + process.env.APP + "/build/Release-iphonesimulator/" + process.env.APP + ".app") : ''
};
break;
case 'ios71':
case 'ios71_iphone':
case 'ios71_ipad':
env.CAPS = {
browserName: ''
, device: iphoneOrIpadSimulator(env.DEVICE)
, app: path.resolve(__dirname, "../../sample-code/apps/" + process.env.APP +
"/build/Release-iphonesimulator/" + process.env.APP + ".app")
, deviceName: iphoneOrIpadSimulator(env.DEVICE, "7.1")
, app: process.env.APP ? path.resolve(__dirname, "../../sample-code/apps/" + process.env.APP + "/build/Release-iphonesimulator/" + process.env.APP + ".app") : ''
};
break;
case 'android':
env.CAPS = {
device: 'Android'
browserName: ''
, platformName: 'Android'
, deviceName: 'Android Emulator'
};
break;
case 'selendroid':
env.CAPS = {
browserName: 'Selendroid'
, device: 'Selendroid',
app: path.resolve(__dirname, "../../sample-code/apps/" + process.env.APP + "/bin/" + process.env.APP + "-debug.apk")
browserName: ''
, platformName: 'Android'
, automationName: 'Selendroid'
, deviceName: 'Android Emulator'
, app: process.env.APP ? path.resolve(__dirname, "../../sample-code/apps/" + process.env.APP + "/bin/" + process.env.APP + "-debug.apk") : ''
};
break;
case 'firefox':
env.CAPS = {
browserName: 'Firefox'
, device: 'Firefox',
app: process.env.APP
app: process.env.APP ? process.env.APP : ''
};
break;
default:
throw new Error('Unknown device!!!');
}

env.IOS = env.DEVICE.match(/ios/i);
env.IOS6 = env.DEVICE.match(/ios6/i);
env.IOS7 = env.DEVICE.match(/ios7/i);
env.IOS71 = env.DEVICE.match(/ios71/i);
env.ANDROID = env.DEVICE.match(/android/i);
Expand All @@ -109,8 +127,18 @@ if (env.SAUCE) {

env.CAPS.launchTimeout = env.LAUNCH_TIMEOUT;

if (env.IOS) {
env.CAPS.platformName = "iOS";
}

if (env.VERSION) {
env.CAPS.version = env.VERSION;
env.CAPS.platformVersion = env.VERSION;
} else if (env.IOS6) {
env.CAPS.platformVersion = "6.1";
} else if (env.IOS71) {
env.CAPS.platformVersion = "7.1";
} else if (env.IOS7) {
env.CAPS.platformVersion = "7.0";
}

// app path root
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ module.exports.initSession = function (desired, opts) {

function init(remainingAttempts) {
if (env.VERBOSE) console.log("remainingAttempts -->", remainingAttempts);

return browser
.init(caps)
.catch(function (err) {
Expand All @@ -80,7 +79,9 @@ module.exports.initSession = function (desired, opts) {
var attempts = opts['no-retry'] ? 1 : 3;
return browser.chain()
.then(function () {
if (env.IOS && env.RESET_IOS) { return iosReset(); }
if (env.IOS && env.RESET_IOS && !opts['no-reset']) {
return iosReset();
}
}).then(function () {
// if android uninstall package first
if (desired.device === 'Android' && desired['app-package']) {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/configuration-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ describe('Appium', function () {
var happyTests = [
[{}, {app: 'chromium', device: 'android'}, 'chrome']
, [{}, {app: '/path/to/my.app', device: 'Android'}, 'android']
, [{}, {browserName: "safari"}, 'safari']
, [{app: '/path/to/my.app'}, {device: 'Android'}, 'android']
, [{}, {device: 'iPhone Simulator'}, 'ios']
, [{}, {device: 'iPhone Simulator', browserName: 'Safari'}, 'ios']
, [{}, {device: 'iPhone Simulator', browserName: 'safari'}, 'ios']
, [{}, {device: 'iPhone Simulator', browserName: 'Safari'}, 'safari']
, [{}, {device: 'iPhone Simulator', browserName: 'safari'}, 'safari']
, [{}, {device: 'iPhone'}, 'ios']
, [{}, {device: 'iphone'}, 'ios']
, [{}, {device: 'ipad'}, 'ios']
Expand All @@ -52,7 +53,6 @@ describe('Appium', function () {
[{}, {}]
, [{}, {device: 'rando'}]
, [{}, {app: '/path/to/my.exe'}]
, [{}, {browserName: 'Safari'}]
, [{ipa: '/path/to/my.exe'}, {}]
, [{}, {platformName: 'notarealdevice'}]
];
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Appium', function () {
describe('browserName', function () {

var browserCapabilities = [
[{}, {platformName: 'ios', browserName: 'Safari'}, 'ios']
[{}, {platformName: 'ios', browserName: 'Safari'}, 'safari']
, [{}, {platformName: 'Android', browserName: 'Chrome'}, 'chrome']
, [{}, {platformName: 'Android', browserName: 'Chromium'}, 'chrome']
, [{}, {platformName: 'Android', browserName: 'browser'}, 'chrome']
Expand Down

0 comments on commit ce8adcf

Please sign in to comment.