Skip to content

Commit

Permalink
Merge pull request #577 from Satellite-im/luis/refactor-2
Browse files Browse the repository at this point in the history
chore(appium): refactor to simplify instances handling on code
  • Loading branch information
luisecm authored Dec 18, 2023
2 parents 795695c + 4a4b694 commit 1edcde0
Show file tree
Hide file tree
Showing 82 changed files with 1,936 additions and 2,785 deletions.
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Ignore test results and system files
node_modules/
test-results/
config/
.gitignore
appium.log
babel.config.js
package-lock.json
package.json
tsconfig.json
102 changes: 56 additions & 46 deletions config/wdio.mac.app.conf.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require("module-alias/register");
const allureReporter = require('@wdio/allure-reporter').default;
const sharedConfig = require('@config/wdio.shared.conf.ts').config;
const allureReporter = require("@wdio/allure-reporter").default;
const sharedConfig = require("@config/wdio.shared.conf.ts").config;
const homedir = require("os").homedir;
const join = require("path").join;
const MACOS_BUNDLE_ID = require("@helpers/constants").MACOS_BUNDLE_ID;
const MACOS_DRIVER = require("@helpers/constants").MACOS_DRIVER;const fsp = require("fs").promises;
const MACOS_DRIVER = require("@helpers/constants").MACOS_DRIVER;
const fsp = require("fs").promises;
const { readFileSync, rmSync } = require("fs");

