rajdeeep2k17
2/16/2018 - 2:51 PM

Sexy Date Functionality Testing Code Mobile

This code snippet consists of all the test cases for mobile version running in headless mode

require('dotenv').config()

const { exists } = require('../jest/utils')
const faker = require('faker');

test("Setup", async () => {
  await page.setRequestInterception(true)
  page.on('request', (request) => {
    (['image', 'font'].indexOf(request.resourceType()) !== -1) ? request.abort() : request.continue()
  })
})

const fakeEmail = faker.internet.email();
const itomail = faker.name.firstName() + '@itobuz.com';
const first_name = faker.name.firstName() + 'abc';
const pass = faker.internet.password();
const message = faker.lorem.sentence();
const paras = faker.lorem.paragraphs();
const name = faker.name.firstName();

describe("Landing Page", async() => {
  it("Goto landing page", async() => {
    await page.goto(baseUrl, {waitUntil: "networkidle0"})
    
  })
  describe("Registration Error Checks", async() => {
    it("Registration without email id", async() => {
      await page.click('app-register-step-one form button')
      await page.waitForSelector('#register-form form div.msg--error.before-submit')
    })
    it("Registration with incorrect email id", async() => {
      await page.type('app-register-step-one p-autocomplete input', 'qwerty@testfake.com')
      await page.click('app-register-step-one form button')
      await page.waitForSelector('app-register-step-one form div.msg.msg--error')
    })
  })
  describe("Email ID domain names autocomplete", async() => {
    it("Email ID domain names autocomplete", async() => {
      await page.$eval('app-register-step-one p-autocomplete input', e => e.value = '')
      await page.type('app-register-step-one p-autocomplete input', 'rajdeep@o')
      await page.waitForSelector('form > div > div:nth-child(2) > div > p-autocomplete > span > div > ul')
    })
  })
  describe("Registration process step by step", async () => {
    it("first step", async () => {
      await page.$eval('input[type="email"]', e => e.value = '')
      await page.selectRandom('div.register select')
      await page.type('input[type="email"]', itomail)
      await page.click('form button')
      await page.waitForSelector('div.custom-modal.register')
    })
    it("second step", async () => {
      await page.type('input[formControlName="nick_name"]', first_name)
      await page.type('input[formControlName="name"]', first_name)
      await page.type('input[formControlName="password"]', pass)
      await page.selectRandom('div.custom-modal.register select')
      await page.click('.btn-green')
      await page.waitForSelector('div.register-step-three-container')
    })
    it("third step", async () => {
      let selectBoxesSelectors = [
        'div.register-step-three-container select[formcontrolname="province_id"]',
        'div.register-step-three-container select[formcontrolname="height"]',
        'div.register-step-three-container select[formcontrolname="weight"]',
        'div.register-step-three-container select[formcontrolname="body_type_id"]',
        'div.register-step-three-container select[formcontrolname="hair_color_id"]',
        'div.register-step-three-container select[formcontrolname="eye_color_id"]'
      ]
      await page.selectRandom(selectBoxesSelectors, { multiple: true })
      await page.type('div.register-step-three-container textarea[formcontrolname="description"]', message)
      await page.click('body > ngb-modal-window app-register-step-three div.form-wrap > form > div.button-wrap > button')
    })
    it("Check that it has the correct email", async () => {
      await page.waitForSelector('body > ngb-modal-window > div > div > app-register-confirm > div > div > div > div > h4')
      await page.waitForFunction( () => document.querySelector('body > ngb-modal-window > div > div > app-register-confirm > div > div > div > div > h4').innerText != '' )
      const email1 = await page.$eval('.confirm-modal .register > div > h4', e => e.innerText)
      expect(email1).toEqual(itomail)
    })
    it("Resends email", async () => {
      await page.waitForSelector('app-register-confirm .card-verification-v1 .resend-row .s-btn:nth-child(1)')
      await page.click('app-register-confirm .card-verification-v1 .resend-row .s-btn:nth-child(1)')
      await page.waitForSelector('div.register div.msg--success')
    })
  })
})

