7

I have the following lines in my feature file:

Given I have website "www.google.co.uk" When I click the website "www.google.co.uk" Then "www.google.co.uk" page is opened in a new window 

I am struggling to find a way to test that the webpage is definately opened in a new window.

Currently I have been using this in my step def:

Then /url "([^"]*)" is opened in new window/ do |url| browser = page.driver.browser current_id = browser.window_handle tab_id = page.driver.find_window(url) browser.switch_to.window tab_id page.driver.browser.close browser.switch_to.window current_id end 

but this still passes the test if the webpage is loaded on the same page, I want it to fail if the webpage is loaded on the same window/tab.

Any suggestions?

Many thanks

1 Answer 1

7

I see no assertions in your test.

My approach would be to test size of window_handles array after performing clicking action on the link, since before clicking the size should equal 1 and after the clicking window_handles should equal 2.

assert page.driver.browser.window_handles.size == 2 

Imho, good enough, since if the webpage is loaded in the same tab, the size will be 1 and the test will fail.

Sign up to request clarification or add additional context in comments.

1 Comment

CHeers for that mate. That was perfect. I am just starting out with cucmber+capybara and agile tbh. But again thanks for your help, it has cleared up other things for me too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.