Closed thomasklaush closed 1 year ago
@Dileep17
Hi @thomasklaush Good Day!
I tested the plugin with appium 2.0.0 with the sample java implementation in the repo [test/AppiumReportPluginDemo]. Report generated don't have duplicate entries!
It would help if you could you share more details of implementation, sample code.
I added the test function in the after Test section of wdio config:
/**
* Function to be executed after a test (in Mocha/Jasmine).
*/
afterTest: async function (
test,
context,
{ error, result, duration, passed, retries }
) {
if (activateAppiumReporter) {
await setTestInfo(`${test.title} in ${duration / 1000} s`, passed, error)
}
},
The Function is defined in the file. To work properly and get driver session, I had to define it globally.
// api call to setTestinfo binding is made with params
async function setTestInfo(testName, boolTestStatus, error) {
console.log('setTestInfo: %s', testName)
let testStatus = 'FAILED'
if (boolTestStatus) {
testStatus = 'PASSED'
}
global.setTestInfoGlobal(testName, testStatus, error)
}
Global inits:
/**
* Gets executed before test execution begins. At this point you can access to all global
* variables like `browser`. It is the perfect place to define custom commands.
* @param {Array.<Object>} capabilities list of capabilities details
* @param {Array.<String>} specs List of spec file paths that are to be run
*/
before: async function (capabilities, specs) {
const sessionId = driver.sessionId
global.getReportGlobal = async function (currentOS) {
const url = 'http://127.0.0.1:4723/getReport'
// await new Promise((resolve) => setTimeout(resolve, 5000))
const response = await fetch(url)
console.log(response)
const data = await response.text()
// console.log(data)
// return data
console.log('deleteReportData')
const urlD = 'http://127.0.0.1:4723/deleteReportData'
await fetch(urlD, { method: 'DELETE' })
// Create Report File
const fileName = `Report_${currentOS}`
// const fileName = 'Report'
console.log('createReportFile')
fs.writeFile(`./${fileName}.html`, data, 'utf-8', (err) => {
if (err) throw err
})
return data
}
// api call to setTestinfo binding is made with params
global.setTestInfoGlobal = async function (testName, testStatus, error) {
console.log(
'setTestInfo: %s with id: %s Result: %s',
testName,
sessionId,
testStatus
)
const url = 'http://127.0.0.1:4723/setTestInfo'
const reqBody = {}
reqBody.sessionId = sessionId
reqBody.testName = testName
reqBody.testStatus = testStatus
reqBody.error = error
console.log(reqBody)
await fetch(url, {
method: 'post',
body: JSON.stringify(reqBody),
headers: { 'Content-Type': 'application/json' }
})
// console.log(response)
}
},
@thomasklaush As of now, report plugin uses sessionID as primary key to differentiate tests. AFAIK wdio reuses same driver session if not explicitly reset. Could you make below changes and check the report ?
before
and used in global.setTestInfoGlobal
. Instead, in afterTest
get sessionID and pass it as an argument to setTestInfoGlobal
. await driver.reloadSession();
after setTestInfoGlobal
call in afterTest
After making changes, Im able to see links as expected. Please make the changes and let me know the result.
Thanks for the suggestion.
To use it, I would have to redesign my tests.
await driver.reloadSession(); triggers a complete newstart of the App.
So I would have to do the complete login and onboarding process for each test, which is not possible since it would make the test about 20 times slower.
@Dileep17 I made just the other changes you've recommended, and now at least a few of the entries are changing. Unfortunately now some data is wrong. I will try to get a deeper look into it.
@thomasklaush It's an pre-requisite for the report plugin that tests are independent and each test has unique driver session. Its interesting to think on how to extend report plugin for other cases.
Unfortunately now some data is wrong.
-- Im curious to know them. knowing and fixing them would help others using the plugin. Please share them.
@Dileep17 the wrong data was a one time thing, no issue
In a sequential app test, I cannot start the app over again.
The consequence would be to summarize at least one feature in one test.
If I test a feature, I have currently several tests, several screens.
So unfortunately not applicable.
Additionally, I have to do the login over again inclusive onboarding, since the app gets reset.
So would be cool to add a possibility to do that.
I will use it further with the wrong overview on the side menu, since basic information stays correct.
Anyway, nice tool and I really appreciate your work!
@thomasklaush Could you install 1.1.0-beta.02
latest
and check if things are working fine for you use-case ?
With this version, same session can be used by multiple tests. PR #137
@Dileep17 thanks, solved the issue
In the clickable overview on the left side, only the first test is shown over again.
Mobile testing with appium 2.0.0 and last reporter version.