describe("Login Page", async() => {
  it("Goto login popup", async() => {
    await page.goto(baseUrl, {waitUntil: "networkidle0"})
    await page.click("#bannerwrapper div.landing-banner > button")
    await page.waitForSelector('ngb-modal-window app-login div.form-box')
  })
  describe("Login Cases", async() => {
    describe("Login Error Checks", async() => {
      it("Login without any credentials", async() => {
        await page.click("app-login form > button")
        await page.waitForSelector('app-login form > input[formcontrolname="email_or_nick"] + div.msg.msg--error')
        await page.waitForSelector('app-login form > input[formcontrolname="password"] + div.msg.msg--error')
      })
      it("Entering only email displays 'enter password'", async() => {
        await page.type('app-login form > input[formcontrolname="email_or_nick"]', 'rajdeep')
        await page.click("app-login form > button")
        await page.waitForSelector('app-login form > input[formcontrolname="password"] + div.msg.msg--error')
      })
      it("Wrong credential user login", async() => {
        await page.$eval('app-login form > input[formcontrolname="email_or_nick"]', el => el.value = '')
        await page.type('app-login form > input[formcontrolname="email_or_nick"]', 'rajdeep')
        await page.type('app-login form > input[formcontrolname="password"]', 'wrongPassword')
        await page.click('app-login form > button')
        await page.waitForSelector('app-login form > button + div.msg.msg--error')
      })
      it("Unregistered User Login", async() => {
        await page.$eval('app-login form > input[formcontrolname="email_or_nick"]', el => el.value = '')
        await page.$eval('app-login form > input[formcontrolname="password"]', el => el.value = '')
        await page.type('app-login form > input[formcontrolname="email_or_nick"]', 'saikat')
        await page.type('app-login form > input[formcontrolname="password"]', 'password')
      })
    })
  })
  describe("Forgot Password", async() => {
    it("Goto Forgot Password modal", async() => {
      await page.click("app-login button.forgot")
      await page.waitForSelector("app-forgot-password form > input")
    })
    describe("Error Checks", async() => {
      it("Submit without email Id", async() => {
        await page.click('app-forgot-password form button')
        await page.waitForSelector('input[formcontrolname="email"] + div.msg.msg--error')
      })
      it("Submit with incorrect email Id", async() => {
        await page.type('input[formcontrolname="email"]', 'testing123@googloo.com')
        await page.click('app-forgot-password form button')
        await page.waitForSelector('div.button-wrap + div.msg.msg--error')
      })
    })
    describe("Success Checks", async() => {
      it("Submit with valid email", async() => {
        await page.$eval('input[formcontrolname="email"]', el => el.value = '')
        await page.type('input[formcontrolname="email"]', 'rajdeep@itobuz.com')
        await page.click('app-forgot-password form button')
      })
      it("Success message appears", async() => {
        await page.waitForSelector("div.msg.msg--success")
      })
    })
    describe("Modal closes on X button", async() => {
      it("Modal closes on X button", async() => {
        await page.click('app-forgot-password button.close-modal-btn')
        await page.waitForSelector('#bannerwrapper div.landing-banner > button')
      })
    })
  })
  describe("Successful Login Cases", async () => {
    describe("First time registered-user login", async () => {
      it("Logged in", async () => {
        await page.goto(baseUrl, { waitUntil: "networkidle0" })
        await page.click('#bannerwrapper > div > div > div.landing-banner > button')
        await page.type('input[formcontrolname="email_or_nick"]', process.env.LOGEMAIL)
        await page.type('input[formcontrolname="password"]', process.env.PASSWORD)
        await page.click('app-login > div > div > div > form > button')
      })
      it("Logging out", async () => {
        await page.waitForSelector('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(1) > a')
        await page.click('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(1) > a')
        await page.waitForSelector('app-dashboard > div > div.profile-actions > div > button:nth-child(4)')
        await page.click('app-dashboard > div > div.profile-actions > div > button:nth-child(4)')
      })
    })
  
    describe("User with completed profile login", async () => {
      describe("Basic User Type", async () => {
        it("Log in as basic user", async () => {
          // await page.goto(baseUrl, { waitUntil: "networkidle0" }) // to remove
          await page.waitForSelector('#bannerwrapper > div > div > div.landing-banner > button')
          await page.click('#bannerwrapper > div > div > div.landing-banner > button')
          await page.waitForSelector('input[formcontrolname="email_or_nick"]')
          await page.type('input[formcontrolname="email_or_nick"]', process.env.COMPMAIL)
          await page.type('input[formcontrolname="password"]', process.env.PASSWORD)
          await page.click('app-login > div > div > div > form > button')
        })
        it("Check for User Type (at top right section of header)", async () => {
          await page.waitForSelector('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(1) > a')
          await page.click('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(1) > a')
          await page.waitForSelector('div.profile-name-wrapper div.name-subscribe > h2 > span.frown.smiley > span')
          var basicText = await page.$eval('div.profile-name-wrapper div.name-subscribe > h2 > span.frown.smiley > span', e => e.innerText.split(' ')[0])
          expect('Basic').toEqual(basicText)
        })
        it("check smiley as per user type", async () => {
          await page.waitForSelector('div.profile-name-wrapper > div > div > div.name-subscribe > h2 > span.frown.smiley > span > i')
        })
        it("'Subscribe' button present", async () => {
          await page.waitForSelector('div.profile-name-wrapper div.name-subscribe > button')
        })
        it("Logging out", async () => {
          await page.click('app-dashboard > div > div.profile-actions > div > button:nth-child(4)')
        })
      })
      describe("Elite User Type", async () => {
        it("Log in as Elite user", async () => {
          // await page.goto(baseUrl, { waitUntil: "networkidle0" }) // to remove
          await page.waitForSelector('#bannerwrapper > div > div > div.landing-banner > button')
          await page.click('#bannerwrapper > div > div > div.landing-banner > button')
          await page.waitForSelector('input[formcontrolname="email_or_nick"]')
          await page.type('input[formcontrolname="email_or_nick"]', process.env.ELITUSER)
          await page.type('input[formcontrolname="password"]', process.env.PASSWORD)
          await page.click('app-login > div > div > div > form > button')
        })
        it("Check for User Type (at top right section of header)", async () => {
          await page.waitForSelector('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(1) > a')
          await page.click('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(1) > a')
          await page.waitForSelector('div.profile-name-wrapper div.name-subscribe > h2 > span.smile.smiley')
          var eliteText = await page.$eval('div.profile-name-wrapper div.name-subscribe > h2 > span.smile.smiley', e => e.innerText.split(' ')[0])
          expect('ELITE').toEqual(eliteText)
        })
        it("check smiley as per user type", async () => {
          await page.waitForSelector('div.profile-name-wrapper div.name-subscribe > h2 > span.smile.smiley > i')
        })
        it("'Subscribe' button absent", async () => {
          await page.waitForSelector('div.profile-name-wrapper div.name-subscribe > button', { hidden: true })
        })
        it("Logging out", async () => {
          await page.click('app-dashboard > div > div.profile-actions > div > button:nth-child(4)')
        })
      })
      describe.skip("VIP User Type", async () => {
        it("Log out", async () => {
          await page.click('div.login-wrapper.logged-in > button')
        })
        it("Log in as VIP user", async () => {
          await page.waitForSelector('input[formcontrolname="email_or_nick"]')
          await page.type('input[formcontrolname="email_or_nick"]', process.env.VIPUSER)
          await page.type('input[formcontrolname="password"]', process.env.PASSWORD)
          await page.click('button[type="submit"]')
          await page.waitForSelector('.subscription-block h5 > span')
        })
        it("Check for User Type (at top right section of header)", async () => {
          var vipText = await page.$eval('.subscription-block h5 > span', e => e.innerText)
          expect(vipText).toEqual(expect.stringContaining('VIP'))
        })
        it("check smiley as per user type", async () => {
          await page.waitForSelector('div.login-wrapper.logged-in .fa-smile-o')
        })
        it("Does not show 'Become Elite' button", async () => {
          try {
            await page.waitForSelector('.desktop-nav .nav button', { timeout: 1000 })
          }
          catch (err) {
            console.log('No Button in nav. Test Passed.')
          }
        })
      })
    })
  })
})

describe("Message List Page", async() => {
  it("Login as Prosenjit", async() => {
    await page.waitForSelector("#bannerwrapper div.landing-banner > button")
    await page.click("#bannerwrapper div.landing-banner > button")
    await page.waitForSelector('ngb-modal-window app-login div.form-box')
    await page.type('app-login form > input[formcontrolname="email_or_nick"]', process.env.USERNAME_P)
    await page.type('app-login form > input[formcontrolname="password"]', process.env.PASSWORD)
    await page.click('app-login form > button')
    await page.waitForSelector('app-favorite-member')
  })
  it("Goto Message List Page", async() => {
    await page.click('app-mobile-tab-header > ul > li:nth-child(3) > a')
    await page.waitForSelector('.chat-list-wrapper')
  })
  describe("Show/Hide details beside message", async() => {
    it("Swipe left/click arrow to show details", async() => {
      await page.click('.chatwrapper-list i.fa.fa-angle-right')
      await page.waitForSelector('.chatwrapper-list.toggled')
    })
    it("Swipe right/click arrow to hide details", async() => {
      await page.click('.chatwrapper-list i.fa.fa-angle-right')
      const isExist = await page.evaluate(() => {
        const e = document.querySelector('.chatwrapper-list.toggled');
        if (!e)
          return false;
        else 
          return true;
      });
      expect(isExist).toBeFalsy()
    })
  })
  describe.skip("Delete Message", async() => {
    it("Delete Message", async() => {
      const oldChatName = await page.$eval('.custom-heading-style-01', e => e.innerText)
      await page.click('.chatwrapper-list i.fa.fa-angle-right')
      await page.waitForSelector('.chatwrapper-list.toggled')
      await page.click('div.chatwrapper-list.toggled > div.chat-wrapper-option > div.delete-msg.wrapper-option > i')
      await page.waitForSelector('.custom-heading-style-01')
      await page.waitForFunction( (oldChatName) => document.querySelector('.custom-heading-style-01').innerText !== oldChatName, {polling: 'mutation'}, oldChatName )
      const newChatName  = await page.$eval('.custom-heading-style-01', e => e.innerText)
      expect(oldChatName).not.toBe(newChatName)
    })
  })
})

describe("Trash Page", async() => {
  it("Goto Trash Page", async() => {
    await page.click('app-my-chat > div > div.options-title > a')
    await page.waitForSelector("app-chat-trash .chat-list-wrapper div.chatwrapper-list")
  })
  describe("Pagination", async() => {
    it("Click next goes to next page", async() => {
      const prevChatname = await page.$eval("app-chat-trash .chat-list-wrapper .chatwrapper-list div.profile-header > h3", e => e.innerText)
      await page.click('app-chat-trash div.pagination > button > span.pr-2')
      await page.waitForSelector('app-chat-trash .chat-list-wrapper .chatwrapper-list div.profile-header > h3')
      await page.waitForFunction( (prevChatname) => document.querySelector('app-chat-trash .chat-list-wrapper .chatwrapper-list div.profile-header > h3').innerText !== prevChatname, {polling: "mutation"}, prevChatname )
      const nextChatName = await page.$eval("app-chat-trash .chat-list-wrapper .chatwrapper-list div.profile-header > h3", e => e.innerText)
      expect(prevChatname).not.toBe(nextChatName)
    })
    it("Click Prev goes to previous page", async() => {
      const nextChatname = await page.$eval("app-chat-trash .chat-list-wrapper .chatwrapper-list div.profile-header > h3", e => e.innerText)
      await page.click('app-chat-trash div.pagination > button:nth-child(1) > span.pl-2')
      await page.waitForSelector('app-chat-trash .chat-list-wrapper .chatwrapper-list div.profile-header > h3')
      await page.waitForFunction( (nextChatname) => document.querySelector('app-chat-trash .chat-list-wrapper .chatwrapper-list div.profile-header > h3').innerText !== nextChatname, {polling: "mutation"}, nextChatname )
      const prevChatName = await page.$eval("app-chat-trash .chat-list-wrapper .chatwrapper-list div.profile-header > h3", e => e.innerText)
      expect(prevChatName).not.toBe(nextChatname)
    })
  })
  describe("Logout", async() => {
    it("Logout", async() => {
      await page.click("app-chat-trash app-mobile-tab-header > ul > li:nth-child(1) > a")
      await page.waitForSelector('app-dashboard div.profile-actions button:nth-child(4)')
      await page.click("app-dashboard div.profile-actions button:nth-child(4)")
      await page.waitForSelector("#bannerwrapper div.landing-banner > button")
    })
  })
})

