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] 삭제
몇 마디 만하겠습니다