Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function DriverWaitElement(selector) {
  2.     this.selector = selector;
  3.  
  4.     this.waitDisplay = async (timeout) => {
  5.         let resultWait = await this.__promiseDisplay(timeout);
  6.         if (!resultWait)
  7.             throw new Error("Element not displayed");
  8.         return this;
  9.     };
  10.  
  11.     this.waitInvisible = async (timeout) => {
  12.         let resultWait = await this.__promiseInvisible(timeout);
  13.         if (!resultWait)
  14.             throw new Error("Element displayed");
  15.         return this;
  16.     };
  17.  
  18.     this.__promiseDisplay = (timeout) => {
  19.         return new Promise(
  20.             resolve => {
  21.                 let outID, intID;
  22.                 intID = setInterval(
  23.                     () => {
  24.                         if ($(this.selector).length) {
  25.                             clearTimeout(outID);
  26.                             clearInterval(intID);
  27.                             resolve(true);
  28.                         }
  29.                     }, 100);
  30.                 outID = setTimeout(
  31.                     () => {
  32.                         clearInterval(intID);
  33.                         resolve(false);
  34.                     }, timeout);
  35.             }
  36.         );
  37.     };
  38.  
  39.     this.__promiseInvisible = (timeout) => {
  40.         return new Promise(
  41.             resolve => {
  42.                 let outID, intID;
  43.                 intID = setInterval(
  44.                     () => {
  45.                         if (!$(this.selector).length) {
  46.                             clearTimeout(outID);
  47.                             clearInterval(intID);
  48.                             resolve(true);
  49.                         }
  50.                     }, 100);
  51.                 outID = setTimeout(
  52.                     () => {
  53.                         clearInterval(intID);
  54.                         resolve(false);
  55.                     }, timeout);
  56.             }
  57.         );
  58.     }
  59. }
  60.  
  61. new DriverWaitElement("bodyw").waitDisplay(5000).then(() => console.log(111));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement