I am working on a protractor typescript testing framework and would like to run tests in different environments depending upon the env specific params that I send in CLI. For example: I want to run my test as "npm test SIT" or "npm test dit". The base url picks the url for SIT in case 1 and DIT in case2 to launch the application in different SIT and DIT environments.
I have made a file name Url.js(root/ data/ Url.js)
'use strict';
var env = browser.params.environment;
module.exports = {
baseURL: function() {
var baseUrl = '';
if (env.toLowerCase().indexOf('sit') === -1) {
baseUrl = 'https://'+env+'-site.com/app/home';
} else if(env.toLowerCase().indexOf('dit') === -1){
baseUrl = 'https://'+env+'-site.com/app/home';
} else if(env.toLowerCase().indexOf('rit') === -1){
baseUrl = 'https://'+env+'-site.com/app/home';
}
return baseUrl;
},
internalPage1: 'app/page/details/fff/ttt.html'
};
Here is my config.ts
let path = require('path');
import { browser, Config } from "protractor";
import { Reporter } from "../support/reporter";
import * as oracledb from 'oracledb';
const jsonReports = process.cwd() + "/reports/json";
export const config: Config = {
params:{
environment: 'fdi', //dit or rit can be passed from cmd line
},
seleniumAddress: "http://localhost:4444/wd/hub",
SELENIUM_PROMISE_MANAGER: false,
capabilities: {
browserName: 'chrome',
maxInstances: 6
},
framework: "custom",
frameworkPath: require.resolve("protractor-cucumber-framework"),
specs: [
"../../features/automation/regression/*.feature",
],
onPrepare: () => {
browser.ignoreSynchronization = true;
browser.manage().timeouts().implicitlyWait(12000);
browser.manage().window().maximize();
Reporter.createDirectory(jsonReports);
},
cucumberOpts: {
compiler: "ts:ts-node/register",
format: "json:./reports/json/cucumber_report.json",
require: ["../../typeScript/stepdefinitions/*.js",
"../../typeScript/support/*.js",
"../../dbUtils/index"],
strict: true,
tags: "@dataTable",
restartBrowserBetweenTests: true
},
onComplete: () => {
Reporter.createHTMLReport();
},
};
Cucumber hooks:
const { BeforeAll, After, AfterAll, Status, setDefaultTimeout, Before } = require("cucumber");
import * as fs from "fs";
import { browser } from "protractor";
import { config } from "../config/config";
import { build$ } from "protractor/built/element";
var env = browser.params.environment;
//setDefaultTimeout(600 * 1000);
Before(async function () {
await browser.get(env);
});
After(async function(scenario) {
if (scenario.result.status === Status.FAILED) {
// screenShot is a base-64 encoded PNG
const screenShot = await browser.takeScreenshot();
this.attach(screenShot, "image/png");
}
});
AfterAll(async () => {
await browser.quit();
});
I dont know if I should call Url.js in my config.ts, I think I do but I am not sure how that could be done. Could someone give me some pointers as to who I can nail this down?
Aucun commentaire:
Enregistrer un commentaire