// @ts-expect-error
export const config: WebdriverIO.Config = {
...sharedConfig,
...sharedConfig,
...{
//
// ==================
Expand All @@ -27,10 +27,12 @@ export const config: WebdriverIO.Config = {
// then the current working directory is where your `package.json` resides, so `wdio`
// will be called from there.
//
specs: [join(process.cwd(), "./tests/suites/MainTests/01-UplinkTests.suite.ts")],
specs: [
join(process.cwd(), "./tests/suites/MainTests/01-UplinkTests.suite.ts"),
],
// Patterns to exclude.
exclude: [
// 'path/to/excluded/files'
// 'path/to/excluded/files'
],
//
// ============
Expand All @@ -47,50 +49,55 @@ export const config: WebdriverIO.Config = {
// https://docs.saucelabs.com/reference/platforms-configurator
//
port: 4723,
path: '/',
capabilities: {
userA: {
capabilities: {
platformName: "mac",
"appium:automationName": MACOS_DRIVER,
"appium:bundleId": MACOS_BUNDLE_ID,
"appium:arguments": ["--discovery", "disable", "--path", homedir() + "/.uplink"],
"appium:systemPort": 4724,
"appium:prerun": {
command: 'do shell script "rm -rf ~/.uplink"',
},
}
path: "/",
capabilities: [
{
platformName: "mac",
"appium:automationName": MACOS_DRIVER,
"appium:bundleId": MACOS_BUNDLE_ID,
"appium:arguments": [
"--discovery",
"disable",
"--path",
homedir() + "/.uplink",
],
"appium:systemPort": 4724,
"appium:prerun": {
command: 'do shell script "rm -rf ~/.uplink"',
},
},
}
,
],
//
// ===================
// Test Configurations
// ===================
// Define all options that are relevant for the WebdriverIO instance here
//
reporters: [
["spec",
[
"spec",
{
showPreface: false,
},
],
['allure',
],
[
"allure",
{
outputDir: './allure-results',
outputDir: "./allure-results",
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: false,
}
},
],
['junit',
[
"junit",
{
outputDir: './test-report/',
outputDir: "./test-report/",
outputFileFormat: function (options) {
return `test-results-macos-app-${options.cid}.xml`;
}
}
},
},
],
],
],
//
// =====
// Hooks
Expand All @@ -99,48 +106,51 @@ export const config: WebdriverIO.Config = {
// it and to build services around it. You can either apply a single function or an array of
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
// resolved to continue.
onPrepare: async function() {
onPrepare: async function () {
const cacheFolder = homedir() + "/.uplink/.user";
const allureResultsFolder = join(process.cwd(), "./allure-results");
const testReportFolder = join(process.cwd(), "./test-report");
const testResultsFolder = join(process.cwd(), "./test-results");
const testReportFolder = join(process.cwd(), "./test-report");
const testResultsFolder = join(process.cwd(), "./test-results");
try {
await rmSync(allureResultsFolder, { recursive: true, force: true });
await rmSync(testReportFolder, { recursive: true, force: true });
await rmSync(testResultsFolder, { recursive: true, force: true });
console.log("Deleted Artifacts Folders Successfully!");
} catch (error) {
console.error(
`Got an error trying to delete artifacts folders: ${error.message}`
`Got an error trying to delete artifacts folders: ${error.message}`,
);
}
try {
await rmSync(cacheFolder, { recursive: true, force: true });
console.log("Deleted Cache Folder Successfully!");
} catch (error) {
console.error(
`Got an error trying to delete Cache Folder: ${error.message}`
`Got an error trying to delete Cache Folder: ${error.message}`,
);
}
},

afterTest: async function (test, describe, { error }) {
if (error) {
let imageFile = await driver.takeScreenshot();
const imageFolder = join(process.cwd(), "./test-results/macos-app", test.parent);
const imageTitle = test.title + " - Failed.png"
await fsp.mkdir(imageFolder, {recursive: true});
const imageFolder = join(
process.cwd(),
"./test-results/macos-app",
test.parent,
);
const imageTitle = test.title + " - Failed.png";
await fsp.mkdir(imageFolder, { recursive: true });
await fsp.writeFile(
imageFolder + "/" + imageTitle,
imageFile,
"base64"
"base64",
);

// Add to Screenshot to Allure Reporter
const data = await readFileSync(`${imageFolder}/${imageTitle}`);
allureReporter.addAttachment(imageTitle, data, 'image/png')
allureReporter.addAttachment(imageTitle, data, "image/png");
}
},
}

}
},
};
118 changes: 64 additions & 54 deletions config/wdio.mac.ci.conf.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
require("module-alias/register");
const allureReporter = require('@wdio/allure-reporter').default;
const sharedConfig = require('@config/wdio.shared.conf.ts').config;
const allureReporter = require("@wdio/allure-reporter").default;
const sharedConfig = require("@config/wdio.shared.conf.ts").config;
const homedir = require("os").homedir;
const join = require("path").join;
const MACOS_BUNDLE_ID = require("@helpers/constants").MACOS_BUNDLE_ID;
const MACOS_DRIVER = require("@helpers/constants").MACOS_DRIVER;
const fsp = require("fs").promises;
const { readFileSync, rmSync } = require("fs");

// @ts-expect-error
export const config: WebdriverIO.Config = {
...sharedConfig,
...sharedConfig,
...{
//
// ==================
Expand All @@ -28,10 +27,12 @@ export const config: WebdriverIO.Config = {
// then the current working directory is where your `package.json` resides, so `wdio`
// will be called from there.
//
specs: [join(process.cwd(), "./tests/suites/MainTests/01-UplinkTests.suite.ts")],
specs: [
join(process.cwd(), "./tests/suites/MainTests/01-UplinkTests.suite.ts"),
],
// Patterns to exclude.
exclude: [
// 'path/to/excluded/files'
// 'path/to/excluded/files'
],
//
// ============
Expand All @@ -47,22 +48,24 @@ export const config: WebdriverIO.Config = {
// https://docs.saucelabs.com/reference/platforms-configurator
//
port: 4723,
path: '/',
capabilities: {
userA: {
capabilities: {
platformName: "mac",
"appium:automationName": MACOS_DRIVER,
"appium:bundleId": MACOS_BUNDLE_ID,
"appium:arguments": ["--discovery", "disable", "--path", homedir() + "/.uplink"],
"appium:systemPort": 4724,
"appium:prerun": {
command: 'do shell script "rm -rf ~/.uplink"',
},
}
path: "/",
capabilities: [
{
platformName: "mac",
"appium:automationName": MACOS_DRIVER,
"appium:bundleId": MACOS_BUNDLE_ID,
"appium:arguments": [
"--discovery",
"disable",
"--path",
homedir() + "/.uplink",
],
"appium:systemPort": 4724,
"appium:prerun": {
command: 'do shell script "rm -rf ~/.uplink"',
},
},
}
,
],
//
// ===================
// Test Configurations
Expand All @@ -72,27 +75,30 @@ export const config: WebdriverIO.Config = {
// The only one supported by default is 'dot'
// see also: https://webdriver.io/docs/dot-reporter
reporters: [
["spec",
[
"spec",
{
showPreface: false,
},
],
['allure',
],
[
"allure",
{
outputDir: './allure-results',
outputDir: "./allure-results",
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: false,
}
},
],
['junit',
[
"junit",
{
outputDir: './test-report/',
outputDir: "./test-report/",
outputFileFormat: function (options) {
return `test-results-macos-ci-${options.cid}.xml`;
}
}
},
},
],
],
],
//
// =====
// Hooks
Expand All @@ -101,50 +107,54 @@ export const config: WebdriverIO.Config = {
// it and to build services around it. You can either apply a single function or an array of
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
// resolved to continue.
onPrepare: async function() {
onPrepare: async function () {
const cacheFolder = homedir() + "/.uplink/.user";
const allureResultsFolder = join(process.cwd(), "./allure-results");
const testReportFolder = join(process.cwd(), "./test-report");
const testResultsFolder = join(process.cwd(), "./test-results");
const testReportFolder = join(process.cwd(), "./test-report");
const testResultsFolder = join(process.cwd(), "./test-results");
try {
await rmSync(allureResultsFolder, { recursive: true, force: true });
await rmSync(testReportFolder, { recursive: true, force: true });
await rmSync(testResultsFolder, { recursive: true, force: true });
console.log("Deleted Artifacts Folders Successfully!");
} catch (error) {
console.error(
`Got an error trying to delete artifacts folders: ${error.message}`
`Got an error trying to delete artifacts folders: ${error.message}`,
);
}
try {
await rmSync(cacheFolder, { recursive: true, force: true });
console.log("Deleted Cache Folder Successfully!");
} catch (error) {
console.error(
`Got an error trying to delete Cache Folder: ${error.message}`
`Got an error trying to delete Cache Folder: ${error.message}`,
);
}
},
/**
* Function to be executed after a test (in Mocha/Jasmine).
*/
afterTest: async function (test, describe, { error }) {
if (error) {
// If test fails, take a screenshot, make a folder with the test name and save it there
let imageFile = await driver.takeScreenshot();
const imageFolder = join(process.cwd(), "./test-results/macos-ci", test.parent);
const imageTitle = test.title + " - Failed.png";
await fsp.mkdir(imageFolder, {recursive: true});
await fsp.writeFile(
imageFolder + "/" + imageTitle,
imageFile,
"base64"
);
if (error) {
// If test fails, take a screenshot, make a folder with the test name and save it there
let imageFile = await driver.takeScreenshot();
const imageFolder = join(
process.cwd(),
"./test-results/macos-ci",
test.parent,
);
const imageTitle = test.title + " - Failed.png";
await fsp.mkdir(imageFolder, { recursive: true });
await fsp.writeFile(
imageFolder + "/" + imageTitle,
imageFile,
"base64",
);

// Add to Screenshot to Allure Reporter
const dataImage = await readFileSync(`${imageFolder}/${imageTitle}`);
allureReporter.addAttachment(imageTitle, dataImage, 'image/png')
}
},
}
}
// Add to Screenshot to Allure Reporter
const dataImage = await readFileSync(`${imageFolder}/${imageTitle}`);
allureReporter.addAttachment(imageTitle, dataImage, "image/png");
}
},
},
};
Loading

0 comments on commit 1edcde0

Please sign in to comment.