Wednesday 15 September 2010

Why does test pass when it should fail - Selenium/Python -


I am using Python 2.7.8 and Selenium 2.45.0. I am going to use Amazon.com as my example in this question. My test looks like this:

  class 1 test (single testcase): def testStep1 (self): self.browser = webdriver.firefox () self.browser.get ("http: //www.amazon.com ") if self.browser.find_element_by_link_text ('Amazon'): Thrust: (true) Other: emphasis (wrong) def testStep2 (self): self.browser.find_element_by_css_selector ('# nav-link -shopall 'directory () directory_sfin = self.browser.find_elements_by_xpath (' // * [= id = "siteDirectoryHeading"]) For the duration of the directory: If "Earth's greatest selection" in span.text: emphasis ( Correct) Other: Emphasis (false)  

What is happening when the button clips That is, it is not at the desired page. Because of this, "the greatest selection of the earth" is never displayed, yet the claim says that it has been passed. Why is it doing this?

Note: I changed the code and now it is working as expected, I have changed the above version:

  def testStep2 (self): ( Webdriver.ActionChains (self.browser)). Double_click (self.browser.find_element_by_id ('nav-link-shopall')) directory = self.browser.find_element_by_id ('siteDirectoryHeading'). Text: In the "Earth's largest selection" directory: emphasis: (true) Other: emphasis (false)  

The code is now searching the directory_span text and passing as expected is. Thanks for the input and help! I just did not know that I needed double_click () in exchange for click () .

self.browser.find_elements_by_xpath ('// * [@ id = "siteDirectoryHeading"]) Then code>, you will not get any errors, but empty list

what exactly is happening here - directory_span is an empty list and the body loop is never executed. This is the reason why you see the test pass.


No comments:

Post a Comment