Automated Web Login Testing Without CAPTCHA

Understanding Automated Testing

Automated testing refers to the process of converting manual testing activities into machine-executed procedures. Fundamentally, automated testing shares the same objectives as manual testing, with the primary distinction being the context in which each approach excels. Automated testing becomes particularly valuable in scenarios where repetitive test execution is required.

When to Avoid Automation

Several scenarios make automation impractical:

  • Frequently changing requirements
  • Short project timelines
  • One-time test scripts
  • Limited time resources
  • High technical complexity
  • Low reusability potential

Automated Testing Process Example

Let's examine a practical example of automating login functionality for a web application. We'll focus on a simplified login interface that accepts either phone numbers or email addresses along with passwords.

The test scenarios include various combinations:

  • Registered phone + correct password
  • Registered phone + incorrect password
  • Unregistered phone + existing password
  • Unregistered phone + non-existent password
  • Empty phone and password fields
  • Empty phone field only
  • Empty password field only
  • Both fields populated

Automated test cases require more detailed specifications than manual test cases. Key elmeents include:

  • ID (unique identifier)
  • Feature name
  • Scenario description
  • Preconditions (given)
  • Test steps (when)
  • Expected results (then)
  • Actual results

Implementation Using unittest Framework

Here's a practical implementation using Python's unittest framework with Selenium WebDriver:

import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

class LoginTestSuite(unittest.TestCase):

    def setup_method(self):
        print("Initializing test")
        self.driver = webdriver.Chrome('/path/to/chromedriver')
        target_url = 'https://example.com/login'
        self.driver.get(target_url)
        remember_checkbox = self.driver.find_element_by_id('remember_me')
        if remember_checkbox.is_selected():
            remember_checkbox.click()

    def test_valid_credentials_login(self):
        print("Executing valid credentials test")
        
        self.driver.find_element_by_id('username_field').send_keys('valid_user@example.com')
        self.driver.find_element_by_id('password_field').send_keys('correct_password')
        self.driver.find_element_by_class_name('login-btn').click()
        time.sleep(5)
        
        try:
            profile_element = self.driver.find_element_by_class_name('user-profile')
            ActionChains(self.driver).move_to_element(profile_element).perform()
            time.sleep(2)
            self.driver.find_element_by_link_text('My Profile').click()
            profile_name = self.driver.find_element_by_xpath("//a[@class='profile-name']").text
            self.assertEqual(profile_name, 'Expected Username')
        except Exception as error:
            print(f"Test failed: {error}")
            raise error

    def test_empty_password_login(self):
        print("Executing empty password test")
        self.driver.find_element_by_id('username_field').send_keys('test_user@example.com')
        self.driver.find_element_by_id('password_field').send_keys('')
        self.driver.find_element_by_class_name('login-btn').click()
        time.sleep(3)
        
        try:
            error_message = self.driver.find_element_by_xpath("//span[@class='error-text']").text
            self.assertEqual(error_message, 'Password cannot be empty')
        except Exception as error:
            print(f"Test failed: {error}")
            raise error

    def teardown_method(self):
        self.driver.quit()
        print('Test completed')

if __name__ == "__main__":
    unittest.main()

The setup and teardown methods execute before and after each test case respectively. The unittest.main() function handles test discovery and execution by initializing test cases, parsing arguments, creating test suites, and running the tests.

Generating Test Reports

To generate comprehensive test reports, use HTMLTestRunner:

import unittest
import HTMLTestRunner
import time
import login_tests

test_suite = unittest.TestSuite()
test_loader = unittest.TestLoader()

test_suite.addTests(test_loader.loadTestsFromModule(login_tests))

timestamp = time.strftime("%Y-%m-%d_%H_%M_%S")
report_path = f"test_report_{timestamp}.html"

with open(report_path, "wb+") as report_file:
    report_runner = HTMLTestRunner.HTMLTestRunner(
        stream=report_file,
        verbosity=2,
        title='Login Functionality Test Report',
        description='Automated test execution results'
    )
    report_runner.run(test_suite)

Common Implementation Challenges

  • Ensure WebDriver version compatibility with your browser
  • Handle dynamic page elements appropriately
  • Manage test data effectively
  • Implement proper wait strategies

Tags: Selenium unittest python webdriver HTMLTestRunner

Posted on Thu, 16 Jul 2026 16:00:47 +0000 by gnunoob