-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract logger and wait on result to new class
- Loading branch information
Yen Truong
committed
Jul 14, 2021
1 parent
914e2f9
commit f8e9b26
Showing
6 changed files
with
86 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
module.exports.PORT=9999; | ||
module.exports.PORT=9999; | ||
module.exports.VERTICAL_SEARCH_QUERY_URL=/v2\/accounts\/me\/answers\/vertical\/query/; | ||
module.exports.UNIVERSAL_SEARCH_QUERY_URL=/v2\/accounts\/me\/answers\/query/; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { VERTICAL_SEARCH_QUERY_URL, UNIVERSAL_SEARCH_QUERY_URL } from './constants'; | ||
import { Selector, RequestLogger, t } from 'testcafe'; | ||
import { registerIE11NoCacheHook } from '../test-utils/testcafe'; | ||
|
||
/** | ||
* Handles request logger registration and request/response data received during test execution. | ||
*/ | ||
class SearchRequestLogger { | ||
constructor () { | ||
this._searchComplete = Selector('.yxt-Results--searchComplete'); | ||
} | ||
|
||
/** | ||
* Register a RequestLogger that tracks vertical query requests to given test. | ||
* If browser is IE11, register an Ie11NoCacheHook. | ||
* | ||
* @param {import('testcafe').TestController} testInstance | ||
*/ | ||
async registerVerticalSearchLogger(testInstance) { | ||
this._queryRequestLogger = RequestLogger({ | ||
url: VERTICAL_SEARCH_QUERY_URL | ||
}); | ||
await testInstance.addRequestHooks(this._queryRequestLogger); | ||
await registerIE11NoCacheHook(testInstance, VERTICAL_SEARCH_QUERY_URL); | ||
} | ||
|
||
/** | ||
* Register a RequestLogger that tracks universal query requests to given test. | ||
* If browser is IE11, register an Ie11NoCacheHook. | ||
* | ||
* @param {import('testcafe').TestController} testInstance | ||
*/ | ||
async registerUniversalSearchLogger() { | ||
this._queryRequestLogger = RequestLogger({ | ||
url: UNIVERSAL_SEARCH_QUERY_URL | ||
}); | ||
await testInstance.addRequestHooks(this._queryRequestLogger); | ||
await registerIE11NoCacheHook(testInstance, UNIVERSAL_SEARCH_QUERY_URL); | ||
} | ||
|
||
/** | ||
* Wait for results to load on page by checking query response status and searchComplete state | ||
* (timeout is set to 10 seconds) | ||
*/ | ||
async waitOnSearchComplete() { | ||
const responseWaitTimeout = 10000; | ||
const waitTimeInterval = 200; | ||
let totalWaitTime = 0; | ||
while (totalWaitTime < responseWaitTimeout && !this.isLoggerResultsPresent()) { | ||
await t.wait(waitTimeInterval); | ||
totalWaitTime += waitTimeInterval; | ||
} | ||
await t.expect(this._searchComplete.exists).ok(); | ||
this._queryRequestLogger.clear(); | ||
} | ||
|
||
/** | ||
* Returns true if there exists a query response from logger with status code 200 | ||
* @returns {boolean} | ||
*/ | ||
async isLoggerResultsPresent() { | ||
return await this._queryRequestLogger.contains(r => r.response.statusCode === 200); | ||
} | ||
} | ||
|
||
export default new SearchRequestLogger(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters