Why does the test pass when using the element? method to check the element's existence?

Farooq

How do you figure out if elements exist on a page?

The page has a link:

<a class="twitter" href="h.....">twitter</a>

My page object class is:

class Computer
  include PageObject

  link(:twitter_link, :class => "twitterrrrr")

  def element_exists?
    puts @browser.url
    twitter_link?        
  end       
end

This page is being used in a Cucumber step definition:

Then /the elements should exist/ do
  on(Computer).element_exists?
end

The above :class is purposefully wrong, it should really be equal to "twitter" (like the HTML above), but when I call twitter_link? the step still passes and doesn't fail.

When I call .exists? on twitter_link then the test fails, which is correct:

def element_exists?
  puts @browser.url
  twitter_link.exists?
end  

The desired outcome also occurred when I did:

def element_exists?
  puts @browser.url
  twitter_link?.should == true
end 

내가 twitter_link?스스로 전화하면 왜 지나가는 지 아는 사람 ? page-objects gem 문서에 따르면 즉시 존재 여부를 확인하는 방법이 있어야합니다. 실제 페이지 자체가 아니라 페이지 클래스에 존재하는지 확인하는 것을 의미합니까? 그것이 그것이하고있는 것처럼 보입니다.

저스틴 코

문제는 twitter_link?단순히 참 또는 거짓을 반환 한다는 것 입니다. RSpec 및 Cucumber와 같은 테스트 프레임 워크는 무언가가 거짓을 반환했다고해서 실패하지 않습니다. 어설 션이 실패하거나 예외가 발생하는 경우에만 실패합니다.

즉, twitter_link?메서드를 호출하는 대신 어설 션에서 확인해야합니다. 예를 들면 :

# Examples using should syntax
page.twitter_link?.should == true
page.twitter_link_element.should exist

# Examples using expect syntax
expect(page.twitter_link?).to be_true
expect(page.twitter_link_element).to exist

일련의 요소를 확인하려면 요소 이름의 배열을 만든 다음 반복 할 수 있습니다.

elements = [:twitter_link]
elements.each { |x| self.send( "#{x.to_s}?").should == true }

Note that when creating the array of elements, you do not want to use elements = [twitter_link]. By having twitter_link in the array, it will call the method to actually try to click the link. That is why you need to use something like a string or symbol instead. Storing the page object element would also be an option:

elements = [twitter_link_element]
elements.each { |x| x.exists?.should == true }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why does the knockout binding pass the span element's id rather than the anchor element's id?

분류에서Dev

Why does XmlReader.ReadInnerXmlAsync hang when reading <ns:element>?

분류에서Dev

check if there is a new element using jquery

분류에서Dev

I need to select an HTML element when it's clicked using AngularJS

분류에서Dev

Best way to check an element's width?

분류에서Dev

Does a reference to an element break when that element is moved or attached?

분류에서Dev

Why a dangerous method doesn't work with a character element of String in Ruby?

분류에서Dev

"appendTo"-method not functioning correctly when connecting a draggable to a sortable element in jQueryUI

분류에서Dev

Why my a element tag does not effect the links? Right syntax?

분류에서Dev

Why does IndexSet say that a new element is inserted even though the element is already in the set?

분류에서Dev

How to access schema element annotation using Marklogic sc:annotations method

분류에서Dev

Java: Using a mutator method on element of array with a for loop, not working

분류에서Dev

why is element undefined in CFC?

분류에서Dev

Why does consuming a RESTful web service (using javax.ws.rs.* and Jsersey) work in unit test but not when submitted to Spark?

분류에서Dev

pass element through function jquery

분류에서Dev

How to center an absolutely positioned element within its parent when the child element's height is unknown

분류에서Dev

How to center an absolutely positioned element within its parent when the child element's height is unknown

분류에서Dev

SQL:Using group by to check existence of a value against a separate list of strings

분류에서Dev

How to check file existence using Struts 1 tags?

분류에서Dev

How close other element when clicked using .slideToggle

분류에서Dev

why does the addDomain method affect the Domain's SuperClass

분류에서Dev

Why does my url reference in my test controller don't pass succesfully trought the if(isset)

분류에서Dev

Why pass by pointer when we can pass the variable's address with the & operator?

분류에서Dev

CSS3 Transform - why does increasing height cause element to move down?

분류에서Dev

C++ why does empty set::emplace() inserts an element into a set of pointers?

분류에서Dev

Why does NVL2 returns NULL when it's not expected?

분류에서Dev

How to get a variable's literal value when setting an element's onclick handler via jQuery?

분류에서Dev

show an element when it comes to the layer

분류에서Dev

How to check if a char array element is empty?

Related 관련 기사

  1. 1

    Why does the knockout binding pass the span element's id rather than the anchor element's id?

  2. 2

    Why does XmlReader.ReadInnerXmlAsync hang when reading <ns:element>?

  3. 3

    check if there is a new element using jquery

  4. 4

    I need to select an HTML element when it's clicked using AngularJS

  5. 5

    Best way to check an element's width?

  6. 6

    Does a reference to an element break when that element is moved or attached?

  7. 7

    Why a dangerous method doesn't work with a character element of String in Ruby?

  8. 8

    "appendTo"-method not functioning correctly when connecting a draggable to a sortable element in jQueryUI

  9. 9

    Why my a element tag does not effect the links? Right syntax?

  10. 10

    Why does IndexSet say that a new element is inserted even though the element is already in the set?

  11. 11

    How to access schema element annotation using Marklogic sc:annotations method

  12. 12

    Java: Using a mutator method on element of array with a for loop, not working

  13. 13

    why is element undefined in CFC?

  14. 14

    Why does consuming a RESTful web service (using javax.ws.rs.* and Jsersey) work in unit test but not when submitted to Spark?

  15. 15

    pass element through function jquery

  16. 16

    How to center an absolutely positioned element within its parent when the child element's height is unknown

  17. 17

    How to center an absolutely positioned element within its parent when the child element's height is unknown

  18. 18

    SQL:Using group by to check existence of a value against a separate list of strings

  19. 19

    How to check file existence using Struts 1 tags?

  20. 20

    How close other element when clicked using .slideToggle

  21. 21

    why does the addDomain method affect the Domain's SuperClass

  22. 22

    Why does my url reference in my test controller don't pass succesfully trought the if(isset)

  23. 23

    Why pass by pointer when we can pass the variable's address with the & operator?

  24. 24

    CSS3 Transform - why does increasing height cause element to move down?

  25. 25

    C++ why does empty set::emplace() inserts an element into a set of pointers?

  26. 26

    Why does NVL2 returns NULL when it's not expected?

  27. 27

    How to get a variable's literal value when setting an element's onclick handler via jQuery?

  28. 28

    show an element when it comes to the layer

  29. 29

    How to check if a char array element is empty?

뜨겁다태그

보관