describe("Profile Page", async() => {
  it("Login as Suman", async() => {
    await page.click("#bannerwrapper div.landing-banner > button")
    await page.waitForSelector('ngb-modal-window app-login div.form-box')
    await page.type('app-login form > input[formcontrolname="email_or_nick"]', process.env.USERNAME)
    await page.type('app-login form > input[formcontrolname="password"]', process.env.PASSWORD)
    await page.click('app-login form > button')
    await page.waitForSelector('app-favorite-member .profile-pic')
  })
  it("Goto Profile", async() => {
    await page.click('app-favorite-member .profile-pic')
    await page.waitForSelector('div.visit.profile-wrapper div.visiter-profile-wrap div.circle-icon-wrapper')
  })
  describe("Add to Favorite", async() => {
    it(" 'Empty Heart' icon becomes 'Filled Heart' icon", async() => {
      await page.click('div.visitor-contact-container-button-group > div.big-circle-icon-wrapper.big-circle-icon-wrapper--pink.mr-3.not-fav')
      await page.waitForSelector('div.visitor-contact-container-button-group > div.big-circle-icon-wrapper.big-circle-icon-wrapper--pink.mr-3.fav')
    })
    it(" 'Added to Favorites' success message appears", async() => {
      await page.waitForSelector('app-root > app-notification-list > div')
    })
  })
  describe("Remove from favourites", async() => {
    it(" 'Filled Heart' icon becomes 'Empty Heart' icon", async() => {
      await page.click('div.visitor-contact-container-button-group > div.big-circle-icon-wrapper.big-circle-icon-wrapper--pink.mr-3.fav')
      await page.waitForSelector('div.visitor-contact-container-button-group > div.big-circle-icon-wrapper.big-circle-icon-wrapper--pink.mr-3.not-fav')
    })
    it(" 'Removed from Favorites' success message appears", async() => {
      await page.waitForSelector('app-root > app-notification-list > div')
    })
  })
  describe('Photo Album', async() => {
    it("Clicking on any photo, opens Gallery modal", async() => {
      await page.click("div.visit.profile-wrapper div.visiter-profile-wrap div.circle-icon-wrapper")
      await page.waitForSelector('div.lightbox.animation.fadeIn > div.lb-outerContainer.transition > div > img')
    })
    it.skip("Click > for next image", async() => {
      // No Image on right
    })
    it.skip("Click < for previous image", async() => {
      // No Image on left
    })
  })
})

describe("Settings page", async() => {
  it("Goto Settings Page", async() => {
    await page.goto(baseUrl, { waitUntil: "networkidle0" })
    await page.waitForSelector("app-mobile-tab-header > ul > li:nth-child(1) > a")
    await page.click("app-mobile-tab-header > ul > li:nth-child(1) > a")
    await page.waitForSelector("app-dashboard div.profile-actions button:nth-child(2)")
    await page.click('app-dashboard div.profile-actions button:nth-child(2)')
    await page.waitForSelector('app-settings form > div.st-card-v1 > div.align-items-center')
  })
  it("Account/condition type check", async() => {
    const subscriptionType = await page.$eval('.has-mobile-tab > div:nth-child(4) > h5 > span', e => e.innerText)
    expect(subscriptionType).toBe('BASIC')
  })
  it("Change email", async() => {
    await page.$eval('input[formcontrolname="email"]', e => e.value = '')
    await page.type('input[formcontrolname="email"]', process.env.COMPMAIL)
    await page.click('app-settings form > button')
    await page.waitForSelector('app-settings form div.msg.msg--success')
  })
  it("Enable/Disable notification", async() => {
    await page.click('label.sd-check')
    await page.click('app-settings form > button')
    await page.waitForSelector('app-settings form div.msg.msg--success')
  })
  it.skip("Delete account", async() => {
    await page.click('app-settings > div.has-mobile-tab > div:nth-child(5) > button')
  })
  describe("Change current password", async() => {
    it("Open Password Form", async() => {
      await page.click('i.icon-pencil')
      await page.waitForSelector('input[formcontrolname="old_password"]')
    })
    it("Enter current password", async() => {
      await page.type('input[formcontrolname="old_password"]', process.env.PASSWORD)
    })
    it("Enter new password", async() => {
      await page.type('input[formcontrolname="new_password"]', process.env.PASSWORD)
    })
    it("Repeat New password", async() => {
      await page.type('input[formcontrolname="new_password_repeat"]', process.env.PASSWORD)
      await page.click('app-settings form > button')
      await page.waitForSelector('app-settings form div.msg.msg--success')
    })
  })
})

describe("Other Favourites Page", async() => {
  var hasMultiple=false
  it("Goto Other Fvourites Page", async() => {
    await page.waitForSelector('app-settings > div.has-mobile-tab > app-mobile-tab-header > ul > li:nth-child(1)')
    await page.click('app-settings > div.has-mobile-tab > app-mobile-tab-header > ul > li:nth-child(1)')
    await page.waitForSelector('div.profile-stats-wrapper div.stats-item.love-item')
    await page.click('div.profile-stats-wrapper div.stats-item.love-item')
    await page.waitForSelector('app-favorite-member')
  })
  it("convert profile to base state", async() => {
    const count = await page.$$eval('app-favorite-member', el => el.length)
    hasMultiple = count > 0 ? true : false
    classList = await page.$eval('app-favorite-member div.member-details button', e => Array.from(e.classList) )
    if(classList.findIndex( e => e=='btn-action--like-o') == -1) {
      await page.click('app-favorite-member div.member-details button')
      await page.waitForSelector('app-favorite-member:nth-child(1) div.member-details button.btn-action--like-o')
    }
  })
  it("Add to Favorites", async() => {
    await page.click('app-favorite-member:nth-child(1) div.member-details button.btn-action--like-o')
    await page.waitForSelector('app-favorite-member:nth-child(1) div.member-details button.btn-action--like')
    await page.waitForSelector('app-notification-list > div')
  })
  it("Remove From Favourites", async() => {
    await page.click("app-favorite-member:nth-child(1) div.member-details button.btn-action--like")
    await page.waitForSelector("app-favorite-member:nth-child(1) div.member-details button.btn-action--like-o")
    await page.waitForSelector('app-notification-list > div')
    await page.waitForFunction( () => !document.querySelector('app-notification-list > div') === true, {polling: 'mutation'} )
  })
  it("Logout", async() => {
    await page.waitForSelector("app-favorite > app-favorite-other app-mobile-tab-header > ul > li:nth-child(1) > a")
    await page.click("app-favorite > app-favorite-other app-mobile-tab-header > ul > li:nth-child(1) > a")
    await page.waitForSelector("app-dashboard div.profile-actions > div > button:nth-child(4)")
    await page.click("app-dashboard div.profile-actions > div > button:nth-child(4)")
    await page.waitForSelector("#bannerwrapper > div > div > div.landing-banner > button")
  })
})

describe("Message Detail page", async () => {
  it("login", async () => {
    await page.goto(baseUrl, { waitUntil: "networkidle0" })
    await page.waitForSelector('#bannerwrapper > div > div > div.landing-banner > button')
    await page.click('#bannerwrapper > div > div > div.landing-banner > button')
    await page.waitForSelector('input[formcontrolname="email_or_nick"]')
    await page.type('input[formcontrolname="email_or_nick"]', process.env.USERNAME)
    await page.type('input[formcontrolname="password"]', process.env.PASSWORD)
    await page.click('app-login > div > div > div > form > button')
    await page.waitForSelector('app-favorite-member')
  })
  it("goes to send message page", async () => {
    await page.waitForSelector('app-favorite-member:nth-child(1) > div > div.member-details > div > button')
    await page.click('app-favorite-member:nth-child(1) > div > div.member-details > div > button')
  })
  describe("Error cases", async () => {
    describe("Blank message", async () => {
      it("Sending blank message", async () => {
        await page.waitForSelector('app-chat-detail form > div.textarea-container > textarea')
        await page.click('app-chat-detail form > div.send > button')
      })
      it("Error displayed", async () => {
        await page.$eval('app-chat-detail form > div.textarea-container > div > i', e => {
          setTimeout(function () {
            e.style.display = 'none';
          }, 5000);
          return false;
        })
      })
    })
    describe("Sending single character in message", async () => {
      it("Sending single character", async () => {
        await page.type('app-chat-detail form > div.textarea-container > textarea', 'm')
        await page.click('app-chat-detail form > div.send > button')
      })
      it("Error displayed", async () => {
        var twoCharacters = await page.$eval('app-chat-detail > div > div > div.msg.msg--error', e => e.innerText)
        expect('The message must be at least 2 characters.').toEqual(twoCharacters)
      })
    })
    describe("Message 500 letters limitation", async() => {
      it("Message 500 letters limitation", async() => {
        await page.$eval('app-chat-detail form textarea', e => e.value = '')
        await page.type('app-chat-detail form textarea', process.env.FIVE_HUNDRED_CHARS)
        const textLength = await page.$eval('app-chat-detail form textarea', e => e.value.length)
        expect(textLength).toBe(500)
      })
    })
  })

  describe("Success cases", async() => {
    describe.skip("Elite User", async() => {
      it("Goto Landing", async() => {
        await page.click('app-top-bar > div.top-header--icon-left.icon-left > button')
        await page.waitForSelector('app-favorite-member')
      })
      it("Send messages to 5 different users", async() => {
        var msgUsers = []
        while(msgUsers.length < 5) {
          await page.waitForSelector('app-favorite-member:nth-child(1) div.member-details > h5')
          const user = await page.$eval('app-favorite-member:nth-child(1) div.member-details > h5', e => e.innerText)
          if(msgUsers.indexOf(user) !== -1) {
            await page.reload({waitUntil: 'networkidle0'})
          } else {
            msgUsers.push(user)
            await page.click('app-favorite-member:nth-child(1) div.member-details button')
            await page.waitForSelector('span.header-title')
            await page.type('app-chat-detail form textarea', 'hola hola hola')
            await page.click('app-chat-detail form > div.send > button')
            await page.waitForSelector('.chat-body')
            await page.click('app-top-bar > div.top-header--icon-left.icon-left > button')
            await page.waitForSelector('app-favorite-member')
          }
        }
      })
      it("Send message to 6th user redirects to payment page", async() => {
        await page.click('app-favorite-member:nth-child(1) div.member-details button')
        await page.waitForSelector('span.header-title')
        await page.type('app-chat-detail form textarea', 'hola hola hola')
        await page.click('app-chat-detail form > div.send > button')
        await page.waitForSelector("div.payment-page > div:nth-child(2) > div.msg.msg--info")
      })
      it("Logout", async() => {
        await page.click('app-payment app-mobile-tab-header > ul > li:nth-child(1)')
        await page.waitForSelector('app-dashboard div.profile-actions button:nth-child(4)')
        await page.click('app-dashboard div.profile-actions button:nth-child(4)')
        await page.waitForSelector('#bannerwrapper div.landing-banner > button')
      })
    })
    describe("Basic User", async() => {
      it.skip("Login as basic", async() => {
        await page.click('#bannerwrapper > div > div > div.landing-banner > button')
        await page.waitForSelector('input[formcontrolname="email_or_nick"]')
        await page.type('input[formcontrolname="email_or_nick"]', process.env.RJ_ELITE_USER)
        await page.type('input[formcontrolname="password"]', process.env.PASSWORD)
        await page.click('app-login > div > div > div > form > button')
        await page.waitForSelector('app-favorite-member')
      })
      it("Goto Landing", async() => {
        await page.click('app-top-bar > div.top-header--icon-left.icon-left > button')
        await page.waitForSelector('app-favorite-member')
      })
      it("Send Message", async() => {
        await page.click('app-favorite-member:nth-child(1) div.member-details button')
        await page.waitForSelector('span.header-title')
        await page.type('app-chat-detail form textarea', 'hola hola hola')
        await page.click('app-chat-detail form > div.send > button')
      })
      it("Redirect to payment page", async() => {
        await page.waitForSelector("div.payment-page > div:nth-child(2) > div.msg.msg--info")
      })
      it("Logout", async() => {
        await page.waitForSelector("app-payment > div > app-mobile-tab-header > ul > li:nth-child(1)")
        await page.click("app-payment > div > app-mobile-tab-header > ul > li:nth-child(1)")
        await page.waitForSelector("app-dashboard div.profile-actions > div > button:nth-child(4)")
        await page.click("app-dashboard div.profile-actions > div > button:nth-child(4)")
        await page.waitForSelector("#bannerwrapper > div > div > div.landing-banner > button")
      })
    })
  })
})

