From 415fb192bd7861c28273cb2fc79ff7b06dc219db Mon Sep 17 00:00:00 2001 From: Damjan Smickovski Date: Tue, 27 Jun 2023 20:28:51 +0200 Subject: [PATCH] Adjusted the structure and decoupled config --- .gitignore | 3 ++- package.json | 1 + src/config/appium-conf.ts | 31 ++++++++++++++----------------- src/tests/settingsTest.ts | 8 ++++---- tsconfig.json | 6 ++++++ yarn.lock | 9 ++++++++- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 6de57a9..561d0e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules mochawesome-report .env -.DS_Store \ No newline at end of file +.DS_Store +yarn-error.log \ No newline at end of file diff --git a/package.json b/package.json index 9d16a55..5bb957b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/config/appium-conf.ts b/src/config/appium-conf.ts index 5d7135b..e66d6f1 100644 --- a/src/config/appium-conf.ts +++ b/src/config/appium-conf.ts @@ -1,5 +1,5 @@ import dotenv from 'dotenv'; - +import { RemoteOptions } from 'webdriverio'; dotenv.config(); @@ -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 } } \ No newline at end of file diff --git a/src/tests/settingsTest.ts b/src/tests/settingsTest.ts index b9f3359..885cfcb 100644 --- a/src/tests/settingsTest.ts +++ b/src/tests/settingsTest.ts @@ -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(); diff --git a/tsconfig.json b/tsconfig.json index ab33074..43ec0c3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,12 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, "outDir": "dist", + "types": [ + "node", + "mocha", + "@wdio/globals/types", + "@wdio/mocha-framework" + ], "baseUrl": "./src", "paths": { "@config/*": [ diff --git a/yarn.lock b/yarn.lock index 3b4ac68..7cfa151 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -2014,7 +2021,7 @@ webdriver@8.11.1: 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==