sample.cy.js [this file runs the auto-test script.]
/// <reference types="Cypress" />
import { Homepage } from "../pages/Homepage"
const homepage = new Homepage();
console.log(homepage)
describe('empty spec', () => {
beforeEach("visit google", ()=>{
homepage.navigate();
cy.viewport(1920, 1080)
})
it.only('Check Distance dropdown is working ', () => {
const login = homepage.facebookLogin();
})
})
Homepage.js [this is file where I defined and Initialized the method in which contain logic of what I want to do]
/// <reference types="Cypress" />
export class Homepage {
navigate() { //This function will lead to homePage -> SELECT LOCATION
cy.on('uncaught:exception', (err, runnable) => {
return false
})
cy.viewport(1920, 1080)
cy.visit(Cypress.env('host'));
cy.viewport(1920, 1080)
// cy.get(':nth-child(2) > .img-icon-nav').click()
cy.get(':nth-child(3) > .top-menu-item').click()
}
facebookLogin(){
const username = Cypress.env('facebookSocialLoginUsername')
const password = Cypress.env('facebookSocialLoginPassword')
const loginUrl = Cypress.env('facebookLoginUrl')
const cookieName = Cypress.env('qattCookieName')
const socialLoginOptions = {
username: username,
password: password,
loginUrl: loginUrl,
headless: true,
logs: true,
postLoginSelector: '#app > ion-app > ion-header > ion-grid.grid-desktop.topBar.md > ion-row > ion-col.md.ion-text-end.ion-float-right.ion-no-padding > ion-row > ion-col:nth-child(3) > div.user-profile.ion-hide-xl-down > span:nth-child(1) > img'
}
cy.clearCookies()
return cy.task('FacebookSocialLogin', socialLoginOptions).then(results => {
results['cookies'].forEach(cookie => {
if (cookie.domain.includes(cookieName)) {
cy.setCookie(cookie.name, cookie.value, {
domain: cookie.domain,
expiry: cookie.expires,
httpOnly: cookie.httpOnly,
path: cookie.path,
secure: cookie.secure
})
}
})
cy.window().then(window => {
Object.keys(results.ssd).forEach(key => window.sessionStorage.setItem(key, results.ssd[key]))
Object.keys(results.lsd).forEach(key => window.localStorage.setItem(key, results.lsd[key]))
})
})
}
}
I am trying to automate third-party login (0auth) of Facebook on a site. I have faced an issue when cypress types email and password and clicks login. But the Facebook page not redirecting to the home page.