0
我已经使用硒ide创建测试并将其保存为python脚本(webdriver)。但是,当我运行这个使用python。我得到一些错误 文件“/usr/local/lib/python2.7/dist-packages/PyUnit-1.4.1-py2.7.egg/unittest.py”,第273行,in failUnlessEqual硒python格式化程序测试失败
这是在Selenium IDE中使用python格式化程序自动生成的代码。
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']