Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saikrishna321/eaef2c7be5f5e55caed649c1da65daec to your computer and use it in GitHub Desktop.
Save saikrishna321/eaef2c7be5f5e55caed649c1da65daec to your computer and use it in GitHub Desktop.
ios-wdio-perfecto-config
const path = require('path');
const opener = require('opener');
const Reporting = require('perfecto-reporting');
var reportingClient;
//1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com).
const host = 'trial';
// 2. Replace <<security token>> with your perfecto security token.
const securityToken = '';
//Define your global tags here:
const tags = ['SampleTag1'];
global.STEP_TIMEOUT = 900000;
global.IMPLICIT_TIMEOUT = 5000;
global.progressBar = new ProgressBar(10);
exports.config = {
securityToken: securityToken,
protocol: 'http',
hostname: host + '.perfectomobile.com',
path: '/nexperience/perfectomobile/wd/hub',
port: 80,
sync: true,
bail: 0,
exclude: [],
specs: [
'ios/native.js'
],
maxInstances: 1,
capabilities: [
{
securityToken: securityToken,
automationName: 'Appium',
// 3. Set device capabilities.
platformName: 'iOS',
platformVersion: '14.3',
manufacturer: 'Apple',
model: 'iPhone-11 Pro',
// 4. Set Perfecto Media repository path of App under test.
app: 'PUBLIC:InvoiceApp1.0.ipa',
// 5. Set the unique identifier of your app
bundleId: 'io.perfecto.expense.tracker',
autoLaunch: true, // Whether to have Appium install and launch the app automatically.
autoInstrument: true, // To work with hybrid applications, install the iOS/Android application as instrumented.
// fullReset: false, // Reset app state by uninstalling app
browserName: '',
takesScreenshot: false,
screenshotOnError: true,
openDeviceTimeout: 5
},
],
// Default timeout for all waitFor* commands.
waitforTimeout: 30000,
// Default timeout in milliseconds for request
// if Selenium Grid doesn't send response
connectionRetryTimeout: 90000,
// Default request retries count
connectionRetryCount: 3,
framework: 'jasmine',
// Options to be passed to Jasmine.
jasmineNodeOpts: {
// Jasmine default timeout
defaultTimeoutInterval: 100000,
// The Jasmine framework allows interception of each assertion in order to log the state of the application
// or website depending on the result. For example, it is pretty handy to take a screenshot every time
// an assertion fails.
expectationResultHandler: function (passed, assertion) {
// do something
}
},
reporters: ['spec'],
// Set log level to 'error'
logLevel: 'info',
logLevels: {
webdriver: 'error',
webdriverio: 'error',
'@wdio/local-runner': 'error',
'@wdio/cli': 'error'
},
//
// =====
// Hooks
// =====
// Gets executed just before initializing the webdriver session.
beforeSession: function (config, capabilities, specs) {
// Update progress to the first step
setTimeout(() => {
global.progressBar.step();
}, 2000, global);
},
// Gets executed before test execution begins. At this point you can access all global
// variables, such as `browser`. It is the perfect place to define custom commands.
before: function (capabilities, specs) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000;
if (process.env.jobName != null) {
reportingClient = new Reporting.Perfecto.PerfectoReportingClient(new Reporting.Perfecto.PerfectoExecutionContext({
webdriver: {
executeScript: (command, params) => {
return browser.execute(command, params);
}
},
job: new Reporting.Model.Job({
jobName: process.env.jobName,
buildNumber: parseInt(process.env.jobNumber)
}),
tags: tags
}));
} else {
reportingClient = new Reporting.Perfecto.PerfectoReportingClient(new Reporting.Perfecto.PerfectoExecutionContext({
webdriver: {
executeScript: (command, params) => {
return browser.execute(command, params);
}
},
tags: tags
}));
}
browser.reportingClient = reportingClient;
browser.progressBar = global.progressBar;
var myReporter = {
specStarted: function (result) {
reportingClient.testStart(result.fullName);
},
specDone: async function (result) {
if (result.status === 'failed') {
const failure = await result.failedExpectations[result.failedExpectations.length - 1];
await reportingClient.testStop({
status: Reporting.Constants.results.failed,
message: `${failure.message} ${failure.stack}`
});
} else {
await reportingClient.testStop({
status: Reporting.Constants.results.passed
});
}
}
}
jasmine.getEnv().addReporter(myReporter);
},
// Gets executed right after terminating the webdriver session.
afterSession: async function (config, capabilities, specs) {
const reportURL = browser.capabilities['testGridReportUrl'] + "&onboardingJourney=automated&onboardingDevice=nativeApp";
// Launch browser with the Report URL
browser.progressBar.finish();
opener(reportURL);
await new Promise((resolve) => setTimeout(resolve, 3000)); // Wait for report url to open
console.log(`\n\nOpen this link to continue with the guide: ${reportURL}\n`);
}
}
function ProgressBar(numSteps) {
this.currentStep = 0;
this.tickSize = 5;
this.paddingSize = 21;
this.totalSteps = numSteps;
this.step = function() {
this.setProgress(this.currentStep + 1);
}
this.finish = function() {
this.setProgress(this.totalSteps);
}
this.setProgress = function (value) {
const repeatCharacter = (character, times) => character.repeat(times)
if (this.currentStep === 0 || this.currentStep === this.totalSteps) {
process.stdout.write('\n\n');
}
this.currentStep = value;
const completed = repeatCharacter('=', this.currentStep * this.tickSize);
const remaining = repeatCharacter(' ', (this.totalSteps - this.currentStep) * this.tickSize);
const progress = parseInt(this.currentStep / this.totalSteps * 100) + '%';
const padding = repeatCharacter(' ', this.paddingSize);
process.stdout.write(`\r[${completed}${remaining}] ${progress}${padding}`);
}
}
@saikrishna321
Copy link
Author

