Python3.6+selenium2.53.6自动化测试_禅道新增BUG(一)(本地禅道)
时间:2022-08-23 18:30:01
环境:
编辑工具:
浏览器:
有问题可以联系qq:1776376537
工程目录截图:
base.py脚本如下:
from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC class Base(): def __init__(self,driver:webdriver.Firefox):#加一个:号码可以调整 self.driver = driver self.timeout = 10 self.t = 0.5 def finElementNew(self,loctor): '''定位到元素,返回元素对象,没有定位到返回Timeeout异常''' ele = WebDriverWait(self.driver, self.timeout,self.t).until(EC.presence_of_element_located(loctor)) return ele def findElement(self,loctor): ele = WebDriverWait(self.driver, self.timeout,self.t).until(lambda x: x.find_element(*loctor)) return ele def findElements(self,loctor): try: eles = WebDriverWait(self.driver, self.timeout,self.t).until(lambda x: x.find_elements(*loctor)) return eles except: return [] def sendKeys(self,locator,text): ele = self.findElement(locator) ele.send_keys(text) def click(self,locator): ele = self.findElement(locator) ele.click() def clear(self,locator): ele = self.findElement(locator) ele.clear() def isSelected(self,locator): 判断元素是否被选中,返回bool值''' ele = self.findElement(locator) r = ele.is_selected() return r def isElementExist(self,locator): ‘判断元素是否存在’ try: self.findElement(locator) return True except: return False def isElementsExist(self,locator): eles = self.findElements(locator) n = len(eles) if n == 0: return False elif n == 1: return True else: print("定位元素的数量:%s"%n) return True def is_title(self,_title): '''返回bool值''' try: result = WebDriverWait(self.driver, self.timeout,self.t).until(EC.title_is(_title)) return result except: return False def is_title_contains(self,_title): '''返回bool值''' try: result = WebDriverWait(self.driver, self.timeout,self.t).until(EC.title_contains(_title)) return result except: return False def is_text_in_element(self,locator,_text): '''返回bool值''' try: result = WebDriverWait(self.driver, self.timeout,self.t).until(EC.text_to_be_present_in_element(locator,_text)) return result except: return False def is_value_in_element(self,locator,_value): '''返回bool值,value返回空字符串False''' try: result = WebDriverWait(self.driver, self.timeout,self.t).until(EC.text_to_be_present_in_element_value(locator,_value)) return result except: return False def is_alert(self): try: result = WebDriverWait(self.driver, self.timeout,self.t).until(EC.alert_is_present()) return result except: return False if __name__ == "__main__": driver = webdriver.Firefox() driver.get("http://127.0.0.1/zentao/user-login.html") zentao = Base(driver) # loc2 = (By.NAME,"password") # loc3 = (By.ID,"submit") # loc1 = (By.ID,"account") # loc2 = (By.CSS_SELECTOR,"[name='password']") # loc3 = (By.XPATH,"//*[@id='submit']") loc1 = ("id","account") loc2 = ("css selector","[name='password']") loc3 = ("xpath","//*[@id='submit']") # loc4 = ("class name","xxx") # zentao.findElement(loc1).send_keys("admin") # zentao.findElement(loc2).send_keys("123456") # zentao.findElement(loc3).click() # driver.switch_to.frame() zentao.sendKeys(loc1,"admin") zentao.sendKeys(loc2,"123456") zentao.click(loc3)
HTMLTestRunner_cn.py 代码如下:
#-*- coding: utf-8 -*- """ A TestRunner for use with the Python unit testing framework. It generates a HTML report to show the resultat a glance.
The simplest way to use this is to invoke its main method. E.g.
import unittest
import HTMLTestRunner
... define your tests ...
if __name__ == '__main__':
HTMLTestRunner.main()
For more customization options, instantiates a HTMLTestRunner object.
HTMLTestRunner is a counterpart to unittest's TextTestRunner. E.g.
# output to a file
fp = file('my_report.html', 'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='My unit test',
description='This demonstrates the report output by HTMLTestRunner.'
)
# Use an external stylesheet.
# See the Template_mixin class for more customizable options
runner.STYLESHEET_TMPL = ''
# run the test
runner.run(my_test_suite)
------------------------------------------------------------------------
Copyright (c) 2004-2007, Wai Yip Tung
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name Wai Yip Tung nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
# URL: http://tungwaiyip.info/software/HTMLTestRunner.html
__author__ = "Wai Yip Tung"
__version__ = "0.8.3"
"""
Change History
Version 0.8.4 by GoverSky
* Add sopport for 3.x
* Add piechart for resultpiechart
* Add Screenshot for selenium_case test
* Add Retry on failed
Version 0.8.3
* Prevent crash on class or module-level exceptions (Darren Wurf).
Version 0.8.2
* Show output inline instead of popup window (Viorel Lupu).
Version in 0.8.1
* Validated XHTML (Wolfgang Borgert).
* Added description of test classes and test cases.
Version in 0.8.0
* Define Template_mixin class for customization.
* Workaround a IE 6 bug that it does not treat
%(heading)s
%(report)s
%(ending)s