describe("Support/Contact Page", async () => {
  it("GoTo Contact Page", async () => {
    await page.goto(baseUrl, { waitUntil: 'networkidle0' })
    await page.waitForSelector('#landing-page-wrap > app-footer > div > div > div > ul > li:nth-child(1) > a')
    await page.click('#landing-page-wrap > app-footer > div > div > div > ul > li:nth-child(1) > a')
  })
  describe("Accordion", async () => {
    var randomAccordian
    var accordionLength
    var accordianArr = []
    var newAccordionLength
    var newOpenRandom
    it("Initial setup", async () => {
      await page.reload({ waitUntil: 'networkidle0' })
      // await page.waitForSelector('div.page-content-header')
      var accordionLength = await page.$$eval('app-contact app-accordion', e => e.length)
      await page.waitForFunction(() => document.querySelectorAll("app-contact app-accordion"), e => e.length === accordionLength)

      randomAccordian = await page.$$eval('app-contact app-accordion',
        e => Math.floor(Math.random() * e.length)
      )
      newAccordionLength = accordionLength
      for (var i = 0; i < newAccordionLength; i++) {
        accordianArr.push(i);
      }
      newOpenRandom = Math.floor(Math.random() * accordianArr.length)
    })

    describe("Accordion expand", async () => {
      it("Check initial arrow direction", async () => {
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--arrow .icon-down-arrow-of-angle`)
      })
      it("Expand & check content + arrow", async () => {
        await page.click(`app-contact app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--title`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--arrow .icon-up-arrow-angle`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--content`)
      })
    })

    describe("Accordian collapse", async () => {
      it("Check initial arrow direction", async () => {
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--arrow .icon-up-arrow-angle`)
      })
      it("collapse & check content + arrow", async () => {
        await page.click(`app-contact app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--title`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--arrow .icon-down-arrow-of-angle`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--content`, { hidden: true })
      })
    })

    describe("opening random accordian and click on another random accordian closes previously opened accordian", async () => {
      it("expand random accordian and check for arrow and content", async () => {
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--arrow .icon-down-arrow-of-angle`, { timeout: 60000 })
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--content`, { hidden: true })
        await page.click(`app-contact app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--title`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--arrow .icon-up-arrow-angle`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--content`)
      })
      it("opening another random accordian and check for previous accordian arrow and content", async () => {
        var newarray = accordianArr.slice(0);
        newarray.splice(newOpenRandom, 1)
        var newCloseRandom = newarray[Math.floor(Math.random() * newarray.length)]
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newCloseRandom + 1}) .accordion--title .accordion--arrow .icon-down-arrow-of-angle`)
        await page.click(`app-contact app-accordion:nth-of-type(${+newCloseRandom + 1}) .accordion--title`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newCloseRandom + 1}) .accordion--title .accordion--arrow .icon-up-arrow-angle`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newCloseRandom + 1}) .accordion--content`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--title .accordion--arrow .icon-down-arrow-of-angle`)
        await page.waitForSelector(`app-contact app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--content`, { hidden: true })
      })
    })
    describe("Error Checks", async () => {
      it("Submitting form without filling any field", async () => {
        await page.waitForSelector('app-root > app-contact > div > div > app-contact-form')
        await page.click('app-root > app-contact > div > div > app-contact-form')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(8) > button')
        await page.click('#form-wrapper > form > div:nth-child(8) > button')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(1) > div.msg.msg--error')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(2) > div.msg.msg--error')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(3) > div.msg.msg--error')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(4) > div.msg.msg--error')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(5) > div.msg.msg--error')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(6) > div.msg.msg--error')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(7) > div.msg.msg--error')
      })
      it("Check if captcha loads successfully", async () => {
        await page.waitForSelector('#ngrecaptcha-0')
      })
    })
    describe("Valid form submit", async () => {
      it("Valid form submit", async () => {
        await page.type('#form-wrapper > form > div:nth-child(2) > input', 'rajdeep')
        await page.type('#form-wrapper > form > div:nth-child(3) > input', 'This Is Test Subject')
        await page.type('#form-wrapper > form > div:nth-child(4) > input', 'rajdeep@itobuz.com')
        await page.type('#form-wrapper > form > div:nth-child(5) > input', 'rajdeep@itobuz.com')
        await page.type('#form-wrapper textarea', 'This is my test message to submit form')
        await page.click('#form-wrapper > form > div:nth-child(8) > button')
        await page.waitForSelector('#form-wrapper > form > div:nth-child(7) > div.msg.msg--error')
      })
    })
  })
})

