我使用 selenium ide 创建测试并将其保存为 python 脚本(webdriver)。但是当我使用 python 运行它时。我收到一些错误文件“/usr/local/lib/python2.7/dist-packages/PyUnit-1.4.1-py2.7.egg/unittest.py”,第 273 行,在 failUnlessEqual
这是使用 python 格式化程序在 Selenium IDE 中自动生成的代码。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class Untitled(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.google.co.in/"
self.verificationErrors = []
self.accept_next_alert = True
def test_untitled(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("gbqfq").clear()
driver.find_element_by_id("gbqfq").send_keys("testomg")
try: self.assertEqual("testomg - Google Search", driver.title)
except AssertionError as e: self.verificationErrors.append(str(e))
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
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()
结果
乙
ERROR: test_untitled (__main__.Untitled)
Traceback (most recent call last):
File "testing2.py", line 40, in tearDown
self.assertEqual([], self.verificationErrors)
File "/usr/local/lib/python2.7/dist-packages/PyUnit-1.4.1-py2.7.egg/unittest.py", line 273, in failUnlessEqual
raise self.failureException, (msg or '%s != %s' % (first, second))
AssertionError: [] != ['testomg - Google Search != Google']