Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function DriverWaitElement(selector) {
- this.selector = selector;
- this.waitDisplay = async (timeout) => {
- let resultWait = await this.__promiseDisplay(timeout);
- if (!resultWait)
- throw new Error("Element not displayed");
- return this;
- };
- this.waitInvisible = async (timeout) => {
- let resultWait = await this.__promiseInvisible(timeout);
- if (!resultWait)
- throw new Error("Element displayed");
- return this;
- };
- this.__promiseDisplay = (timeout) => {
- return new Promise(
- resolve => {
- let outID, intID;
- intID = setInterval(
- () => {
- if ($(this.selector).length) {
- clearTimeout(outID);
- clearInterval(intID);
- resolve(true);
- }
- }, 100);
- outID = setTimeout(
- () => {
- clearInterval(intID);
- resolve(false);
- }, timeout);
- }
- );
- };
- this.__promiseInvisible = (timeout) => {
- return new Promise(
- resolve => {
- let outID, intID;
- intID = setInterval(
- () => {
- if (!$(this.selector).length) {
- clearTimeout(outID);
- clearInterval(intID);
- resolve(true);
- }
- }, 100);
- outID = setTimeout(
- () => {
- clearInterval(intID);
- resolve(false);
- }, timeout);
- }
- );
- }
- }
- new DriverWaitElement("bodyw").waitDisplay(5000).then(() => console.log(111));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement