一个登录脚本,执行时却提示“Ran 0 tests in 0.000s”,请大家帮我分析一下
本帖最后由 afs1984 于 2014-7-10 18:17 编辑这个脚本一执行,就直接提示“Ran 0 tests in 0.000s”,请大家帮忙分析!脚本内容如下:
# 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
class Login(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://xxx.xxxxx.com/user/signin"
self.verificationErrors = []
self.accept_next_alert = True
def Login_with_subaccount(self):
driver = self.driver
driver.get(self.base_url)
driver.maximize_window()
#输入用户名:afs@afs.com
driver.find_element_by_id("user_slug").clear()
driver.find_element_by_id("user_slug").send_keys("afs@afs.com")
#输入密码:xxxxxx
driver.find_element_by_id("pwd").clear()
driver.find_element_by_id("pwd").send_keys("xxxxxx")
#单击【登录】
driver.find_element_by_id("submit_button").click()
#获取当前登录用户名,判断是否登录成功
now_user = driver.find_element_by_css_selector("span.user-name").text
if now_user=="afs":
print "子账户登陆成功!当前登陆用户是:",now_user,"."
else:
print "子账户登录失败!"
def Logout_sub_account(self):
driver = self.driver
#单击【注销】
driver.find_element_by_css_selector("a.icon.i-exit").click()
#获取当前url,判断是否注销成功
now_url = driver.current_url
if now_url=="https://xxx.xxxxx.com/user/signin":
print "子账户注销成功!"
else:
print "子账户注销失败!"
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main() 我找到原因了,def后面的函数名一定要是以test_开头才行。
页:
[1]