Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**/*.ts
/**/*.map
!/**/*.d.ts
e2e/reports
e2e/**/*.js
!e2e/*.ts
!e2e/tsconfig.json
samples/reports
samples/e2e-tsc/*.js
!samples/e2e-tsc/*.ts
!samples/e2e-tsc/tsconfig.json
publish-next.js
test-app
.vscode
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/*.js": true,
"/lib/**/*.js": true,
"/bin/**/*.js": true,
"samples/e2e-js/*.js": false,
"**/*.map": true,
"**/*.d.ts": true,
"postinstall.js": false
Expand Down
4 changes: 2 additions & 2 deletions lib/device-manager.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { INsCapabilities } from "./interfaces/ns-capabilities";
import { IDeviceManager } from "./interfaces/device-manager";
import { IDevice, DeviceType } from "mobile-devices-controller";
import { IDevice, Device, DeviceType } from "mobile-devices-controller";
export declare class DeviceManager implements IDeviceManager {
private static _emulators;
constructor();
Expand All @@ -9,7 +9,7 @@ export declare class DeviceManager implements IDeviceManager {
installApp(args: INsCapabilities): Promise<any>;
uninstallApp(args: INsCapabilities): Promise<any>;
static kill(device: IDevice): Promise<void>;
static getDefaultDevice(args: INsCapabilities, deviceName?: string, token?: string, type?: DeviceType, platformVersion?: number): any;
static getDefaultDevice(args: INsCapabilities, deviceName?: string, token?: string, type?: DeviceType, platformVersion?: number): Device;
static setDontKeepActivities(args: INsCapabilities, driver: any, value: any): Promise<void>;
static executeShellCommand(driver: any, commandAndargs: {
command: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/image-helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export declare class ImageHelper {
blockOutAreas: IRectangle[];
imageOutputLimit(): ImageOptions;
thresholdType(): ImageOptions;
threshold(thresholdType: any): 10 | 0.01;
threshold(thresholdType: any): 0.01 | 10;
delta(): number;
static cropImageDefault(_args: INsCapabilities): {
x: number;
Expand Down
36 changes: 19 additions & 17 deletions lib/ns-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INsCapabilities } from "./interfaces/ns-capabilities";
import { INsCapabilitiesArgs } from "./interfaces/ns-capabilities-args";
import { AutomationName } from "./automation-name";
import { resolveCapabilities } from "./capabilities-helper";
import { getAppPath, fileExists, logInfo, logError } from "./utils";
import { getAppPath, fileExists, logInfo, logError, logWarn } from "./utils";
import { IDevice } from "mobile-devices-controller";
import { IDeviceManager } from "./interfaces/device-manager";

Expand Down Expand Up @@ -146,13 +146,13 @@ export class NsCapabilities implements INsCapabilities {
if (this._ignoreDeviceController) {
this.appiumCaps["fullReset"] = true;
this.appiumCaps["noReset"] = false;
console.log("Changing appium setting fullReset: true and noReset: false ");
logInfo("Changing appium setting fullReset: true and noReset: false ");
}

if (this._attachToDebug || this._devMode) {
this.appiumCaps["fullReset"] = false;
this.appiumCaps["noReset"] = true;
console.log("Changing appium setting fullReset: false and noReset: true ");
logInfo("Changing appium setting fullReset: false and noReset: true ");
}
}

Expand Down Expand Up @@ -194,23 +194,25 @@ export class NsCapabilities implements INsCapabilities {
}

private resolveApplication() {
if (this.isSauceLab) {
if (this.appPath){
if (this.appPath.startsWith("http")){
this._appiumCaps.app = this.appPath;
} else {
this._appiumCaps.app = `sauce-storage:${this.appPath}`;
}
} else if (!this._appiumCaps.app){
throw new Error("Neither appPath option nor capabilities.app provided!!!");
if (this._isSauceLab) {
if (this._appPath) {
this._appiumCaps.app = this._appPath.startsWith("http") ? this._appPath : `sauce-storage:${this._appPath}`;
}

if (!this._appiumCaps.app) {
const errorMsg = "Neither appPath option nor capabilities.app provided!!!";
logError(errorMsg);
throw new Error(errorMsg);
}


this._appPath = this._appiumCaps.app;
this._ignoreDeviceController = true;
console.log("Using Sauce Labs. The application path is changed to: " + this._appiumCaps.app);
logInfo(`Using Sauce Labs. The application path is changed to: ${this._appiumCaps.app}`);
} else {
this.appiumCaps.app = getAppPath(this);
this._appiumCaps.app = getAppPath(this);
this._appPath = this._appiumCaps.app;
console.log("Application full path: " + this._appiumCaps.app);

logInfo(`Application full path: ${this._appiumCaps.app}`);
}
}

Expand All @@ -230,7 +232,7 @@ export class NsCapabilities implements INsCapabilities {
}

if (!this._appiumCaps.platformVersion) {
console.warn("Platform version is missing! You'd better to set it in order to use the correct device");
logWarn("Platform version is missing! You'd better to set it in order to use the correct device");
}

if (!this._appiumCaps.deviceName && !this._appiumCaps.udid) {
Expand Down
5 changes: 0 additions & 5 deletions lib/ui-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ export class UIElement {
return await (await this.element()).click();
}

/**
* Click a point by providing coordinates
* @param x
* @param y
*/
public async tapCenter() {
let action = new this._wd.TouchAction(this._driver);
const rect = await this.getActualRectangle();
Expand Down
6 changes: 3 additions & 3 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,8 @@ export const getRegexResultsAsArray = (regex, str) => {
}

function getAppName(args: INsCapabilities) {
const appLocation = args.appPath || args.appiumCaps.app;
const appName = args.appName || appLocation
.substring(appLocation.lastIndexOf("/") + 1, appLocation.lastIndexOf("."))
const appName = args.appName || path.basename(args.appPath)
.replace(path.extname(args.appPath), "")
.replace("-release", "").replace("-debug", "");

return appName;
Expand Down Expand Up @@ -557,6 +556,7 @@ export const prepareApp = async (args: INsCapabilities) => {
args.appName = groupings[groupings.length - 1];
console.log(`Setting application name as ${args.appName}`);
if (!args.devMode && !args.ignoreDeviceController) {
logInfo("Check and uninstall application from device.");
await args.deviceManager.uninstallApp(args);
} else {
args.appiumCaps.app = "";
Expand Down
81 changes: 47 additions & 34 deletions postinstall.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
#!/usr/bin/env node

const { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } = require("fs");
const {
existsSync,
mkdirSync,
readdirSync,
readFileSync,
statSync,
writeFileSync
} = require("fs");
const { basename, resolve } = require("path");

const appRootPath = require('app-root-path').toString();
const childProcess = require("child_process");
const appRootPath = require('app-root-path').toString();

const sampleTestsFolder = "samples";
const e2eTests = "e2e";
const e2eProjectFolderPath = resolve(appRootPath, e2eTests);
const e2ePluginFolderPath = resolve(appRootPath, "node_modules", "nativescript-dev-appium", "e2e");
const sampleTestsProjectFolderPath = resolve(appRootPath, e2eTests);
const sampleTestsPluginFolderPath = resolve(appRootPath, "node_modules", "nativescript-dev-appium", sampleTestsFolder);
const packageJsonPath = resolve(appRootPath, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));

const isTypeScriptProject =
(
packageJson.dependencies &&
packageJson.dependencies.hasOwnProperty("typescript")
) || (
packageJson.devDependencies &&
packageJson.devDependencies.hasOwnProperty("typescript")
);
(packageJson.dependencies && packageJson.dependencies.hasOwnProperty("typescript"))
|| (packageJson.devDependencies && packageJson.devDependencies.hasOwnProperty("typescript"));
const isWin = /^win/.test(process.platform);

function executeNpmInstall(cwd) {
const executeNpmInstall = cwd => {
let spawnArgs = [];
let command = "";
if (isWin) {
Expand All @@ -33,7 +37,7 @@ function executeNpmInstall(cwd) {
childProcess.spawnSync(command, spawnArgs, { cwd, stdio: "inherit" });
}

function copy(src, dest) {
const copy = (src, dest) => {
if (!existsSync(src)) {
return Error("Source doesn't exist: " + src);
}
Expand All @@ -57,25 +61,24 @@ function copy(src, dest) {
}
}

function getDevDependencies() {
const getDevDependencies = () => {
// These are nativescript-dev-appium plugin's dependencies.
// There is NO need to explicitly install them to the project.
// const requiredDevDependencies = [
// { name: "chai", version: "~4.1.1" },
// { name: "chai-as-promised", version: "~7.1.1" },
// { name: "mocha", version: "~3.5.0" },
// { name: "mocha", version: "~5.2.0" },
// { name: "mocha-junit-reporter", version: "^1.13.0" },
// { name: "mocha-multi", version: "^0.11.0" },
// { name: "mocha-multi", version: "^1.0.1" },
// ];

// These are nativescript-dev-appium plugin's devDependencies.
// There is need to explicitly install them to the project.
const typeScriptDevDependencies = [
//{ name: "tslib", version: "^1.7.1" },
{ name: "@types/chai", version: "~4.1.3" },
{ name: "@types/mocha", version: "~5.2.1" },
{ name: "@types/node", version: "^7.0.5" },
];
// const typeScriptDevDependencies = [
// { name: "@types/chai", version: "~4.1.3" },
// { name: "@types/mocha", version: "~5.2.1" },
// { name: "@types/node", version: "^7.0.5" },
// ];

// return isTypeScriptProject ?
// [
Expand All @@ -84,10 +87,15 @@ function getDevDependencies() {
// ] :
// requiredDevDependencies;

return typeScriptDevDependencies;
return !isTypeScriptProject ? [] :
[
{ name: "@types/chai", version: "~4.1.3" },
{ name: "@types/mocha", version: "~5.2.1" },
{ name: "@types/node", version: "^7.0.5" },
];
}

function configureDevDependencies(packageJson) {
const configureDevDependencies = packageJson => {
if (!packageJson.devDependencies) {
packageJson.devDependencies = {};
}
Expand All @@ -100,13 +108,13 @@ function configureDevDependencies(packageJson) {
if (devDependenciesToInstall.length) {
console.info("Installing new devDependencies ...");
// Execute `npm install` after everything else
setTimeout(function() {
setTimeout(function () {
executeNpmInstall(appRootPath);
}, 300);
}
}

function updatePackageJsonDependencies(packageJson, isTypeScriptProject) {
const updatePackageJsonDependencies = (packageJson, isTypeScriptProject) => {
if (!packageJson.scripts) {
packageJson.scripts = {};
}
Expand All @@ -126,14 +134,19 @@ function updatePackageJsonDependencies(packageJson, isTypeScriptProject) {

if (basename(appRootPath) !== "nativescript-dev-appium") {
updatePackageJsonDependencies(packageJson, isTypeScriptProject);
if (!existsSync(e2eProjectFolderPath)) {
mkdirSync(e2eProjectFolderPath);
if (!existsSync(sampleTestsProjectFolderPath)) {
mkdirSync(sampleTestsProjectFolderPath);
if (isTypeScriptProject) {
console.info("TypeScript project - adding sample config and test ...");
console.info("Copying " + e2ePluginFolderPath + " to " + e2eProjectFolderPath + " ...");
copy(e2ePluginFolderPath, e2eProjectFolderPath);
console.info(`TypeScript project - adding sample config and test ...`);
const tscSampleTestsPath = resolve(sampleTestsPluginFolderPath, "e2e-tsc")
console.info(`Copying ${tscSampleTestsPath} to ${sampleTestsProjectFolderPath} ...`);
copy(tscSampleTestsPath, sampleTestsProjectFolderPath);
} else {
console.info("JavaScript project - not adding sample config and test ...");
const jsSampleTestsPath = resolve(sampleTestsPluginFolderPath, "e2e-js")
console.info("JavaScript project - adding sample config and test ...");
console.info(`Copying ${jsSampleTestsPath} to ${sampleTestsProjectFolderPath} ...`);
copy(jsSampleTestsPath, sampleTestsProjectFolderPath);
}
}
}
}

File renamed without changes.
44 changes: 44 additions & 0 deletions samples/e2e-js/sample.e2e-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const nsAppium = require("nativescript-dev-appium");
const assert = require("chai").assert;

describe("sample scenario", () => {
const defaultWaitTime = 5000;
let driver;

before(async () => {
driver = await nsAppium.createDriver();
});

after(async () => {
await driver.quit();
console.log("Quit driver!");
});

afterEach(async function () {
if (this.currentTest.state === "failed") {
await driver.logTestArtifacts(this.currentTest.title);
}
});

it("should find an element by text", async () => {
const btnTap = await driver.findElementByText("TAP", nsAppium.SearchOptions.exact);
await btnTap.click();

const message = " taps left";
const lblMessage = await driver.findElementByText(message, nsAppium.SearchOptions.contains);
assert.equal(await lblMessage.text(), "41" + message);

// Image verification
// const screen = await driver.compareScreen("hello-world-41");
// assert.isTrue(screen);
});

it("should find an element by type", async () => {
const btnTap = await driver.findElementByClassName(driver.locators.button);
await btnTap.click();

const message = " taps left";
const lblMessage = await driver.findElementByText(message, nsAppium.SearchOptions.contains);
assert.equal(await lblMessage.text(), "40" + message);
});
});
9 changes: 9 additions & 0 deletions samples/e2e-js/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const nsAppium = require("nativescript-dev-appium");

before("start appium server", async () => {
await nsAppium.startServer();
});

after("stop appium server", async () => {
await nsAppium.stopServer();
});
Loading