describe("Advanced Search page", async () => {
  describe("Quick Search Cases", async () => {
    describe("Random search", async () => {
      it("Initial setup", async () => {
        await page.goto(baseUrl, { waitUntil: "networkidle0" }) // to remove
        await page.waitForSelector('#bannerwrapper > div > div > div.landing-banner > button')
        await page.click('#bannerwrapper > div > div > div.landing-banner > button')
        await page.waitForSelector('input[formcontrolname="email_or_nick"]')
        await page.type('input[formcontrolname="email_or_nick"]', process.env.USERNAME)
        await page.type('input[formcontrolname="password"]', process.env.PASSWORD)
        await page.click('app-login > div > div > div > form > button')
        await page.waitForSelector('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(2) > a')
        await page.click('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(2) > a')
      })
      it("Selecting seeking randomly", async () => {
        await page.reload({ waitUntil: "networkidle0" })
        const randomSeeking = Math.floor(Math.random() * 3) + 1
        await page.waitForSelector('app-search div.container.quick-search-mobile > div > div:nth-child(1) > div > div > div:nth-child(1) > label')
        await page.click(`app-search div.container.quick-search-mobile > div > div:nth-child(1) > div > div > div:nth-child(${randomSeeking}) > label`)
      })
      it('selecting age and province randomly', async () => {
        let selectBoxesSelectors = [
          '.quick-search-mobile .card select[formcontrolname="age"]',
          '.quick-search-mobile .card select[formcontrolname="province_id"]'
        ]
        await page.selectRandom(selectBoxesSelectors, { multiple: true })
      })
      it("fast search and reached result page", async () => {
        await page.click('app-root > app-search > div > div > form > h3')
        await page.waitForSelector('app-search-result > div > div.container')
      })
      it("search with profile pics", async () => {
        const placeHolderImagesLength = await page.$$eval('app-search-result app-favorite-member > div > div.profile-pic', (el, domain) => Array.from(el).map(e => e.style.backgroundImage).filter(e => e.indexOf(domain) > -1).length, api.split('.')[1])
        expect(placeHolderImagesLength).toBe(0)
      })
    })

    describe("Search which has results", async () => {
      var lookingVal;
      var ageVal;
      var provinceVal;
      it("Selecting options which is known to provide results", async () => {
        await page.waitForSelector('app-search-result > div > app-page-title > div > button')
        await page.click('app-search-result > div > app-page-title > div > button')
        await page.waitForSelector('.quick-search-mobile .card select[formcontrolname="age"]')
        // seeking
        await page.click('app-search div.container.quick-search-mobile > div > div:nth-child(1) > div > div > div:nth-child(1) > label')
        // with photo
        await page.click('div.container.quick-search-mobile > div > div:nth-child(2) > div > div > label > span')
        ageVal = await page.$eval('.quick-search-mobile .card select[formcontrolname="age"] > option:nth-child(5)', e => e.value.split('-'))
        const ageForSelect = await page.$eval('.quick-search-mobile .card select[formcontrolname="age"] > option:nth-child(5)', e => e.value)
        await page.select('.quick-search-mobile .card select[formcontrolname="age"]', ageForSelect)

        await page.waitForFunction(() => document.querySelector('.quick-search-mobile .card select[formcontrolname="province_id"]').value, { polling: 'mutation' })
        const provinceForSelect = await page.$eval('app-search div.container.quick-search-mobile > div > div:nth-child(4) > div > select > option:nth-child(32)', e => e.value)
        await page.select('app-search div.container.quick-search-mobile > div > div:nth-child(4) > div > select', provinceForSelect)
        provinceVal = await page.$eval('.quick-search-mobile .card select[formcontrolname="province_id"]', e => e.selectedOptions[0].innerText)
      })
      it("started search and reached result page with results", async () => {
        await page.click('app-root > app-search > div > div > form > h3')
        await page.waitForSelector('app-search-result > div > div.container')
      })
      it("comparing Age in search result", async () => {
        await page.waitForSelector('app-search-result app-favorite-member:nth-child(1) > div > div.member-details > span')
        const ageResult = await page.$eval('app-search-result app-favorite-member:nth-child(1) > div > div.member-details > span', e => +(e.innerText).split(' ')[0])
        expect(ageResult).toBeNull
        expect(ageResult).toBeLessThanOrEqual(+ageVal[1])
        expect(ageResult).toBeGreaterThanOrEqual(+ageVal[0])
      })
      it("comparing Province in search result", async () => {
        await page.waitForSelector('app-search-result app-favorite-member:nth-child(1) > div > div.member-details > span')
        const provinceResult = await page.$eval('app-search-result app-favorite-member:nth-child(1) > div > div.member-details > span', e => (e.innerText).split(' ')[2])
        expect(provinceResult).toEqual(provinceVal)
      })
      it("search without profile pics", async () => {
        const placeHolderImagesLength = await page.$$eval('app-search-result app-favorite-member > div > div.profile-pic', (el, domain) => Array.from(el).map(e => e.style.backgroundImage).filter(e => e.indexOf(domain) > -1).length, api.split('.')[1])
        expect(placeHolderImagesLength).toBeGreaterThanOrEqual(1)
      })
    })

    describe("search with no result", async () => {
      it("Selecting options which is known to provide NO results", async () => {
        await page.waitForSelector('app-search-result > div > app-page-title > div > button')
        await page.click('app-search-result > div > app-page-title > div > button')
        await page.waitForSelector('app-search div.container.quick-search-mobile > div > div:nth-child(1) > div > div > div:nth-child(1) > label')
        await page.click('app-search div.container.quick-search-mobile > div > div:nth-child(1) > div > div > div:nth-child(1) > label')
        const ageForSelect = await page.$eval('.quick-search-mobile .card select[formcontrolname="age"] > option:nth-child(8)', e => e.value)
        await page.select('.quick-search-mobile .card select[formcontrolname="age"]', ageForSelect)
        await page.waitForFunction(() => document.querySelector('app-search div.container.quick-search-mobile > div > div:nth-child(4) > div > select').value, { polling: 'mutation' })
        const provinceForSelect = await page.$eval('app-search div.container.quick-search-mobile > div > div:nth-child(4) > div > select > option:nth-child(41)', e => e.value)
        await page.select('app-search div.container.quick-search-mobile > div > div:nth-child(4) > div > select', provinceForSelect)
      })
      it("started search and reached result page with info box showing 'no results'", async () => {
        await page.click('app-root > app-search > div > div > form > h3')
        await page.waitForSelector('div.no-favs .msg--info');
      })
    })

    describe("Advanced Search", async () => {
      describe("Random advanced search", async () => {
        it("0", async () => {
          await page.click('app-search-result > div > app-page-title > div > button')
        })
        it("1", async () => {
          // await page.click('app-search-result app-page-title > div > button')
          await page.reload({ waitUntil: "networkidle0" })
          const randomSeeking = Math.floor(Math.random() * 3) + 1

          // Selecting seeking randomly
          await page.waitForSelector('app-search div.container.quick-search-mobile > div > div:nth-child(1) > div > div > div:nth-child(1) > label')
          await page.click(`app-search div.container.quick-search-mobile > div > div:nth-child(1) > div > div > div:nth-child(${randomSeeking}) > label`)
        })
        it("2", async () => {
          // selecting age and province randomly
          let selectBoxesSelectors1 = [
            '.quick-search-mobile .card select[formcontrolname="age"]',
            '.quick-search-mobile .card select[formcontrolname="province_id"]'
          ]
          await page.selectRandom(selectBoxesSelectors1, { multiple: true })
        })
        it("3", async () => {
          // random selection in general
          await page.click('.card div:nth-child(1) > a')
          let selectBoxesSelectors2 = [
            'form select[formcontrolname="marital_status_id"]',
            'form select[formcontrolname="eye_color_id"]',
            'form select[formcontrolname="hair_color_id"]',
            'form select[formcontrolname="body_type_id"]',
            'form select[formcontrolname="height_from"]',
            'form select[formcontrolname="height_to"]',
            'form select[formcontrolname="weight_from"]',
            'form select[formcontrolname="weight_to"]',
            'form select[formcontrolname="smoke_id"]'
          ]
          await page.selectRandom(selectBoxesSelectors2, { multiple: true })
        })
        it("4", async () => {
          // random selection in opento
          await page.click('.card div:nth-child(3) > a')
          await page.waitForSelector('#ngb-panel-1 > app-checkbox-group > div:nth-child(1) > div > label.form-check-label.actual')
          let selectCheck3 = [
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(1) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(2) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(3) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(4) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(5) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(6) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(7) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(8) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(9) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(10) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(11) > div > label.form-check-label.actual',
            '#ngb-panel-1 > app-checkbox-group > div:nth-child(12) > div > label.form-check-label.actual',
          ]
          await page.checkRandom(selectCheck3)
        })
        it("5", async () => {
          // random selection in prefrences
          await page.click('.card div:nth-child(5) > a')
          await page.waitForSelector('#preventchange-3 > app-checkbox-group > div:nth-child(1) > div > label.form-check-label.actual')
          let selectCheck4 = [
            '#preventchange-3 > app-checkbox-group > div:nth-child(1) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(2) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(3) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(4) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(5) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(6) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(7) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(8) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(9) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(10) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(11) > div > label.form-check-label.actual',
            '#preventchange-3 > app-checkbox-group > div:nth-child(12) > div > label.form-check-label.actual',
          ]
          await page.checkRandom(selectCheck4)
        })
        it("6", async () => {
          // random selection in character
          await page.click('.card div:nth-child(7) > a')
          await page.waitForSelector('#preventchange-4 > app-checkbox-group > div:nth-child(1) > div > label.form-check-label.actual')
          let selectCheck5 = [
            '#preventchange-4 > app-checkbox-group > div:nth-child(1) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(2) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(3) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(4) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(5) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(6) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(7) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(8) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(9) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(10) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(11) > div > label.form-check-label.actual',
            '#preventchange-4 > app-checkbox-group > div:nth-child(12) > div > label.form-check-label.actual'
          ]
          await page.checkRandom(selectCheck5)
        })
        it("7", async () => {
          await page.waitFor(3000)
          await page.waitForSelector('body > app-root > app-search > div > div > form > div.open-to > div > button')
          await page.evaluate(() => {
            document.querySelector('body > app-root > app-search > div > div > form > div.open-to > div > button').click();
            document.querySelector('body > app-root > app-search > div > div > form > div.open-to > div > button').click();
          })
          await page.waitForSelector('app-search-result > div > div')
        })
      })
    })
    describe("Accordion", async () => {
      it("loop through all Accordian and check content", async () => {
        await page.waitForSelector('body > app-root > app-search-result > div > app-page-title > div > button');
        await page.click('body > app-root > app-search-result > div > app-page-title > div > button')
        for (i = 1; i < 5; i++) {
          await page.waitForSelector(`ngb-accordion .card .card-header:nth-child(${i}) a`)
          await page.click(`ngb-accordion .card .card-header:nth-child(${i}) a`)
          await page.waitForSelector(`ngb-accordion .card .card-block:nth-child(${i + 1})`)
          await page.click(`ngb-accordion .card .card-header:nth-child(${i}) a`)
          await page.waitForSelector(`ngb-accordion .card .card-block:nth-child(${i + 1})`, { hidden: true })
        }
      })
    })
  })
})

describe("Faq page", async () => {
  describe("Accordion", async () => {
    var randomAccordian
    var accordionLength
    var accordianArr = []
    var newAccordionLength
    var newOpenRandom
    it("Initial setup", async () => {
        await page.goto(baseUrl, { waitUntil: "networkidle0" })
        await page.waitForSelector('app-footer ul > li:nth-child(3) > a')
        await page.click('app-footer ul > li:nth-child(3) > a')
        await page.reload({ waitUntil: 'networkidle0' })
        await page.waitForSelector('app-faq > div > app-top-bar')
        var accordionLength = await page.$$eval('app-faq app-accordion', e => e.length)
        await page.waitForFunction(() => document.querySelectorAll("app-faq app-accordion"), e => e.length === accordionLength)
        randomAccordian = await page.$$eval('app-faq app-accordion',
        e => Math.floor(Math.random() * e.length)
      )
      // new
      newAccordionLength = accordionLength
      for (var i = 0; i < newAccordionLength; i++) {
        accordianArr.push(i);
      }
      newOpenRandom = Math.floor(Math.random() * accordianArr.length)
    })
    describe("Accordion expand", async () => {
      it("Check initial arrow direction", async () => {
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--arrow .icon-down-arrow-of-angle`)
      })
      it("Expand & check content + arrow", async () => {
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1})`)
        await page.click(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--title`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--title .accordion--arrow .icon-up-arrow-angle`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--content`)
      })
    })
    describe("Accordian collapse", async () => {
      it("Check initial arrow direction", async () => {
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--arrow .icon-up-arrow-angle`)
      })
      it("collapse & check content", async () => {
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--title`)
        await page.click(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--title`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--arrow .icon-down-arrow-of-angle`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+randomAccordian + 1}) .accordion--content`, { hidden: true })
      })
    })
    describe("open random accordian and click on another random accordian close previously opened accordian", async () => {
      it("expand random accordian and check for arrow and content", async () => {
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--arrow .icon-down-arrow-of-angle`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--content`, { hidden: true })
        await page.click(`app-faq app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--title`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--arrow .icon-up-arrow-angle`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--content`)
      })
      it("opening another random accordian and check for previous accordian arrow and content", async () => {
        var newarray = accordianArr.slice(0);
        newarray.splice(newOpenRandom, 1)
        var newCloseRandom = newarray[Math.floor(Math.random() * newarray.length)]
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newCloseRandom + 1}) .accordion--arrow .icon-down-arrow-of-angle`)
        await page.click(`app-faq app-accordion:nth-of-type(${+newCloseRandom + 1}) .accordion--title`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newCloseRandom + 1}) .accordion--arrow .icon-up-arrow-angle`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newCloseRandom + 1}) .accordion--content`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--arrow .icon-down-arrow-of-angle`)
        await page.waitForSelector(`app-faq app-accordion:nth-of-type(${+newOpenRandom + 1}) .accordion--content`, { hidden: true })
        await page.waitFor(3000)
      })
    })
  })

})

