0

I have a Behat scenario that looks like the following:

Scenario: Creating and booking an event
    Given I go to "http://domain.com/"
    And I am logged in with the username "user" and password "pass"
    And I follow "link"
    When I press "Book Now"
    Then I should see "Booking Confirm"

This works fine, but i want to be able to specify a specific URL to go to after logging in, rather than just following a link. Like this:

Scenario: Creating and booking an event
    Given I go to "http://domain.com/"
    And I am logged in with the username "user" and password "pass"
    And I go to "http://domain.com/single-event/?event_id=14&start_time=1457481600&finish_time=1457481600"
    When I press "Book Now"
    Then I should see "Booking Confirm"

When i write the test like this it doesn't work - I get:

Button with id|name|title|alt|value "Book Now" not found.

I've dumped the HTML that is being parsed at this point and it is apparent that the user is logged out (the Book Now button doesn't appear if the user is logged out). It seems that a new session is being started after the "And I go to" statement - is the avoidable, and is there any other way to achieve what I'm looking for?

jamiemax
  • 179
  • 13
  • 1
    how are you handling your I press. How did you define it ? like @AkaAlso mentioned you have to specify what your Book now is, to help the search. That is the problem – eskoba Mar 12 '16 at 10:20
  • @eskoba when mink is installed, press is defined by default - it looks for a button with that text, name or ID. like i say the first scenario works fine so this line is not the issue – jamiemax Mar 14 '16 at 11:16
  • Did you ever solve this? I have a very similar issue that I can't figure out. – greggles Sep 12 '19 at 21:33

1 Answers1

2

You have to specify what "Book Now" is. Just as the error message is saying. If it is an id, for instance, you have to add # tag.

When I press "#Book Now"
akaAlso
  • 132
  • 1
  • 1
  • 8
  • That's not the issue - it knows that Book Now is the button text because the first scenario works fine. The issue is that in the second scenario the page is being viewed as a non-logged in user – jamiemax Mar 14 '16 at 11:14