|
新人,请教:
每写一个用例都需要写class类吗,比如如下的代码,标红的是每个.py文件里都需要吗?
#-*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import sys
#需要将\Public目录添加到环境变量中
sys.path.append("\Public")
from Public import Pub_subaccount_login
from Public import Pub_logout
def is_element_present(driver, selector, value):
try:
driver.find_element(by=selector, value=value)
return True
except:
return False
class New_folder(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://******.com/user/signin"
self.verificationErrors = []
self.accept_next_alert = True
#调用子账户登录模块
Pub_subaccount_login.login(self)
time.sleep(3)
#新建文件夹,名称为:网盘testing logs(5)
def test_new_folder(self):
u"新建文件夹"
driver = self.driver
driver.maximize_window()
foldername = u"网盘testing logs(5)"
driver.find_element_by_css_selector("i.icon.i-addfolder").click()
driver.find_element_by_id("folderName").send_keys(foldername)
driver.find_element_by_id("create").click()
time.sleep(2)
#判断文件夹是否新建成功 如检测到名为"网盘testing logs(5)"的文件夹,则判定新建成功
if is_element_present(driver, By.LINK_TEXT, foldername):
print "Create folder successful.Foldername is:", foldername
else:
print "Create folder failed!"
#调用注销模块
Pub_logout.logout(self)
time.sleep(2)
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
|
|