android

const path = require("path");
const opener = require("opener");
const Reporting = require("perfecto-reporting");
var reportingClient;
//1. Replace <> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com).
const host = "trial";
// 2. Replace <> with your perfecto security token.
const securityToken =
"";

//Define your global tags here:
const tags = ["SampleTag1"];
global.STEP_TIMEOUT = 900000;
global.IMPLICIT_TIMEOUT = 5000;
global.progressBar = new ProgressBar(10);

exports.config = {
securityToken: securityToken,
protocol: "http",
hostname: host + ".perfectomobile.com",
path: "/nexperience/perfectomobile/wd/hub",
port: 80,
sync: true,
bail: 0,
exclude: [],
specs: ["ios/native-android.js"],
maxInstances: 1,

capabilities: [
{
securityToken: securityToken,
automationName: "Appium",
// 3. Set device capabilities.
platformName: "Android",
platformVersion: "9",
location: "NA-US-BOS",
resolution: "1440x3040",
manufacturer: "Samsung",
model: "Galaxy S10\+",

  // 4. Set Perfecto Media repository path of App under test.
  app: "PUBLIC:ExpenseAppVer1.0.apk",
  autoLaunch: true, // Whether to have Appium install and launch the app automatically.
  autoInstrument: true, // To work with hybrid applications, install the iOS/Android application as instrumented.
  // fullReset: false, // Reset app state by uninstalling app
  browserName: "",
  takesScreenshot: false,
  screenshotOnError: true,
  openDeviceTimeout: 5,
},

],
// Default timeout for all waitFor* commands.
waitforTimeout: 30000,
// Default timeout in milliseconds for request
// if Selenium Grid doesn't send response
connectionRetryTimeout: 90000,
// Default request retries count
connectionRetryCount: 3,
framework: "jasmine",
// Options to be passed to Jasmine.
jasmineNodeOpts: {
// Jasmine default timeout
defaultTimeoutInterval: 100000,
// The Jasmine framework allows interception of each assertion in order to log the state of the application
// or website depending on the result. For example, it is pretty handy to take a screenshot every time
// an assertion fails.
expectationResultHandler: function (passed, assertion) {
// do something
},
},
reporters: ["spec"],

// Set log level to 'error'
logLevel: "info",
logLevels: {
webdriver: "error",
webdriverio: "error",
"@wdio/local-runner": "error",
"@wdio/cli": "error",
},

//
// =====
// Hooks
// =====
// Gets executed just before initializing the webdriver session.
beforeSession: function (config, capabilities, specs) {
// Update progress to the first step
setTimeout(
() => {
global.progressBar.step();
},
2000,
global
);
},
// Gets executed before test execution begins. At this point you can access all global
// variables, such as browser. It is the perfect place to define custom commands.
before: function (capabilities, specs) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000;
if (process.env.jobName != null) {
reportingClient = new Reporting.Perfecto.PerfectoReportingClient(
new Reporting.Perfecto.PerfectoExecutionContext({
webdriver: {
executeScript: (command, params) => {
return browser.execute(command, params);
},
},
job: new Reporting.Model.Job({
jobName: process.env.jobName,
buildNumber: parseInt(process.env.jobNumber),
}),
tags: tags,
})
);
} else {
reportingClient = new Reporting.Perfecto.PerfectoReportingClient(
new Reporting.Perfecto.PerfectoExecutionContext({
webdriver: {
executeScript: (command, params) => {
return browser.execute(command, params);
},
},
tags: tags,
})
);
}
browser.reportingClient = reportingClient;
browser.progressBar = global.progressBar;

var myReporter = {
  specStarted: function (result) {
    reportingClient.testStart(result.fullName);
  },
  specDone: async function (result) {
    if (result.status === "failed") {
      const failure = await result.failedExpectations[
        result.failedExpectations.length - 1
      ];
      await reportingClient.testStop({
        status: Reporting.Constants.results.failed,
        message: `${failure.message} ${failure.stack}`,
      });
    } else {
      await reportingClient.testStop({
        status: Reporting.Constants.results.passed,
      });
    }
  },
};
jasmine.getEnv().addReporter(myReporter);

},
// Gets executed right after terminating the webdriver session.
afterSession: async function (config, capabilities, specs) {
const reportURL =
browser.capabilities["testGridReportUrl"] +
"&onboardingJourney=automated&onboardingDevice=nativeApp";

// Launch browser with the Report URL
browser.progressBar.finish();
opener(reportURL);
await new Promise((resolve) => setTimeout(resolve, 3000)); // Wait for report url to open

console.log(
  `\n\nOpen this link to continue with the guide: ${reportURL}\n`
);

},
};

function ProgressBar(numSteps) {
this.currentStep = 0;
this.tickSize = 5;
this.paddingSize = 21;
this.totalSteps = numSteps;

this.step = function () {
this.setProgress(this.currentStep + 1);
};

this.finish = function () {
this.setProgress(this.totalSteps);
};

this.setProgress = function (value) {
const repeatCharacter = (character, times) => character.repeat(times);

if (this.currentStep === 0 || this.currentStep === this.totalSteps) {
  process.stdout.write("\n\n");
}

this.currentStep = value;
const completed = repeatCharacter("=", this.currentStep * this.tickSize);
const remaining = repeatCharacter(
  " ",
  (this.totalSteps - this.currentStep) * this.tickSize
);
const progress = parseInt((this.currentStep / this.totalSteps) * 100) + "%";
const padding = repeatCharacter(" ", this.paddingSize);
process.stdout.write(`\r[${completed}${remaining}] ${progress}${padding}`);

};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment