import unittest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
class LoginTest(unittest.TestCase):
chrome_driver_path = "/Users/PycharmProjects/pythonProject/chromedriver"
@classmethod
def setUpClass(cls):
# Create a ChromeService object
cls.chrome_service = ChromeService(cls.chrome_driver_path)
@classmethod
def tearDownClass(cls):
pass # You can add any necessary class-level cleanup code here
def setUp(self):
# Create a browser instance using ChromeService
self.driver = webdriver.Chrome(service=self.chrome_service)
def tearDown(self):
# Close the browser
self.driver.quit()
def test_login(self):
# Open the login page
self.driver.get("https://login")
# Click the element with ID #rc-tabs-0-tab-2
element = self.driver.find_element(By.ID, "rc-tabs-0-tab-2")
element.click()
# Find username and password input fields and enter credentials
username_input = self.driver.find_element(By.ID, "account")
password_input = self.driver.find_element(By.ID, "password")
username_input.send_keys("liuyuanping2")
password_input.send_keys("t123456,")
# Click the login button
login_button_locator = "//span[contains(text(), '登 录')]"
element = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, login_button_locator))
)
element.click()
time.sleep(5)
# Add assertions or additional actions as needed
self.assertIn("刘元萍", self.driver.page_source)
if __name__ == "__main__":
unittest.main()