Gmail Gem - how to click a link in email body Ruby Cucumber

瀏覽次數:167 次
跳到第一則未讀訊息

Sandeep Kommineni

未讀,
2017年9月26日 上午8:45:102017/9/26
收件者:Cukes

I have searched the net upside down for this answer, but I can't seem to find it. I've tried various methods but they aren't working.

Goal: Using ruby cucumber, to click a link within an email I have received. Seems simple right?

Using the gmail gem, something like:

When(/^I click the link$/) do
(insert code here)

I can get the body of the email back with

mail.inbox.emails(:from => "rubycucumber")do |email|
  puts email.html_part.body.decoded
end

But how do I navigate to/click the link (which is in A HREF tag when I view the email body after running step above)?

It seems the gmail gem is really awesome at counting, labeling, marking as read, etc, but this piece is giving me trouble :(

Chuck van der Linden

未讀,
2017年9月28日 下午2:08:312017/9/28
收件者:Cukes
So the question is what is your objective in clicking the link?    

If you just want to check that the page is there (e.g. that it is not a 404) you could use the NET:http methods (or other gems that do http requests) to request the url you extract from the link. 

If your objective is to open an actual browser, and interact with the page that the link directs to, then you will need to use a browser driver such as Watir, Capybara, or Webdriver..   Personally I like the Watir API better, and since it uses webdriver under the covers you get the same cross browser support..   A lot of others like Capybara, which is also built on top of  webdriver and for which there are some examples in the Cucumber Book

80Vikram

未讀,
2017年10月23日 上午11:46:532017/10/23
收件者:Cukes
Hey Sandeep,

This is Selenium issue and not related to Cucumber.

You can try it out by adding all the test case in single test method outside cucumber approach.

Regards,
Vikram
回覆所有人
回覆作者
轉寄
0 則新訊息