Skip to content

Commit

Permalink
Adjusted the structure and decoupled config
Browse files Browse the repository at this point in the history
  • Loading branch information
Damjan Smickovski authored and Damjan Smickovski committed Jun 27, 2023
1 parent fbcb033 commit 415fb19
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
mochawesome-report
.env
.DS_Store
.DS_Store
yarn-error.log
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@types/mocha": "^10.0.1",
"@types/webdriverio": "^5.0.0",
"dotenv": "^16.3.1",
"mocha": "^10.2.0",
"mochawesome": "^7.1.3",
Expand Down
31 changes: 14 additions & 17 deletions src/config/appium-conf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from 'dotenv';

import { RemoteOptions } from 'webdriverio';
dotenv.config();


Expand All @@ -13,24 +13,21 @@ if (!APPIUM_PORT) {
throw new Error("Missing APPIUM_PORT")
}

const capabilitiesAndroid = {
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'Android',
'appium:appPackage': 'com.android.settings',
'appium:appActivity': '.Settings',
};

const capabilitiesIOS = {
// For demo purposes not implemented
};

export const getBaseAndroidCapabilities = (appPackage: string, appActivity: string) => {
return {
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'Android',
'appium:appPackage': appPackage,
'appium:appActivity': appActivity,
}
}

export const getConfig = (platform: 'android' | 'ios') => {
export const getConfig = (capabilities: any): RemoteOptions => {
return {
host: APPIUM_HOST,
hostname: APPIUM_HOST,
port: parseInt(APPIUM_PORT),
logLevel: LOG_LEVEL || 'info',
capabilities: platform === 'android' ? capabilitiesAndroid : capabilitiesIOS,
logLevel: LOG_LEVEL ? LOG_LEVEL as 'info' : 'info',
capabilities: capabilities
}
}
8 changes: 4 additions & 4 deletions src/tests/settingsTest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

const { remote } = require('webdriverio');
import { remote } from 'webdriverio';
import SettingsScreen from '@screens/Settings';
import { getConfig } from '@config/appium-conf';
import { getBaseAndroidCapabilities, getConfig } from '@config/appium-conf';

describe("Settings suite", async () => {
const config = getConfig('android');
const config = getBaseAndroidCapabilities('com.android.settings', '.Settings');
const settingsScreen = new SettingsScreen();

it("Should open settings -> Battery", async () => {
const driver = await remote(config);
const driver = await remote(getConfig(config));
try {
const batteryItem = await driver.$(settingsScreen.batteryButton);
await batteryItem.click();
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "dist",
"types": [
"node",
"mocha",
"@wdio/globals/types",
"@wdio/mocha-framework"
],
"baseUrl": "./src",
"paths": {
"@config/*": [
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
integrity sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==

"@types/webdriverio@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@types/webdriverio/-/webdriverio-5.0.0.tgz#9a46fbd8ba2f44ed40d1efa2e1bd8ac0cfd36a3f"
integrity sha512-x4XylDdijSMmhvpyFdQ6/Ow1CvJBY1Z38MnK3gAtGDy3MnR3AnI8CW9O5B8Q0PNLgLAMA466ghsolhb7+xaZ/Q==
dependencies:
webdriverio "*"

"@types/which@^2.0.1":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@types/which/-/which-2.0.2.tgz#54541d02d6b1daee5ec01ac0d1b37cecf37db1ae"
Expand Down Expand Up @@ -2014,7 +2021,7 @@ [email protected]:
ky "^0.33.0"
ws "^8.8.0"

webdriverio@^8.11.2:
webdriverio@*, webdriverio@^8.11.2:
version "8.11.2"
resolved "https://registry.yarnpkg.com/webdriverio/-/webdriverio-8.11.2.tgz#1067ad038409258eb478262ed452b3f315c26446"
integrity sha512-e/9WkdNTfWeoaSo2UzK0Giec/nQX3i7U9J8esimhozH/EpwSqIaEJ2pRRlxRVafEhe2OBG1QDhnLnDjdCC5Hxg==
Expand Down

0 comments on commit 415fb19

Please sign in to comment.