|
#!/usr/bin/env python3
#coding=utf-8
import sys,time,re
import unittest,HTMLTestRunner #引入unittest框架包
from os.path import abspath,dirname,join
from selenium import webdriver
from getopt import getopt
class Suit(unittest.TestCase):
@classmethod
def setUpClass(self):
self.verificationErrors = []
driver = 'chrome'
opts, args = getopt(sys.argv[1:],'b:n:')
for o, a in opts:
if o == '-b':
driver = a
if driver == 'ie':
browser = webdriver.Ie()
elif driver == 'chrome':
browser = webdriver.Chrome()
elif driver =='firefox':
browser = webdriver.Firefox()
elif driver =='PhantomJS':
browser = webdriver.PhantomJS()
browser.maximize_window()
else:
assert False,'Unknown driver'
return browser
def suite():
moduleNames = [
#登录
'test2',
]
modules = map(__import__,moduleNames)
suite = unittest.TestSuite()
for module in modules:
suite.addTest(module.suite(g_browser))
return suite
if __name__ == '__main__':
g_browser = Suit.setUpClass()
timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
filename = "D:\\worktest\\result\\result_" + timestr + ".html"
print (filename)
fp = open(filename,'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='测试结果',
description='测试报告'
)
runner.run(suite())
g_browser.quit()
#!usr/bin/env python3
#coding=utf-8
import sys,time,re
import unittest,HTMLTestRunner
from os.path import abspath,dirname,join
from getopt import getopt
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from Ext import *
from sext import *
from datetime import *
import time
class LoginCase(unittest.TestCase):
def testlogin(self):
g_browser.get("http://pan.baidu.com/")
time.sleep(2)
g_browser.find_element_by_xpath("//div/a[contains(text(),'帐号登录')]").click()
time.sleep(2)
def suite(browser):
global g_browser
g_browser = browser
global Ext
Ext=Ext(g_browser)
suite=unittest.TestSuite()
suite.addTest(LoginCase("testlogin"))
return suite
if __name__ == '__main__':
unittest.main()
|
|