describe("Edit Profile page", async() => {
  it('login as basic and goto edit page', async() => {
    await page.goto(baseUrl, { waitUntil: "networkidle0" })
    await page.waitForSelector('app-mobile-tab-header > ul > li:nth-child(1) > a')
    await page.click('app-mobile-tab-header > ul > li:nth-child(1) > a')
    await page.waitForSelector('div.profile-actions > div > button:nth-child(1)')
    await page.click('div.profile-actions > div > button:nth-child(1)')
    await page.waitForSelector('app-edit-profile form > div:nth-child(3) > div.detail-item.name > input')
  })
  describe("Error checks", async() => {
    it("Empty name error", async() => {
      await page.$eval('app-edit-profile form > div:nth-child(3) > div.detail-item.name > input', e => e.value = '')
      await page.type('app-edit-profile form > div:nth-child(3) > div.detail-item.name > input', 'a')
      await page.keyboard.down('Backspace')
      await page.waitForSelector('app-edit-profile form > div:nth-child(3) > div.detail-item.name > input + .msg--error')
    })
    it("----------------------------- city error", async() => {
      await page.waitForSelector('app-edit-profile form > div:nth-child(3) > div.detail-item.city-detail > p-dropdown > div > label')
      await page.click('app-edit-profile form > div:nth-child(3) > div.detail-item.city-detail > p-dropdown > div > label')
      await page.waitForSelector('app-edit-profile form > div:nth-child(3) > .city-detail > p-dropdown > div > .ui-dropdown-panel.ui-widget-content > div.ui-dropdown-items-wrapper > ul > li:nth-child(1) > span')
      await page.waitForSelector('app-edit-profile form > div:nth-child(3) > .city-detail > p-dropdown > div > .ui-dropdown-panel.ui-widget-content > div.ui-dropdown-items-wrapper > ul > li:nth-child(11) > span')
      await page.click('app-edit-profile form > div:nth-child(3) > .city-detail > p-dropdown > div > .ui-dropdown-panel.ui-widget-content > div.ui-dropdown-items-wrapper > ul > li:nth-child(11) > span')
      await page.waitForSelector('app-edit-profile form > div:nth-child(3) > div.detail-item.city-detail > div.msg--error')
    })
  })
  describe("'Edit Description' Accordion", async() => {
    it("click to expand", async() => {
      await page.reload({ waitUntil: "networkidle0" })
      await page.click('app-edit-profile form > button.btn-pink.m-0.btn-common-style')
    })
    it("Entering text changes button text from 'Edit Description' to 'Save Description'", async() => {
      await page.type('app-edit-profile form > div:nth-child(1) > div > textarea', 'a')
      const saveText = await page.$eval('app-edit-profile form > button.btn-pink.m-0.btn-common-style', e => e.innerText)
      expect(saveText).toEqual('SAVE DESCRIPTION')
    })
    it('can type less than 500 characters', async() => {
      await page.type('app-edit-profile form > div:nth-child(1) > div > textarea', message)
      const textLength = await page.$eval('app-edit-profile form > div:nth-child(1) > div > textarea', e => e.textLength)
      const remaining = await page.$eval('app-edit-profile form > div:nth-child(1) > div > p.char-left', e => e.innerText.split(' ')[0])
      expect(500 - textLength).toEqual(+remaining)
    })
    it("cant type only 500 characters", async() => {
      await page.type('app-edit-profile form > div:nth-child(1) > div > textarea', paras)
      const textLength = await page.$eval('app-edit-profile form > div:nth-child(1) > div > textarea', e => e.textLength)
      const zero = await page.$eval('app-edit-profile form > div:nth-child(1) > div > p.char-left', e => e.innerText.split(' ')[0])
      expect(500 - textLength).toEqual(+zero)
    })
    it("Click to collapse", async() => {
      await page.click('app-edit-profile form > button.btn-pink.m-0.btn-common-style')
    })
  })
  describe("Editing profile and saving", async() => {
    it('random changes in BASIC section', async() => {
      await page.waitForSelector('div.profile-actions > div > button:nth-child(1)')
      await page.click('div.profile-actions > div > button:nth-child(1)')
      // await page.reload({ waitUntil: "networkidle0" })
      await page.waitForSelector('app-edit-profile form select[formcontrolname="day"]')
      await page.$eval('app-edit-profile form > div:nth-child(3) > div.detail-item.name > input', e => e.value = '')
      await page.type('app-edit-profile form > div:nth-child(3) > div.detail-item.name > input', name)
      let selectBoxesSelectors1 = [
        'app-edit-profile form select[formcontrolname="day"]',
        'app-edit-profile form select[formcontrolname="month"]',
        'app-edit-profile form select[formcontrolname="year"]',
        'app-edit-profile form select[formcontrolname="marital_status_id"]',
        // 'app-edit-profile form select[formcontrolname="country_id"]'
      ]
      await page.selectRandom(selectBoxesSelectors1, { multiple: true })
      await page.waitFor(5000)
      await page.waitForSelector('app-edit-profile form select[formcontrolname="province_id"]')
      await page.selectRandom('app-edit-profile form select[formcontrolname="province_id"]')
      await page.waitFor(3000)
      await page.waitForSelector('app-edit-profile form > div:nth-child(3) > div.detail-item.city-detail > p-dropdown > div > label')
      await page.click('app-edit-profile form > div:nth-child(3) > div.detail-item.city-detail > p-dropdown > div > label')
      await page.waitForSelector('app-edit-profile form > div:nth-child(3) > .city-detail > p-dropdown > div > .ui-dropdown-panel.ui-widget-content > div.ui-dropdown-items-wrapper > ul > li:nth-child(1) > span')
      var random = await page.$$eval('app-edit-profile form > div:nth-child(3) > .city-detail > p-dropdown > div > .ui-dropdown-panel.ui-widget-content > div.ui-dropdown-items-wrapper > ul > li > span', e => {
        var arr = Array.from(e)
        var dotIndex = arr.map(el => el.innerText).indexOf('------------------------------------------') + 1
        do {
          var randomOption = Math.floor(Math.random() * arr.length) + 1
        } while (randomOption === dotIndex);
        return randomOption
        }
      )
      await page.click(`app-edit-profile form > div:nth-child(3) > .city-detail > p-dropdown > div > .ui-dropdown-panel.ui-widget-content > div.ui-dropdown-items-wrapper > ul > li:nth-child(${random}) > span`)
    })
    it("random change in GENERAL section", async() => {
      let selectBoxesSelectors2 = [
        '.detail-item select[formcontrolname="sex"]',
        '.detail-item select[formcontrolname="seeking"]',
        '.detail-item select[formcontrolname="hair_color_id"]',
        '.detail-item select[formcontrolname="eye_color_id"]',
        '.detail-item select[formcontrolname="body_type_id"]', 
        '.detail-item select[formcontrolname="height"]',
        '.detail-item select[formcontrolname="weight"]',
        '.detail-item select[formcontrolname="smoke_id"]'
      ]
      await page.selectRandom(selectBoxesSelectors2, { multiple: true })
    })
    it("random change in open to section", async() => {
      await page.click('app-edit-profile form > div:nth-child(7) > h4')
      await page.waitForSelector('app-open-to > div > form > div > app-checkbox-group > div:nth-child(1)')
      // await page.waitFor(3000)
      let selectCheck = [
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(2) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(3) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(4) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(5) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(6) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(7) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(8) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(9) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(10) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(11) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(12) label.form-check-label.actual'
      ]
      await page.checkRandom(selectCheck)
      await page.click('app-open-to > div > form > button')
    })
    it("random check in prefrences section", async() => {
      await page.click('app-edit-profile form > div:nth-child(8) > h4')
      await page.waitForSelector('app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual')
      let selectCheck = [
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(2) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(3) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(4) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(5) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(6) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(7) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(8) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(9) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(10) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(11) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(12) label.form-check-label.actual'
      ]
      await page.checkRandom(selectCheck)
      await page.click('app-open-to > div > form > button')
    })
    it("random check in character section", async() => {
      await page.click('app-edit-profile form > div:nth-child(9) > h4')
      await page.waitForSelector('app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual')
      let selectCheck = [
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(2) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(3) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(4) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(5) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(6) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(7) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(8) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(9) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(10) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(11) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(12) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(13) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(14) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(15) label.form-check-label.actual',
        'app-open-to > div > form > div > app-checkbox-group > div:nth-child(16) label.form-check-label.actual'
      ]
      await page.checkRandom(selectCheck)
      await page.click('app-open-to > div > form > button')
    })
    it("saving profile", async() => {
      await page.click('app-edit-profile form > button:nth-child(10)')
      await page.waitForSelector('app-dashboard > div > div.profile-name-wrapper')
    })
  })
  describe("'Featuring' popup", async() => {
    it('initial setup', async() => {
      await page.waitForSelector('app-dashboard div.profile-actions > div > button:nth-child(1)')
      await page.click('app-dashboard div.profile-actions > div > button:nth-child(1)')
    })
    describe('Open To', async() => {
      it('Check if checked box values are selected when popup is closed', async() => {
        await page.waitForSelector('app-edit-profile form > div:nth-child(7) > h4')
        await page.click('app-edit-profile form > div:nth-child(7) > h4')
        await page.waitForSelector('app-open-to > div > form > div > app-checkbox-group > div:nth-child(1)')
        // await page.waitFor(3000)
        let selectCheck = [
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(2) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(3) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(4) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(5) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(6) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(7) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(8) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(9) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(10) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(11) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(12) label.form-check-label.actual'
        ]
        await page.checkRandom(selectCheck)
        const openToArr = await page.$$eval('ngb-modal-window app-open-to form app-checkbox-group label.form-check-label.actual.active', e => Array.from(e).map(el => el.innerText))
        await page.click('app-open-to > div > form > button')
        const openToSelected = await page.$$eval('app-edit-profile form > div:nth-child(7) > span', e => Array.from(e).map(el => el.innerText))
        expect(openToArr).toEqual(openToSelected)
      })
    })
    describe('Preferences', async() => {
      it('Check if checked box values are selected when popup is closed', async() => {
        await page.click('app-edit-profile form > div:nth-child(8) > h4')
        await page.waitForSelector('app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual')
        let selectCheck = [
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(2) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(3) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(4) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(5) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(6) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(7) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(8) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(9) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(10) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(11) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(12) label.form-check-label.actual'
        ]
        await page.checkRandom(selectCheck)
        const openToArr = await page.$$eval('ngb-modal-window app-open-to form app-checkbox-group label.form-check-label.actual.active', e => Array.from(e).map(el => el.innerText))
        await page.click('app-open-to > div > form > button')
        const openToSelected = await page.$$eval('app-edit-profile form > div:nth-child(8) > span', e => Array.from(e).map(el => el.innerText))
        expect(openToArr).toEqual(openToSelected)
      })
    })
    describe('Character', async() => {
      it('Check if checked box values are selected when popup is closed', async() => {
        await page.click('app-edit-profile form > div:nth-child(9) > h4')
        await page.waitForSelector('app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual')
        let selectCheck = [
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(1) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(2) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(3) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(4) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(5) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(6) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(7) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(8) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(9) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(10) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(11) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(12) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(13) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(14) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(15) label.form-check-label.actual',
          'app-open-to > div > form > div > app-checkbox-group > div:nth-child(16) label.form-check-label.actual'
        ]
        await page.checkRandom(selectCheck)
        const openToArr = await page.$$eval('ngb-modal-window app-open-to form app-checkbox-group label.form-check-label.actual.active', e => Array.from(e).map(el => el.innerText))
        await page.click('app-open-to > div > form > button')
        const openToSelected = await page.$$eval('app-edit-profile form > div:nth-child(9) > span', e => Array.from(e).map(el => el.innerText))
        expect(openToArr).toEqual(openToSelected)
      })
    })
  })
  describe("Logout", async() => {
    it("Logout", async() => {
      await page.goto(baseUrl, { waitUntil: "networkidle0" })
      await page.waitForSelector('app-dashboard div.profile-actions button:nth-child(4)')
      await page.click("app-dashboard div.profile-actions button:nth-child(4)")
      await page.waitForSelector("#bannerwrapper div.landing-banner > button")
    })
  })
})

