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

TestCafe wait for results #878

Merged
merged 11 commits into from
Jul 15, 2021
Merged

TestCafe wait for results #878

merged 11 commits into from
Jul 15, 2021

Conversation

yen-tt
Copy link
Contributor

@yen-tt yen-tt commented Jul 12, 2021

Update cafeTest acceptance test

  • Added waitOnSearchComplete in verticalResults.js to wait till query responses return status 200 and searchComplete state appears on page.
  • Register requestLogger to each test to track vertical request and response to Answers API endpoint
  • Added IE11nocachehook from SDK
  • From oliver's acceptance test failure investigation..
      - first point: the test first function call is verticalResults.scrollToBottom(), which wait on this._resultsWrapper when perform scroll on page. This resultsWrapper will always exist because it's set in our page template. The test didn't account for waiting on the actual search result div. Calling waitOnSearchComplete before scrolling would prevent this issue.
      - second point: removed the arbitrary wait time 1s in dragLeft(). Replaced with waiting for the response to be returned first using searchComplete state.
  • Updated tests to wait for results before calling getNumResults() which check if results exists after a search. (From testCafe documentation, Selector wait/timeouts functionality have no effect on Selector.exists and Selector.count properties. These properties are evaluated immediately.)

J=SLAP-1425
TEST= auto

ran testCafe locally to verify tests and wait time in selectors

J=SLAP-1425
TEST= manual & auto
@coveralls
Copy link

coveralls commented Jul 12, 2021

Coverage Status

Coverage remained the same at 6.67% when pulling 0881390 on dev/testcafe-acceptance-test into 1cb987e on develop.

tests/acceptance/blocks/verticalresults.js Outdated Show resolved Hide resolved
* (default selector timeout of 10 seconds)
*/
async waitOnSearchComplete () {
if(!this._preSearch.exists) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For my own edification, what is preSearch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's one of the search states from SDK (presearch, loading, completed). I originally thought initial search on page may go from presearch to completed, skipping loading state. Turns out it's just testCafe unable to catch the loading transition. Updated to track query request/responses instead!

await t.expect(this._searchLoading.exists).ok();
}
await this._searchComplete();
await t.expect(this._searchComplete.exists).ok();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does await this._searchComplete() being successful imply t.expect(this._searchComplete.exists).ok() automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test would still consider passed if await this._searchComplete() doesn't find any matching element

* wait for results to return based on search complete state
* (default selector timeout of 10 seconds)
*/
async waitOnSearchComplete () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If someone calls this method, but no search has actually been executed, will it timeout? I'm wondering if we should handle that situation gracefully, like it returns immediately. Maybe not something we need to worry about, just a thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in this method, and in the updated one, it will timeout eventually. I think if no search is executed and someone uses this method, meaning they are expecting a search or result returned of some sort, it make sense to indicate a failure here to notify that the expected behavior is not met

@yen-tt yen-tt added the WIP label Jul 13, 2021
const waitTimeInterval = 200;
let totalWaitTime = 0;
while (totalWaitTime < responseWaitTimeout
&& this._queryRequestLogger.requests.find(r => !r.response || r.response.statusCode !== 200)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this code waiting while an invalid response exists? is there a reason for that approach rather than waiting until a successful response has been logged?

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to extract the query logger lookup into a variable or a function so that this logic is a litter easier to follow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logger will hold all request/response throughout a test so just checking for a successful response might accidentally check on previous requests. But, after some thoughts, I updated this method check for a successful response in the loop, and clear out the logger at the end of this method. This make sure we are always verifying the latest response.

@yen-tt yen-tt requested a review from cea2aj July 13, 2021 21:04

fixture`Vertical Full Page Map with Filters and Clusters`
.page(`http://localhost:${PORT}/locations_full_page_map_with_filters`)
.beforeEach(async t => {
await VerticalResults.registerLogger(t);
await registerIE11NoCacheHook(t);
Copy link
Contributor

Choose a reason for hiding this comment

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

should the ie11 hook go inside registerLogger? like, is there ever a time we would call registerLogger without also registering the ie11 hook?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that would make sense. Updated!

@yen-tt yen-tt requested a review from oshi97 July 14, 2021 13:54
* Wait for results to load on page by checking query response status and searchComplete state
* (timeout is set to 10 seconds)
*/
async waitOnSearchComplete() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I know I just recently approved this, but after looking at the SDK half of this item maybe this waitOnSearchComplete should go into its own request logger class instead of inside the VerticalResults component's class?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, if we can move this to it's own class we could easily expand it to universal search. Yen, if we have a new class such as SearchRequestLogger, we could have a registerVerticalSearchLogger and a registerUniversalSearchLogger function so that we could set it up for either type of search

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 see, yeah that sounds good

@yen-tt yen-tt requested a review from oshi97 July 14, 2021 16:59
@yen-tt yen-tt force-pushed the dev/testcafe-acceptance-test branch from f4362c7 to f8e9b26 Compare July 14, 2021 17:03
@yen-tt yen-tt force-pushed the dev/testcafe-acceptance-test branch 2 times, most recently from bafb612 to b496623 Compare July 14, 2021 20:14
@yen-tt yen-tt force-pushed the dev/testcafe-acceptance-test branch from b496623 to 0881390 Compare July 14, 2021 20:15
@yen-tt yen-tt merged commit bb86a14 into develop Jul 15, 2021
@yen-tt yen-tt deleted the dev/testcafe-acceptance-test branch July 15, 2021 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants