我对class方法()有一个问题,我该如何解决它
这是我的代码:
import unittest
from selenium import webdriver
class HomePageTest(unittest.TestCase):
@classmethod
def setUpclass(cls):
#create a new Chrome session
cls.driver = webdriver.Chrome()
cls.driver.implicty_wait(10)
cls.driver.maximize_window()
#navigate to the homepage
cls.driver.get("http://demo.magentocommerce.com/")
def test_search_text_field_max_length(self):
#get the search textbox
search_field = self.driver.find_element_by_id("search")
#check maxlength attribute is set to 128
self.assertEqual("128", search_field.get_attribute("maxlength"))
def test_search_button_enabled(self):
#get Search Button
search_button = self.driver.find_element_by_class_name("button")
#check search button is enabled
self.asserTrue(search_button.is_enabled())
def test_my_account_link_is_displayed(self):
#get the account link
account_link = self.driver.find_element_by_link_text("Account")
#check My Account link is displayed/visible in the home page footer
self.assertTrue(account_link.is_displayed())
def test_account_links(self):
#get the all the links with account text in it
account_links = self.driver.find_elements_by_partial_link_text("ACCOUNT")
#check account and my account link is displayed/visible in the home page footer
self.assertTrue(2, len(account_links))
def test_count_of_promo_banners_images(self):
#get promo banner list
banner_list = self.driver.find_elements_by_class_name("promos")
#get images from the banner_list
banners = banners_list.find_elements_by_tag_name("img")
#check there are 3 banners displayed on the page
self.assertEqual(2, len(banners))
def test_vip_promo(self):
#get vip promo image
vip_promo = self.driver.find_element_by_xpath("//img[@alt='Shop Private Sales - Member Only']")
#check vip promo logo is displayed on home page
self.asserTrue(vip_promo.is_displayed())
#click on vip promo images to open the page
bip_promo.click()
#check page title
self.assertEqual("VIP", self.driver.title)
def test_shopping_cart_status(self):
#check content of my shopping cart block on home page
#get the Shopping cart icon and click to open the shopping cart section
shopping_cart_icon = self.driver.find_find_element_by_css_selector("div.header-minicart span.icon")
shopping_cart_icon.click()
#get the shopping cart status
shopping_cart_status = self.driver.find_element_by_css-selector("p.empty").text
self.assertEqual("You have no items in your shopping cart.", shopping_cart_status)
#close the shopping cart section
close_button = self.driver.find_element_by_css_selector("div.minicart-wrapper a.close")
close_button.click()
@classmethod # in this area red why?
def tearDownClass(cls) :
#close the browser window
cls.driver.quit()
if_name_ == '_main_':
unittest.main(verbosity=2)
目前没有回答
相关问题 更多 >
编程相关推荐