| Module | SeleniumPoetry |
| In: |
lib/selenium_poetry.rb
|
This module extends SeleniumOnRails::TestBuilder. It enables you to write more readable Selenium tests.
To use the methods of Selenium Poetry in your tests, you‘ll first need to load selectors. Do that with the method load_selectors.
Selector files must be place in your Rails application under the directory test/selectors. They should be YAML files.
| SELECTORS_DIR | = | File.dirname(__FILE__) + "/../../../../test/selectors" |
Use it load the selectors you‘ll need to use in your Selenium test. Example:
load_selectors :index
This will load selectors from the file test/selectors/index.yml. If you have to load selectors from several files, you do like this:
load_selectors :index, :checkout, :finish
It will load selectors from the files:
Place load_selectors in the beginning of your tests.
Is equivalent to Selenium‘s assert_element_present.
Suppose you have the selector file test/selectors/index.yml with this content:
postcard of rio de janeiro:
//ul/li/img[@src="images/riodejaneiro.jpg" and @alt="Rio de Janeiro" and @title="Rio de Janeiro"]
postcard of recife:
//ul/li/img[@src="images/recife.jpg" and @alt="Recife" and @title="Recife"]
Using should_have:
should_have "postcard of rio de janeiro"
This is equivalent to the regular Selenium command:
assert_element_present '//ul/li/img[@src="images/riodejaneiro.jpg" and @alt="Rio de Janeiro" and @title="Rio de Janeiro"]'
If you need to test more than one selector, use this syntax:
should_have "postcard of rio de janeiro",
"postcard of recife"
This will produce the equivalent Selenium commands:
assert_element_present '//ul/li/img[@src="images/riodejaneiro.jpg" and @alt="Rio de Janeiro" and @title="Rio de Janeiro"]' assert_element_present '//ul/li/img[@src="images/recife.jpg" and @alt="Recife" and @title="Recife"]'
Is equivalent to Selenium‘s assert_element_not_present.
Take a look at should_have for further explanation.
Is equivalent to Selenium‘s wait_for_element_present.
Take a look at should_have for further explanation. It‘s the same thing, but uses wait_for_element_present instead of assert_element_present.
Is equivalent to Selenium‘s wait_for_element_not_present.
Take a look at should_not_have for further explanation. It‘s the same thing, but uses wait_for_element_not_present instead of assert_element_present.