使用python在selenium中遗漏测试
我正在尝试测试这个网站。我正在测试三个功能,分别是测试A、B和C。我正在使用geckodriver测试代码,geckodriver的exe位于根文件夹中 代码如下:使用python在selenium中遗漏测试,python,selenium,python-unittest,Python,Selenium,Python Unittest,我正在尝试测试这个网站。我正在测试三个功能,分别是测试A、B和C。我正在使用geckodriver测试代码,geckodriver的exe位于根文件夹中 代码如下: from selenium import webdriver import time import unittest class Guru99BankTest(unittest.TestCase): @classmethod def setUp(self): self.driver = webdr
from selenium import webdriver
import time
import unittest
class Guru99BankTest(unittest.TestCase):
@classmethod
def setUp(self):
self.driver = webdriver.Firefox()
def test_C(self):
driver = self.driver
driver.get("http://live.guru99.com/")
driver.find_element_by_link_text('Mobile').click()
listed_prd_el = driver.find_element_by_xpath(
"//a[contains(text(), 'Sony Xperia')]/ancestor::div[@class = 'product-info']")
listed_prd_el.find_element_by_tag_name('button').click()
qty = driver.find_element_by_xpath("//input[@title='Qty']")
qty.clear()
qty.send_keys('1000')
self.assertEqual(qty.get_attribute('value'), '1000')
driver.find_element_by_xpath("//button[@title='Update']").click()
time.sleep(3)
self.assertIn('products cannot be ordered in requested quantity',
driver.find_element_by_class_name('error-msg').text)
driver.find_element_by_xpath("//button[@title='Empty Cart']").click()
time.sleep(3)
self.assertIn('no items in your shopping cart',
driver.find_element_by_class_name('cart-empty').text)
def test_A(self):
driver = self.driver
driver.get("http://live.guru99.com/")
self.assertIn("This is demo site for", driver.page_source)
driver.find_element_by_link_text('Mobile').click()
self.assertEqual("Mobile", driver.title)
def test_B(self):
driver = self.driver
driver.get("http://live.guru99.com/")
driver.find_element_by_link_text('Mobile').click()
driver.find_element_by_xpath("//select[@title='Sort By']/option[contains(text(), 'Name')]").click()
product_names = ([e.text for e in driver.find_elements_by_xpath("//h2[@class='product-name']")])
self.assertEqual(product_names, sorted(product_names))
listed_prd_el = driver.find_element_by_xpath(
"//a[contains(text(), 'Sony Xperia')]/ancestor::div[@class = 'product-info']")
listed_price = listed_prd_el.find_element_by_class_name("price").text
listed_prd_el.find_element_by_tag_name('a').click()
prod_price = driver.find_element_by_xpath('//span[@class="price"]').text
self.assertEqual(listed_price, prod_price)
@classmethod
def tearDown(self):
self.driver.close()
def custom_suite():
suite = unittest.TestSuite()
suite.addTest(Guru99BankTest('test_A'))
suite.addTest(Guru99BankTest('test_B'))
suite.addTest(Guru99BankTest('test_C'))
return suite
if __name__ == "__main__":
runner = unittest.TextTestRunner()
runner.run(custom_suite())
但是,我发现浏览器只打开一次,而不是三次。我做错了什么?我对单元测试还很陌生,所以请容忍我。它对我很有用。我将上一个测试改为测试C,因为测试b是重复的。然而,我不确定这是否是实际情况有两个测试同名test_B,是故意的吗?@michaelsatish我很抱歉这是一个输入错误我刚刚在控制台中得到一个运行chrome的ran 1测试,不确定这会有什么不同,我让chrome驱动程序四处躺着,所以在Chrome中启动了你的代码并成功了。但我不认为浏览器类型和实例决定了流程