Sunday, January 29, 2023

Gmail with pytest

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

def test_gmail_login_and_count_inbox():
    # Initialize the webdriver
    driver = webdriver.Firefox()
    driver.get("https://gmail.com")
    
    # Enter the username and password
    username = driver.find_element(By.ID, "identifierId")
    username.send_keys("your_email@gmail.com")
    next_button = driver.find_element(By.ID, "identifierNext")
    next_button.click()
    password = driver.find_element(By.NAME, "password")
    password.send_keys("your_password")
    next_button = driver.find_element(By.ID, "passwordNext")
    next_button.click()
    
    # Wait for the page to load and count the number of emails in the inbox
    driver.implicitly_wait(10)
    inbox_count = len(driver.find_elements(By.XPATH, "//table[@role='grid']/tbody/tr"))
    print(f"Number of emails in the inbox: {inbox_count}")
    
    # Close the webdriver
    driver.quit()

No comments:

Post a Comment