Skip to content
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

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
13c3ac3
Trying to activate search just changing input value
Nov 24, 2023
a911fd7
Add search should display one result scenario
Nov 27, 2023
d3acd96
Add failed to read the barcode scenario
Nov 27, 2023
0aa9383
Use emulateDevice instead of setWindowSize
Nov 28, 2023
5fe218b
Fix local path
Nov 28, 2023
81214ef
Delete unused method
Nov 28, 2023
cddc9e9
Fix eslint
Nov 28, 2023
24a6625
Directly set the barcode image path without uploading file to Chrome
Nov 29, 2023
ce30fe8
Use snackbarMessage from commonPage
Nov 29, 2023
81f20d3
Change beforeSuite to beforeHook to set emulateDevice capability for …
Nov 29, 2023
47006f9
Set userAgent using variables for android and chrome version
Dec 3, 2023
8232a63
Fix local url
Dec 3, 2023
3a3c387
Fix eslint
Dec 3, 2023
b2567f5
Try with beforeSuite
Dec 3, 2023
01eb63c
Use chromeOptions to enable mobile emulation
Dec 4, 2023
450e230
Fix eslint
Dec 4, 2023
317c9ee
Changing user-agent to a linux user-agent
Dec 4, 2023
87a2c7b
Change the format to pass user-agent to chromeOptions
Dec 4, 2023
736bfb9
Define mobileEmulation with predefined deviceName
Dec 4, 2023
5394762
Try with another deviceName
Dec 4, 2023
ba67a60
Detailed configuration of emulate device
Dec 4, 2023
dd26bd2
Add flag to use mobile user agent
Dec 5, 2023
8caddd5
Back to use emulateDevice
Dec 6, 2023
efdee66
maybe user agent isn't updated?
latin-panda Dec 15, 2023
9d7ff21
reverting change
latin-panda Dec 18, 2023
b61e649
Merge branch '4.4.1-FR-barcode' of https://github.com/medic/cht-core …
latin-panda Dec 18, 2023
02a9426
waiting for search to finish
latin-panda Dec 18, 2023
6922011
longer wait fot search to finish
latin-panda Dec 18, 2023
4ec94f1
Merge branch '4.4.1-FR-barcode' of https://github.com/medic/cht-core …
Jan 2, 2024
afa0041
Update search.wdio.page.js
latin-panda Jan 4, 2024
cf7592a
Trying to check current version
Jan 11, 2024
4c22f3a
Log about page current version
Jan 11, 2024
8ac8efb
Change the way of getting the current Version
Jan 11, 2024
57446eb
Revert "Change the way of getting the current Version"
Jan 11, 2024
b65eaf3
Revert "Log about page current version"
Jan 11, 2024
b45e15b
Revert "Trying to check current version"
Jan 11, 2024
4e351d3
Merge branch '6669-search-by-barcode-e2e-test--weird-issue' of https:…
Jan 12, 2024
58874dc
Adding wait after setting barcode search input value
Jan 12, 2024
5f08fa7
Try with beforeHook
Jan 12, 2024
3aa6210
Wait for barcode scanner input to exist and, log DOM
Jan 12, 2024
995590e
Fix eslint
Jan 12, 2024
a263189
Check current user agent
Jan 12, 2024
a728edf
Fix eslint
Jan 12, 2024
1e0992c
Add browser refresh after setting user agent
Jan 12, 2024
48e6fbc
Check userAgent before changing it
Jan 12, 2024
81306ac
Show current user agent on logs
Feb 2, 2024
b279780
Fix eslint
Feb 2, 2024
1a4599b
Change waitToDisplay with waitForExist and, sync and refresh after ch…
Feb 6, 2024
509cab6
Fix typo
Feb 6, 2024
03e7233
Delete unnecesary step
Feb 6, 2024
b2c57b1
Delete console logs
Feb 6, 2024
f8d8e3c
Cleaning up the code, skip invalid barcode scenario for now
Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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 and package-lock.json is different from the 4.4.1-FR-barcode branch. We need to pull the latest from 4.4.1-FR-barcode

Copy link
Contributor Author

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.

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.');
});

});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions tests/e2e/default-mobile/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const wdioBaseConfig = require('../wdio.conf');

const chai = require('chai');
chai.use(require('chai-exclude'));
const ANDROID_VERSION = '13';
const MOBILE_CHROME_VERSION = '118.0.5993.112';

// Override specific properties from wdio base config
exports.config = Object.assign(wdioBaseConfig.config, {
Expand All @@ -13,10 +15,22 @@ exports.config = Object.assign(wdioBaseConfig.config, {
'../default/navigation/navigation.wdio-spec.js',
'../default/navigation/hamburger-menu.wdio-spec.js',
],
]},
]
},
beforeSuite: async () => {
// We tried the browser.emulateDevice('...') function but it's not stable enough,
// it looses the mobile view and switches back to desktop
await browser.setWindowSize(450, 700);
},
// it looses the mobile view and switches back to desktop.
// Adding to the comment above, it loses the mobile view when a test fails.
// It may be better to use beforeHook instead of beforeSuite so it can set the capability before each test.
await browser.emulateDevice({
viewport: {
width: 600,
height: 960,
isMobile: true,
hasTouch: true,
},
userAgent: `Mozilla/5.0 (Linux; Android ${ANDROID_VERSION}; IN2010) AppleWebKit/537.36 (KHTML, like Gecko) ` +
`Chrome/${MOBILE_CHROME_VERSION} Mobile Safari/537.36`
});
}
});
13 changes: 13 additions & 0 deletions tests/page-objects/default-mobile/search/search.wdio.page.js
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';
Copy link
Member

Choose a reason for hiding this comment

The 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.
Is there no way to use the elements that are displayed on the page to upload the image?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.
Maybe we should just leave it like this.

});
await (await barcodeSearchInput()).setValue(barcodeImagePath);
await browser.pause(1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for the 1s delay?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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,
};
Loading