Skip to content

Commit

Permalink
fix: fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
tzvielwix committed Feb 18, 2025
2 parents 3f1691f + b754536 commit e7f0bf8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/drivers/appium/examples/example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Example Test Suite", () => {

before(async () => {
const promptHandler: PromptHandler = new PromptHandler();
frameworkDriver = new WebdriverIOAppiumFrameworkDriver();
frameworkDriver = new WebdriverIOAppiumFrameworkDriver(() => browser);

pilot.init({
frameworkDriver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "path";

export const config = {
runner: "local",
specs: ["./examples/**/*.test.ts"],
specs: ["./**/*.test.ts"],
maxInstances: 1,

capabilities: [
Expand All @@ -12,7 +12,7 @@ export const config = {
"appium:automationName": "XCUITest",
"appium:app": path.resolve(
__dirname,
"../detox/ExampleApp/ios/build/Build/Products/Release-iphonesimulator/ExampleApp.app",
"../../detox/ExampleApp/ios/build/Build/Products/Release-iphonesimulator/ExampleApp.app",
),
},
],
Expand All @@ -35,8 +35,4 @@ export const config = {
ui: "bdd",
timeout: 600000,
},

before: function () {
global.driver = browser;
},
};
7 changes: 2 additions & 5 deletions packages/drivers/appium/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// global.d.ts
import type { Browser } from "@wdio/types";
import type { Browser } from "webdriverio";

declare global {
// eslint-disable-next-line no-var
var driver: Browser;
const browser: Browser;
const browser: Browser<"async">;
}

export {};
9 changes: 6 additions & 3 deletions packages/drivers/appium/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
} from "@wix-pilot/core";
import * as fs from "fs";
import * as path from "path";
import type { Browser } from "webdriverio";

export class WebdriverIOAppiumFrameworkDriver
implements TestingFrameworkDriver
{
constructor(private getDriver: () => Browser) {}
/**
* Attempts to capture the current view hierarchy (source) of the mobile app as XML.
* If there's no active session or the app isn't running, returns an error message.
Expand All @@ -16,7 +18,7 @@ export class WebdriverIOAppiumFrameworkDriver
try {
// In WebdriverIO + Appium, you can retrieve the current page source (UI hierarchy) via:
// https://webdriver.io/docs/api/browser/getPageSource (driver is an alias for browser)
const pageSource = await driver.getPageSource();
const pageSource = await this.getDriver().getPageSource();
return pageSource;
} catch (_error) {
return "NO ACTIVE APP FOUND, LAUNCH THE APP TO SEE THE VIEW HIERARCHY";
Expand All @@ -39,11 +41,12 @@ export class WebdriverIOAppiumFrameworkDriver
try {
// In WebdriverIO + Appium, driver.takeScreenshot() returns a base64-encoded PNG
// https://webdriver.io/docs/api/browser/takeScreenshot
const base64Image = await driver.takeScreenshot();
const base64Image = await this.getDriver().takeScreenshot();
const buffer = Buffer.from(base64Image, "base64");
fs.writeFileSync(filePath, buffer);
return filePath;
} catch (_error) {
console.log(_error);
return undefined;
}
}
Expand All @@ -58,7 +61,7 @@ export class WebdriverIOAppiumFrameworkDriver
description:
"WebdriverIO is a browser and mobile automation library; Appium is a cross-platform automation framework for native, hybrid, and mobile web apps.",
context: {
webdriverDriver: driver,
driver: this.getDriver(),
},
categories: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/drivers/appium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"scripts": {
"build": "tsc && tsc-alias",
"test": "echo No tests available for this package",
"test:example": "wdio run wdio.conf.ts",
"test:example": "wdio run examples/wdio.conf.ts",
"build:app": "cd ../detox/ExampleApp && npm run build:ios",
"bump-version:patch": "npm version patch && git commit -am 'chore: bump patch version' && git push",
"release:patch": "npm run test && npm run bump-version:patch && npm run build && npm publish --access public",
Expand Down
5 changes: 2 additions & 3 deletions packages/drivers/appium/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"rootDir": "./",
"types": ["jest", "node"],
"types": ["jest", "node", "mocha"],
"baseUrl": "./",
"resolveJsonModule": true
},
"include": ["./"],
"exclude": [
"node_modules",
"dist",
"examples",
]
]
}
22 changes: 22 additions & 0 deletions website/docs/pages/supported-frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ it('should update profile', async () => {
});
```

### WebdriverIO with Appium

WebdriverIO integration with Appium. supports both iOS and Android testing

```js
// 1. Install: npm install --save-dev @wix-pilot/webdriverio-appium
// 2. Import:
import { WebdriverIOAppiumFrameworkDriver } from '@wix-pilot/webdriverio-appium';
// 3. make sure you intalize the the framework driver with your global browser instance:
frameworkDriver = new WebdriverIOAppiumFrameworkDriver(() => browser);

it('should update profile', async () => {
await pilot.perform(
'Launch the app',
'Navigate to Settings',
'Tap on "Edit Profile"',
'Update username to "john_doe"',
'Verify changes are saved'
);
});
```

## Web Testing Support

### Playwright
Expand Down

0 comments on commit e7f0bf8

Please sign in to comment.