我正在尝试在pycharm上运行python中的selenium webdriver的单元测试用例,我坚持这个问题。
我有两个脚本,即 goodsRegister.py 和 Register.py 。
现在在 goodsRegister.py 中有一个函数ie test_Test2
,我只需要那个函数在 Register.py 中执行,而不是{{1 }}。
检查代码
goodsRegister.py 如下:
test_Test1
和 Register.py 文件就是这样:
from selenium import webdriver
import os
import unittest
import time
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import *
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
EmailEntry = input("Please Enter Email Address: ")
password='12345678'
class goodsweb(unittest.TestCase):
def setUp(self):
driverlocation ="/Users/new/Documents/Learning/Drivers/selenium-2.53.1/py/selenium/webdriver/chromedriver"
os.environ["webdriver.chrome.driver"] = driverlocation
self.driver = webdriver.Chrome(driverlocation)
def test_Test1(self):
driver = self.driver
url = "https://goods.theentertainerme.com/"
driver.get(url)
driver.maximize_window()
driver.implicitly_wait(10)
self.RegisterButton = driver.find_element_by_xpath("//*[@id='logs']/li[2]//a[text()='Sign up']")
self.FirstName = driver.find_element_by_id("registrationform-firstname")
self.Lastname = driver.find_element_by_id("registrationform-lastname")
self.EmailAddress = driver.find_element_by_id("registrationform-email")
self.CountryofResidence = driver.find_element_by_xpath("//*[@id='register-form']//div[1]/div[4]//span")
self.SelectCountry = driver.find_element_by_xpath("//*[@id='registrationform-country_of_residence']")
self.DateofBirth = driver.find_element_by_id("registrationform-date_of_birth")
self.Gender = driver.find_element_by_xpath("//*[@id='register-form']//div[1]/div[6]//div")
self.Password = driver.find_element_by_id("registrationform-password")
self.ConfirmPassword = driver.find_element_by_id("registrationform-confirmpassword")
self.RegisterButton.click()
self.FirstName.send_keys("Taimoor")
self.Lastname.send_keys("Pasha")
#self.EmailEntry = input("Please Enter Email Address: ")
self.EmailAddress.send_keys(EmailEntry)
self.CountryofResidence.click()
time.sleep(5)
Pakistan = driver.find_element_by_xpath("//div[17]/div/span//ul/li[175]")
driver.execute_script("return arguments[0].scrollIntoView();", Pakistan)
Pakistan.click()
#selectCountry = Select(self.SelectCountry)
self.DateofBirth.click()
Month = driver.find_element_by_xpath("//*[@id='ui-datepicker-div']/div/div/select[1]/option[6]")
Month.click()
Year= driver.find_element_by_xpath("//*[@id='ui-datepicker-div']//div/select[2]")
YearList = driver.find_elements_by_xpath("//*[@id='ui-datepicker-div']//div/select[2]")
Year.click()
SelectYear = Select(Year)
SelectYear.select_by_visible_text("1990")
DateofMY= driver.find_element_by_xpath("//*[@id='ui-datepicker-div']/table/tbody/tr[2]/td[5]/a")
DateofMY.click()
time.sleep(5)
self.Gender.click()
MaleGender= driver.find_element_by_xpath("//div[17]/div//span/ul/li[2]/span")
MaleGender.click()
self.Password.clear()
#self.password='12345678'
self.Password.send_keys(password)
self.ConfirmPassword.clear()
self.ConfirmPassword.send_keys("12345678")
RegisterButton = driver.find_element_by_xpath("//*[@id='register-form']//div[2]/input")
RegisterButton.click()
time.sleep(5)
TitleDropdown = driver.find_element_by_xpath("//*[@id='user']/li[2]//a")
newactions = ActionChains(driver)
newactions.move_to_element(TitleDropdown).perform()
SignOutButton = driver.find_element(By.XPATH, "//*[@id='user']/li[3]/div/ul/li[5]/a")
newactions.move_to_element(SignOutButton).click().perform()
def test_Test2(self):
driver = self.driver
url = "https://goods.theentertainerme.com/"
driver.get(url)
driver.maximize_window()
driver.implicitly_wait(10)
self.LoginButton = driver.find_element_by_id("signin")
self.LoginButton.click()
self.LoginEmail = driver.find_element_by_xpath("//*[@id='sign_form-default']//div[1]/input[@type='email']")
self.LoginEmail.clear()
self.LoginEmail.click()
self.LoginEmail.send_keys(EmailEntry)
self.LoginPassword = driver.find_element_by_xpath("//*[@id='sign_form-default']//div[1]/input[@type='password']")
self.LoginPassword.clear()
self.LoginPassword.click()
self.LoginPassword.send_keys(password)
time.sleep(5)
self.LoginSubmitButton = driver.find_element_by_xpath("//*[@id='sign_form-default']//div[3]/input")
self.LoginSubmitButton.click()
time.sleep(10)
self.NameofUser = driver.find_element_by_xpath("//*[@id='user']/li[2]//a[text()='Taimoor']")
if self.NameofUser.text == "Taimoor":
print("Title Matches")
else:
print("Name is invalid")
def tearDown(self):
driver = self.driver
driver.close()
if __name__ == "__main__":
unittest.main()
但我无法这样做。有人可以帮我这个。