describe('Favorites page', async() => {
  describe('If Pagination exists (<24 profiles)', async() => {
    it('initial setup', async() => {
      await page.goto(baseUrl, { waitUntil: "networkidle0" })
      await page.waitForSelector('#bannerwrapper > div > div > div.landing-banner > button')
      await page.click('#bannerwrapper > div > div > div.landing-banner > button')
      await page.waitForSelector('input[formcontrolname="email_or_nick"]')
      await page.type('input[formcontrolname="email_or_nick"]', process.env.ELITUSER)
      await page.type('input[formcontrolname="password"]', process.env.PASSWORD)
      await page.click('app-login > div > div > div > form > button')
      await page.waitForSelector('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(1) > a')
      await page.click('app-mobile-dashboard > div > app-mobile-tab-header > ul > li:nth-child(1) > a')
      await page.waitForSelector('app-dashboard div.profile-stats-wrapper > div > div.stats-item.fav-item')
      await page.click('app-dashboard div.profile-stats-wrapper > div > div.stats-item.fav-item')
    })
    it('scroll down, Loader shows & then Next page results', async() => {
      await page.waitForSelector('app-favorite > app-favorite-my div.row > app-favorite-member div.profile-pic')
      await page.waitForSelector('app-favorite > app-favorite-my div.row > app-favorite-member:nth-child(24) div.profile-pic')
      await page.waitForSelector('app-favorite > app-favorite-my > div > div > app-loader > div > div > div.loader-parent')
      await page.hover('app-favorite > app-favorite-my > div > div > app-loader > div > div > div.loader-parent')
      await page.waitForSelector('app-favorite > app-favorite-my div.row > app-favorite-member:nth-child(25) div.profile-pic')
    })
  })
  describe('Delete profile', async() => {
    it("Delete random profile from list", async () => {
      await page.waitForSelector('app-favorite > app-favorite-my app-favorite-member div.member-details > div > div > button')
      var closeLength = await page.$$eval('app-favorite > app-favorite-my app-favorite-member div.member-details > div > div > button', e => e.length)
      await page.waitForFunction(() => document.querySelectorAll('app-favorite > app-favorite-my app-favorite-member div.member-details > div > div > button'), e => e.length === closeLength)
      var randomClose = await page.$$eval('app-favorite > app-favorite-my app-favorite-member div.member-details > div > div > button', e => Math.floor(Math.random() * e.length))
      await page.click(`app-favorite > app-favorite-my app-favorite-member:nth-of-type(${randomClose + 1}) div.member-details > div > div > button`)
      console.log('randomClose for close button', randomClose)
    })
    it("Check if deleted", async () => {
      await page.waitForSelector('app-notification-list .msg--success')
    })
  })
})