Thursday 16 February 2023

Automate Gmail Login with pytest & Selenium

SDET Interview Question and Answers.  

Jenkins Interview Questions and Answers

Appium Interview Questions and Answers

Selenium Interview Questions and answers

GIT Interview Questions and Answers


If you are preparing for Selenium-Python Interview then also check below Q&A:
Python Interview Question & Answers Set - 01

Python Interview Q&A Set - 02

Python Interview Q&A Set - 03


If you are new to PYTHON then first check the post on How to Install Python on windows and mac?, once installation is complete then only checkout the below Q&A


To automate Gmail login with pytest, you can use the pytest framework along with the selenium package to simulate user actions on a web browser. Here are the steps you can follow:

  1. Install the pytest and selenium packages using pip:

pip install pytest selenium


  1. Download the appropriate driver for your browser. You can download the Chrome driver from https://sites.google.com/a/chromium.org/chromedriver/downloads. Make sure to select the version that matches the version of your browser.

  2. Create a new Python file for your test, and import the necessary modules:

import pytest
from selenium import webdriver


Create a fixture that sets up the Selenium WebDriver instance:


@pytest.fixture
def browser():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()



This fixture creates a new Chrome driver instance before the test runs, and quits the driver after the test is finished.

  1. Define a test that logs into Gmail using a valid username and password:

def test_login(browser):
    browser.get("https://mail.google.com")
    email_input = browser.find_element_by_css_selector("input[type='email']")
    email_input.send_keys("your-email-address")
    next_button = browser.find_element_by_css_selector("button[jsname='LgbsSe']")
    next_button.click()
    password_input = browser.find_element_by_css_selector("input[type='password']")
    password_input.send_keys("your-password")
    signin_button = browser.find_element_by_css_selector("button[jsname='LgbsSe']")
    signin_button.click()
    assert "Gmail" in browser.title



This test navigates to the Gmail login page, enters the email address and password, and clicks the "Next" and "Sign in" buttons. It then checks if the Gmail inbox is displayed by checking if the page title contains the string "Gmail".

  1. Run the test using pytest:

pytest test_gmail_login.py


This will launch the Chrome browser and run the test. If the test passes, you should see a message indicating that one test has passed. If the test fails, you should see an error message indicating the reason for the failure.


How to use Selenium with a remote webdriver in Python?


*******************************************************************
For any doubts or career guidance, reach out to me 


********************************************************************





Do remember that knowing Linux is one of the most important aspect to work as an SDET.

Basic Linux Commands for Automation QA


****************************************

TOP 15 BDD - CUCUMBER Interview Q&A


************************************************

✍️AUTHORLinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employees and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET.

For more details whatsapp : https://lnkd.in/dnBWDM33

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

Sorting with Examples & Time Complexity for SDET

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl Bubble Sort:    Bubb...