Hi everyone! I'm a QA Engineer working on a local copy of Drupal 7.22. I'm trying to learn Behat (I have no PHP or BDD experience) - we've got it up and running with the Drupal Extension, and I am using the drupal driver (as opposed to drush) so that I can utilize steps for creating nodes. However, I'm not able to create nodes using the Drupal Extension step definitions.
I'm attempting to test the following feature:
features/editing-a-course.feature
Feature: Editing a course
Creating and editing a course as a course admin.
@api
Scenario: Creating and editing a course as a course admin
Given I am logged in as a user with the "course admin" role
When I am viewing a "course" node with the title "Course"
And I follow "Edit"
Then print last response
And print current URL
My response is a bunch of HTML (the last response) that boils down to an "Access denied" message. The "current URL" displayed is http://74.localhost/testinstall/user/153/edit. The 153 is incrementing every time I run the test.
However! When I run:
features/editing-a-course.feature
Feature: Editing a course
Creating and editing a course as a course admin.
@api
Scenario: Creating and editing a course as a course admin
Given I am logged in as a user with the "course admin" role
When I am viewing a "course" node with the title "Course"
Then print last response
And print current URL
I get the "Access denied" message BUT The "current URL" displayed is http://74.localhost/testinstall/node/61 The 61 is incrementing every time I run the test.
Does anyone have any insight into why creating nodes might not be working for me, and how I can fix this?
Thanks.
Comments
Some tips
Numbers are increasing because on each run Drupal Extension creates a new user and a new node. This is because the step 'Given I am logged in as a user with the "course admin" role' creates a user with given role to perform the test (and logs her). In a similar way, 'When I am viewing a "course" node with the title "Course"', creates a new course node and acces to it.
Once test are run, have you tired to access that URL with your browser to check if you see an access denied message? May be that role has no permissions, may be there's something broken in your Drupal.
You can also use the Selenium Driver, so you can see what the browser do (this driver launches a Firefox instance to perform the steps).
Thanks for your response!
Thanks for your response!
I'm aware that the incrementing of the node/user numbers is due to their creation - I meant to include that detail to show that behat is creating those nodes.
Once tests are run, I am unable to go to the URLs because AfterScenario is deleting everything.
I will try to use the selenium driver. Thanks for the suggestion!
EDIT: upon closer consideration, won't the selenium driver be of no use since it won't have the step definitions for things like "create a node with title x" ?
Combine @javascript and @api
You can combine @javascript and @api. Some steps are performed by the browser, some by the api.
Ah, there's a dirty trick to keep browser open after test is finished. I use it sometimes to debug: just comment out the line on behat source that closes the browser at the end of the test. If you want I can show you where it's located.