-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(#6669): Search by barcode e2e test #8732
Changes from 23 commits
13c3ac3
a911fd7
d3acd96
0aa9383
5fe218b
81214ef
cddc9e9
24a6625
ce30fe8
81f20d3
47006f9
8232a63
3a3c387
b2567f5
01eb63c
450e230
317c9ee
87a2c7b
736bfb9
5394762
ba67a60
dd26bd2
8caddd5
efdee66
9d7ff21
b61e649
02a9426
6922011
4ec94f1
afa0041
cf7592a
4c22f3a
8ac8efb
57446eb
b65eaf3
b45e15b
4e351d3
58874dc
5f08fa7
3aa6210
995590e
a263189
a728edf
1e0992c
48e6fbc
81306ac
b279780
1a4599b
509cab6
03e7233
b2c57b1
f8d8e3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const searchPage = require('@page-objects/default-mobile/search/search.wdio.page.js'); | ||
const loginPage = require('@page-objects/default/login/login.wdio.page'); | ||
const utils = require('@utils'); | ||
const contactPage = require('@page-objects/default/contacts/contacts.wdio.page'); | ||
const commonPage = require('@page-objects/default/common/common.wdio.page'); | ||
const placeFactory = require('@factories/cht/contacts/place'); | ||
const personFactory = require('@factories/cht/contacts/person'); | ||
const userFactory = require('@factories/cht/users/users'); | ||
const path = require('path'); | ||
|
||
const places = placeFactory.generateHierarchy(); | ||
const healthCenter = places.get('health_center'); | ||
const offlineUser = userFactory.build({ place: healthCenter._id, roles: ['chw'] }); | ||
const person = personFactory.build({ | ||
patient_id: '123456', | ||
parent: { _id: healthCenter._id, parent: healthCenter.parent } | ||
}); | ||
const barcodeImagePath = path.join(__dirname, '/images/valid-barcode.gif'); | ||
const invalidBarcodeImagePath = path.join(__dirname, '/images/invalid-barcode.jpg'); | ||
|
||
describe('Test Contact Search with Barcode Scanner', async () => { | ||
before(async () => { | ||
await utils.saveDocs([...places.values(), person]); | ||
await utils.createUsers([offlineUser]); | ||
const canUseBarcodeScannerPermission = ['can_use_barcode_scanner']; | ||
await utils.updatePermissions(offlineUser.roles, canUseBarcodeScannerPermission, [], false); | ||
await loginPage.login(offlineUser); | ||
await commonPage.waitForPageLoaded(); | ||
await commonPage.goToPeople(); | ||
}); | ||
|
||
it('Search should display correct results, clear search should display all contacts', async () => { | ||
await searchPage.performBarcodeSearch(barcodeImagePath); | ||
expect(await contactPage.getAllLHSContactsNames()).to.have.members([ | ||
person.name | ||
]); | ||
|
||
await searchPage.searchPageDefault.clearSearch(); | ||
expect(await contactPage.getAllLHSContactsNames()).to.have.members([ | ||
healthCenter.name, | ||
places.get('clinic').name | ||
]); | ||
}); | ||
|
||
it('With an invalid barcode image - Search should display snackbar with error message', async () => { | ||
await searchPage.performBarcodeSearch(invalidBarcodeImagePath); | ||
expect(await commonPage.snackbarMessage()).to.equal('Failed to read the barcode. Retry.'); | ||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
const searchPageDefault = require('@page-objects/default/search/search.wdio.page'); | ||
|
||
const openSearchBox = () => $('.mm-search-bar-container .search-bar-left-icon .fa-search'); | ||
const barcodeSearchInput = () => $('.barcode-scanner-input'); | ||
|
||
const performSearch = async (term) => { | ||
await (await openSearchBox()).waitForClickable(); | ||
await (await openSearchBox()).click(); | ||
await searchPageDefault.performSearch(term); | ||
}; | ||
|
||
const performBarcodeSearch = async (barcodeImagePath) => { | ||
/*In this case the upload file button is hidden, | ||
then we need to manipulate the DOM of the respective webelement to make it interactable.*/ | ||
browser.execute(function () { | ||
document.getElementsByClassName('barcode-scanner-input')[0].style.display = 'block'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a fain of this either, because it will definitely obscure if the actual button that makes the input selection no longer works, or is not displayed. So the test only validates the functionality partially. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you click on the barcode icon, the OS upload file dialog appears, and Webdriverio has no control over it. I'm investigating how to setValue to a web element that is not interactable without modifying the DOM. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I went through that search as well and in the end I couldn't find anything. The idea is that wdio really wants to simulate as close to user interaction as possible. |
||
}); | ||
await (await barcodeSearchInput()).setValue(barcodeImagePath); | ||
await browser.pause(1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for the 1s delay? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We experienced some delay when uploading and processing the barcode image. But I only tried the e2e test with the wait; It may be unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try without the wait, and the test fails because it doesn't have time to process the search and show results. This validation fails. |
||
}; | ||
|
||
|
||
module.exports = { | ||
searchPageDefault, | ||
performSearch, | ||
performBarcodeSearch, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lorerod just popping up here to see if you need my help with the barcode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @latin-panda. We are experiencing a strange behavior when running the e2e test compared to when running the developer setup first and then the e2e test. When running the e2e test directly in the branch, it does not use the latest changes, and the test fails. This is also happening in CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version in
package.json
andpackage-lock.json
is different from the 4.4.1-FR-barcode branch. We need to pull the latest from4.4.1-FR-barcode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @latin-panda! I pulled the latest from
4.4.1-FR-barcode
, but the test still fails on CI because the barcode search icon doesn't show. I will continue looking into this to see if I can find the problem.