I'm new to the selenium/python field. I have been trying to make test cases using python with selenium to test the login form of a particular webpage. I have 10 test cases testing various scenarios so far. What I want to do is reduce the amount of repetition that's in the code.

this is the login\_form\_base I use as a module for the testcases:

```
from expects import expect, contain
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Login():

    def __init__(self, driver):
        self.driver = driver

    def Username(self, user_name):
        self.driver.find_element_by_name('email').send_keys(user_name)

    def Password(self, password):
        self.driver.find_element_by_name('password').send_keys(password)

    def Submit_wait_confirm_error(self):
        driver = self.driver
        self.driver.find_element_by_class_name('fw-button').click()
        WebDriverWait(driver, 5).until(
            EC.presence_of_all_elements_located(('id', 'body-wrapper-full')))
        error_signing_in = self.driver.find_element_by_id("body-wrapper-full")
        expect(error_signing_in.text).to(contain("Invalid username/password"))

    def Confirm_signed_in(self):
        error_signing_in = self.driver.find_element_by_id("body-wrapper-full")
        expect(error_signing_in.text).not_to(contain(
            "Invalid username/password"))

```

And this is the code with the testcases:

```
from unittest import main, TestCase

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from login_form_base import Login

class SomePageLoginTest(TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome()

    def tearDown(self):
        self.driver.quit()

    def test_strings(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("wrong username")
        login.Password("wrong password")
        login.Submit_wait_confirm_error() 

    def test_long_strings(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
        login.Password("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
        login.Submit_wait_confirm_error()

    def test_negative_numbers(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("-123456789")
        login.Password("-123456789")
        login.Submit_wait_confirm_error()

    def test_special_characters(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("~!@$%^&*()_+:><?||\=-][;/.,]")
        login.Password("~!@$%^&*()_+:><?||\=-][;/.,]")
        login.Submit_wait_confirm_error()

    def test_long_number(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("1234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567")
        login.Password("1234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567891234567893456789123456789123456789123456789123456789123456789")
        login.Submit_wait_confirm_error()

    def test_only_email(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("an_email@gmail.com")
        login.Password("password@gmail.com")
        login.Submit_wait_confirm_error()

    def test_no_email(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("")
        login.Password("pass")
        login.Submit_wait_confirm_error()

    def test_no_password(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("email@email.com")
        login.Password("")
        login.Submit_wait_confirm_error()

    def test_empty_password_username(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("")
        login.Password("")
        login.Submit_wait_confirm_error()

    def test_correct_username_password(self):
        driver = self.driver
        self.driver.get("some url")
        login = Login(driver)
        login.Username("actual_username")
        login.Password("actual_password")
        self.driver.find_element_by_class_name('fw-button').click()
        WebDriverWait(driver, 5).until(
            EC.presence_of_all_elements_located(('id', 'body-wrapper-full')))
        directory_image_visible = self.driver.find_element_by_class_name(
            "webs-image-crop")
        login.Confirm_signed_in()
        #  above finds the image labeled "directory"
        #  it is only visible when logged in
        directory_image_visible.is_displayed()

```

The login\_form\_base module is fine in my opinion. But the test case look like they can be condensed without taking away from their simplicity. I've done my best so far from 150+ lines of code to this but I'm just not sure how I can simplify from here. 

By the way, the code is functioning just fine.