tetest-js v1.5.4
Information
TeTest-js is a plugin for user to build the connection to Te-Test testing platform.
Table of Contents
Install
npm:
npm install tetest-js -save
Protractor with Cucumber
Node
Create a new js file and save in your project folder.
const { TeTest, TeWordConstructor } = require('tetest-js'); const TeTestConfit = { server: "https://te-testDemo.cn", token: "[Your Token]", project: "[Yor Project Name]", taskID: "", buildID: "", reportGroup: "", timeSpan: Date.now(), cucumber: { reportPath: "./tmp/cucumber_test.json", reportNameWithPid:true }, paramerter: {}, taskInfo: {}, jobInfo: {} }; const TeTestObj = new TeTest(TeTestConfit);
//Extend to Cucumber: const { defineSupportCode, setWorldConstructor } = require('cucumber'); defineSupportCode(TeTestObj.cucumber.supportCode); setWorldConstructor(TeWordConstructor);
### Configration
```js
{
server: "https://te-testDemo.cn", // Server Name
token: "[Your Token]", // User token in server, you can get from the profile settings.
project: "[Yor Project Name]", // Project Name in Te-Test
taskID: "", // [Optional] Task id in your project
buildID: "", // [Optional] This build ID will be used in clent agent when executing.
reportGroup: "", // [Optional] [Default='TeTest-LocalTest'] Report Group name,
timeSpan: Date.now(), // [Optional] This is used for get task to check if case in same serniral.
cucumber: { // For Cucumber + Protractor framework
reportPath: "./tmp/cucumber_test.json", //Report path, this should be same as Cucumber JSON out path.
reportNameWithPid: true, // [Optional] [Default=true] When you are using Protractor and want to get the unit report that named with process.pid, you should follow bellow setting for Protractor config file in your Protractor settings:
// {
// capabilities: {
// count: 1, //or more
// shardTestFiles: true,
// },
// plugins: [{
// package: 'protractor-multiple-cucumber-html-reporter-plugin',
// options: {
// automaticallyGenerateReport: true,
// removeExistingJsonReportFile: true,
// }
// ]
// }
// }
paramerter: {}, //[Optional] Parameters from TeTest server task
taskInfo: {}, //[Optional] Task information
jobInfo: {} //[Optional] When task is executing in client, server will send this task and job information to script for execution.
}
}
Multiple World Constructor
Cucumber can only set 1 world constructor, when you have your customize world, you can follow code below:
let TeTestObj = new TeTest(TeTestConfit); defineSupportCode(TeTestObj.cucumber.supportCode); class ExtendTeWordConstructor{ constructor() { this.tetest = TeTestObj.cucumber.teWroldObj; this.yourWorldEntry= new YourClass(); } } setWorldConstructor(ExtendTeWordConstructor);
Supported Agent
Cucumber
v6.0.5+ User should add json formater in command.
cucumber -f json -o ./tmp/cucumber_test.json
Protractor
v7.0.0+ Add the Cucumber options if using Cucumber.
cucumberOpts: { format: 'json:./tmp/cucumber_test.json', }
Cucmber Word API
More comments are coming.....sorry for this inconvenient.
addProjectData = async (tableName, bodyJSON, projectName) => {
}
addMasterData = async (tableName, bodyJSON, projectName) => {
}
getProjectData = async (tableName, queryJSON, projectName) => {
}
getMasterData = async (tableName, queryJSON, projectName) => {
}
getCaseData = async (caseName, projectName) => {
}
getSecretCaseData = async (dataName, projectName) => {
}
getGlobalCaseData = async (projectName) => {
}
updateProjectData = async (tableName, id, data, projectName) => {
}
updateMasterData = async (tableName, bodyJSON, projectName) => {
}
updateCaseData = async (caseName, data, projectName) => {
}
updateGlobalCaseData = async (data, projectName) => {
}
uploadJSONReport = async (reportJson, groupName, projectName) => {
}
converJsonToQueryString = async (tableName, bodyJSON, projectName) => {
}
isE2E = ()=>{}
Cypress with Cucumber
1. Support Feature in Cypress
We need to add our support feature into cypress by confige the cypress.json. Create a new teTest.js file and save in your support folder.
//cypress confige file
{
"supportFile": "support",
}
//[your project]/support/index.js in your support folder,
import './teTest';
//[your project]/support/teTest.js
const TeTestConfig = {
server: "https://te-testDemo.cn",
token: "[Your Token]",
project: "[Yor Project Name]",
taskID: "",
buildID: "",
reportGroup: "",
timeSpan: Date.now(),
cypress: {
reportPath: "./reports/json",
screenshotsFolder:"screenshots",
videosFolder: "videos"
},
paramerter: {},
taskInfo: {},
jobInfo: {}
};
console.log("In TE plugin");
before(() => {
cy.task('TE:initTE', TeTestConfig).then((config) => {
TeTestConfig = config;
const {
CyPressWord
} = require('tetest-js');
let cyWord = new CyPressWord();
cy.tetest = cyWord;
cy.tetestConfig = TeTestConfig;
});
})
after(() => {
cy.task('TE:after').then((res) => {
console.log(res.error ? res.error : "Updated Report");
});
})
afterEach(function () {
let scenario = this.currentTest.title ? this.currentTest.title : "unknown";
let feature = this.currentTest.parent &&
this.currentTest.parent.parent &&
this.currentTest.parent.parent.file ? this.currentTest.parent.parent.file : "unknown";
cy.task('TE:afterEach', {
scenario,
feature
}).then(() => {
console.log("Update TE Testing Data");
});
});
2. Add our plug-in in Cypress
We need to add our plug-ib into cypress by confige the cypress.json.
//cypress confige file
{
"supportFile": "support",
"pluginsFile": "library",
}
//[your project]/library/index.js in your support folder,
const {
TECyPressTask
} = require('tetest-js');
module.exports = (on, config) => {
TECyPressTask(on, config);
}
3. Code sampe in your test.
The keyword method like protractor. But we need use cy.tetest to invoke the method.
//Get Global case Data cy.tetest.getGlobalCaseData("[your project name]").then(result => { //Get Table Data in Project cy.tetest.getProjectData("[your table name]").then(re=>{ console.log(re); }) })
4. If you have the cypress_run.js start file
Some framework will use the cypress api to launch the Cypress execution. So we need to add the paramter for TE by process.env.
//cypress_run.js
const {
getProcessParameter
} = require('../TE/tejs');
//Add command parameter to Env
process.env.tetest = JSON.stringify(getProcessParameter());
5. E2E testing code sample
E2E to slimulate the data flow bewteen 2 different project
import {
Given,
Then
} from "cypress-cucumber-preprocessor/steps";
Given('I create a new post body save in Table_Name table for E2E testing', () => {
cy.tetest.isE2E().then(isE2E => {
cy.tetest.addProjectData("Table_Name", {
part: "1234567890" + Date.now(),
quantity: 1,
count: 1
}, "YourProject", isE2E).then(res => {
cy.task('log', "Create E2E Data: " + JSON.stringify(res));
});
});
})
Given('I get E2E testing data from Table_Name table', () => {
cy.tetest.isE2E().then(isE2E => {
debugger
cy.task('log', "IsE2E:"+isE2E);
cy.tetest.getProjectData("Table_Name", {}, "YourProject", isE2E).then(res => {
cy.task('log', "Get E2E Data: " + JSON.stringify(res));
cy.wrap(res).as("E2EData");
});
});
})
Then('I update this test data back to TE', () => {
debugger
cy.get('@E2EData').then(E2EData => {
//update some field in data body
E2EData.body.data.quantity = 2;
debugger
cy.tetest.updateProjectData("Table_Name",
E2EData.body._id,
E2EData.body.data,
"YourProject").then(res => {
cy.task('log', "Update E2E Data: " + JSON.stringify(res));
});
});
})
Reporting
Cucumber report
You will need to implement your own formatter which inherits the TE event formatter for different version of cucumber in order to sync up report back to TE
Cucumber version 7 and 7+
You will need to inherit newTeEventFormatter
const TeFormatter = require('tetest-js/cucumber/newTeEventFormatter'); //get TE configuration which contains all TE server info const config = { server: '', token: '', project: '', taskID: '', buildID: '', reportGroup: '', timeSpan: Date.now(), paramerter: {}, taskInfo: {}, jobInfo: {}, data: [] }
class MyTeFormatter extends TeFormatter { constructor(options) { super(options, config); }
} exports.default = MyTeFormatter;
In your cucumber options you will need to add following
```json
cucumberOpts: {
format: ['path to MyTeFormatter and with suffix :./test']
}
Or you could use cucumber CLI paramter to pass the customized formatter
Cucumber version 6 and below
You will need to inherit legacyTeEventFormatter
const TeFormatter = require('tetest-js/cucumber/legacyTeEventFormatter');
//get TE configuration which contains all TE server info
const config = {
server: '',
token: '',
project: '',
taskID: '',
buildID: '',
reportGroup: '',
timeSpan: Date.now(),
paramerter: {},
taskInfo: {},
jobInfo: {},
data: []
}
class MyTeFormatter extends TeFormatter {
constructor(options) {
super(options, config);
}
}
exports.default = MyTeFormatter;
In your cucumber options you will need to add following
cucumberOpts: {
format: ['path to MyTeFormatter']
}
Or you could use cucumber CLI paramter to pass the customized formatter
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago