How can I design and implement test cases of a login page by using the Selenium library in the robot framework?

30    Asked by debbieJha in QA Testing , Asked on Apr 17, 2024

I am currently engaged in a particular task that is related to automating the testing of a login functionality for a web-based application by using the selenium library in the robot framework. The login page has the field for username, password, and a login button. How can I design and execute test cases to ensure comprehensive testing of this particular login smoothly? 

Answered by David

In the context of selenium, here is the example given of how you can design and implement the test cases by using the selenium library in the robot framework for testing a login functionality:-

Test cases for successful login:-

*** Test Cases ***

Successful Login Test

    Open Browser https://yourwebsite.com chrome

    Input Text    username_field    ${valid_username}
    Input Password password_field ${valid_password}
    Click Button login_button
    Wait Until Page Contains Element welcome_message
    Page Should Contain Welcome, ${valid_username}

    Close Browser Test cases for invalid credentials

*** Test Cases ***

Invalid Credentials Test   Open Browser https://yourwebsite.com chrome

    Input Text    username_field    ${invalid_username}
    Input Password password_field ${invalid_password}
    Click Button login_button

    Page Should Contain Invalid username or password  Close Browser Test cases for empty username

*** Test Cases ***

Empty Username Test

    Open Browser    https://yourwebsite.com    chrome
    Input Password password_field ${valid_password}
    Click Button login_button

    Page Should Contain Please enter your username  Close Browser Test cases for empty password

*** Test Cases ***

Empty Password Test

    Open Browser    https://yourwebsite.com    chrome
    Input Text username_field ${valid_username}
    Click Button login_button

    Page Should Contain Please enter your password Close Browser Test cases for forgot password link

*** Test Cases ***

Forgot Password Link Test

    Open Browser    https://yourwebsite.com    chrome
    Click Link forgot_password_link

    Page Should Contain Forgot Password Page  Close Browser

Here is the example given of how you can write Python coding by using the Selenium library for automation of the testing the login functionality of a web-based application:-

From selenium import webdriver
From selenium.webdriver.common.by import By
From selenium.webdriver.support.ui import WebDriverWait
From selenium.webdriver.support import expected_conditions as EC
# Initialize the Chrome driver
Driver = webdriver.Chrome()
# Navigate to the login page
Driver.get(https://yourwebsite.com)
# Define valid and invalid credentials
Valid_username = “valid_user”
Valid_password = “valid_pass”
Invalid_username = “invalid_user”
Invalid_password = “invalid_pass”
# Test case for successful login
Def test_successful_login():
    Username_field = driver.find_element_by_id(“username_field”)
    Password_field = driver.find_element_by_id(“password_field”)
    Login_button = driver.find_element_by_id(“login_button”)
    Username_field.send_keys(valid_username)
    Password_field.send_keys(valid_password)
    Login_button.click()
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, “welcome_message”)))
    Assert “Welcome, “ + valid_username in driver.page_source
# Test case for invalid credentials
Def test_invalid_credentials():
    Username_field = driver.find_element_by_id(“username_field”)
    Password_field = driver.find_element_by_id(“password_field”)
    Login_button = driver.find_element_by_id(“login_button”)
    Username_field.send_keys(invalid_username)
    Password_field.send_keys(invalid_password)
    Login_button.click()
    Assert “Invalid username or password” in driver.page_source
# Test case for empty username
Def test_empty_username():
    Password_field = driver.find_element_by_id(“password_field”)
    Login_button = driver.find_element_by_id(“login_button”)
    Password_field.send_keys(valid_password)
    Login_button.click()
    Assert “Please enter your username” in driver.page_source
# Test case for empty password
Def test_empty_password():
    Username_field = driver.find_element_by_id(“username_field”)
    Login_button = driver.find_element_by_id(“login_button”)
    Username_field.send_keys(valid_username)
    Login_button.click()
    Assert “Please enter your password” in driver.page_source
# Test case for forgot password link
Def test_forgot_password_link():
    Forgot_password_link = driver.find_element_by_link_text(“Forgot Password?”)
    Forgot_password_link.click()
    Assert “Forgot Password Page” in driver.page_source
# Run the test cases
Test_successful_login()
Test_invalid_credentials()
Test_empty_username()
Test_empty_password()
Test_forgot_password_link()
# Close the browser
Driver.quit()


Your Answer

Interviews

Parent Categories