Thursday, 24 January 2019

How to test login to GSuite calendar using Cypress

Environment

  • Windows 10
  • NodeJs 8
  • Cypress 3.1.2
  • Selenium
  • Chromium v59

How to authenticate to Google calendar using Cypress?

I need to run automated tests on a Chrome extension that I am developing. The first step is to authenticate/login to GSuite calendar.

I am using Cypress but it is not allowing me to login into GSuite calendar. Instead when "clicking sign-in" (from Cypress) it jumps to the Next button again.

My code snippet

describe('Login',function() {
   it('Go to GSuite calendar', function() {
     cy.visit('https://www.google.com/calendar')
   })

   it('Login', function() {
     cy.get('#Email').type('my user')
     cy.get('#next').click()
     cy.get('#Passwd').type('my password')
     cy.get('#signIn').click()
   })
})  

This fails and takes me to the Next button

Screenshots

1. Hit execute

First image

2. At the end, it returns to the initial screen instead of logging me in

Second image

My Try with Selenium & it works

from selenium import webdriver
import time

# variables for userid & password
u = "JohnDoe@xxxx-labs.com"
p = "Mysecretpassword"

# chromedriver installation required for login through google chrome
driverpath = "C:/Users/pjain2/Desktop/chromedriver_win32/chromedriver"

# launch google calendar login page
d = webdriver.Chrome(driverpath)
d.get("https://www.google.com/calendar")

# fill email field send_keys for filling text
e = d.find_element_by_id("identifierId")
e.send_keys(u)

# find & click next button
d.find_element_by_xpath("//*[@id='identifierNext']/content/span").click()
time.sleep(2)

# enter password
e = d.find_element_by_xpath("//*[@id='password']/div[1]/div/div[1]/input")
e.send_keys("Mysecretpassword")
time.sleep(2)

# sign in
d.find_element_by_xpath("//*[@id='passwordNext']/content/span").click()
time.sleep(10)

Screenshot of successfully login to Google calendar

enter image description here I want to achieve the same thing with Cypress

Any pointers?



from How to test login to GSuite calendar using Cypress

No comments:

Post a Comment