So this code was working perfectly fine, until I recently updated my selenium webdriver:
When /^I search for (.*)$/ do |term|
term = " " if term == "blank"
step "I fill in search with #{term}"
within(".navbar-search") do
page.find(:css, "li:first").click
end
end
I updated, and now I get the following error:
An invalid or illegal string was specified (Selenium::WebDriver::Error::UnknownError)
./features/step_definitions/search_steps.rb:5:in `block (2 levels) in <top (required)>'
./features/step_definitions/search_steps.rb:4:in `/^I search for (.*)$/'
features/search_friend.feature:13:in `When I search for <term>'
Here is the cucumber feature:
#javascript
Scenario Outline: The search bar
Given I login
And I have a contact named ABC
And I have a contact named DEF
And I have a contact named GHI
When I search for <term>
Then I should see the message <message>
Examples:
| term | message |
| ... some examples ... | |
I guess you updated not only Webdriver but also Capybara.
Capybara 2.1 now uses driver's implementation of CSS selectors. In case of Selenium Webdriver it means that browser's implementation is used. :first pseudo selector is not standard and isn't supported by browsers so your CSS selector is not valid.
Previously it worked because Capybara converted CSS selector to XPath using Nokogiri. Nokogiri supports :first pseudo selector.
So you should change your invalid CSS selector to something valid like:
page.first(:css, 'li').click
page.find(:css, 'li', match: :first).click (the difference between previous variant and this one is that this variant waits for element to appear on the page but the first one doesn't wait. See this section of Capybara README to get more information on match)
page.find(:css, "li:first-child").click
page.find('li:first-child').click
Related
I want to use gherkin localization in Karate Framework.
English version of scenario works perfect. But with Russian version it looks like Karate FeatureParser doesn't know localized tags and fails. Here is the error log:
line 15:0 mismatched input '<EOF>' expecting {FEATURE_TAGS, FEATURE}
16:44:01.263 [main] ERROR com.intuit.karate.core.FeatureParser - syntax error: mismatched input '<EOF>' expecting {FEATURE_TAGS, FEATURE}
16:44:01.270 [main] ERROR com.intuit.karate.core.FeatureParser - not a valid feature file: src/test/java/ru.feature - mismatched input '<EOF>' expecting {FEATURE_TAGS, FEATURE}
Exception in thread "main" java.lang.RuntimeException: mismatched input '<EOF>' expecting {FEATURE_TAGS, FEATURE}
at com.intuit.karate.core.FeatureParser.<init>(FeatureParser.java:150)
at com.intuit.karate.core.FeatureParser.<init>(FeatureParser.java:126)
at com.intuit.karate.core.FeatureParser.parse(FeatureParser.java:69)
at com.intuit.karate.IdeUtils.exec(IdeUtils.java:61)
at cucumber.api.cli.Main.main(Main.java:36)
English version of feature file:
Feature: Services A and B
Background:
* url 'http://localhost:8080'
Scenario: call service A
Given path 'service-a'
And method get
Then status 200
Scenario: call service B
Given path 'service-b'
And method get
Then status 200
Russian version of feature file:
# language: ru
Функция: Сервисы А и Б
Контекст:
* адрес 'http://localhost:8080'
Сценарий: вызов сервиса А
Дано путь 'service-a'
И метод get
То статус 200
Сценарий: вызов сервиса B
Дано путь 'service-b'
И метод get
То статус 200
What should I do to fix it?
Yes, Karate does not support localization after we switched away from Cucumber in version 0.9.0.
We decided not to support localization because the goals of Karate are very different from Cucumber. Karate is more like a programming language, better explained here: https://stackoverflow.com/a/47799207/143475
So just like Java or JavaScript do not support localized keywords, Karate does not either. We haven't had any complaints so far :)
I wrote the folowing test but am getting error:
Could not find fixture: Connect.
!path lib/*.jar
!|Import|
!|dbfit.SqlServerTest|
!|Import|
|dbfit.fixture|
!|Connect|Data Source=ACER\SQLEXPRESS;Initial Catalog=NopCommerce;Integrated Security=SSPI;|
!|query|select * from dbo.Employees|
!|Query| select 'test' as x| |x| |test|
Include the following at the top of your page:
!define TEST_SYSTEM {fit}
According to this answer, the syntax for the import should be:
!|import fixture|
|dbfit.fixture|
Note: the dbfit.fixture is in a separated row, and has no preceding exclamation mark, the sign of a command, so the mentioned error message should be read as: "Oh, I have found import command asking for something like dbfit.fixture, but the next line asks for a Connect fixture, which is not expected, because Connect is another command".
Try the following:
|import fixture|
|dbfit.fixture|
!|DatabaseEnvironment|sqlserver|
|Connect|192.168.0.3|user|pass|nz_db|
|Store query|!-select * from sql_tbl-!|fromtbl|
!|Query|<<fromsql|
|Rollback|
!|dbfit.util.ExportFixture|
|dbfit.fixture|
This works for me in DBFit Java.
Anything (even comments) between the 'DatabaseEnvironment' and the 'Connect' will also cause the 'Could not find fixture: Connect' error.
So, this fails:
|DatabaseEnvironment|sybase|
|Connect | jdbc:jtds:sybase://10.158.0.189:8000;user=myuser;password=mypass;databaseName=mydb |
But this works:
|DatabaseEnvironment|sybase |
|Connect |jdbc:jtds:sybase://10.158.0.141:8000;user=myuser;password=mypass;databaseName=mydb|
The page title is "Page1" (https://github.com/biomq/geb-example-grails/blob/master/grails-app/views/person/page1.gsp#L8), but the Page DSL is checking for a title of "Person List" (https://github.com/biomq/geb-example-grails/blob/master/test/functional/pages/LinkPage1.groovy#L9).
To run tests:
grails -Dgeb.env=firefox test-app functional:
If you edit LinkPage1's title ==~ /Page1/ to the incorrect value title ==~ /Person List/ [as it is now, in the repo] while leaving Page1 in page1.gsp, the test passes! The test failure then occurs further down with 'testLink' "page content not found".
If you edit person/page1.gsp and replace g:link controller="Person" action="page2" id="testLink" ... with a href="/person/page2" id="testLink"... i.e. provide an explicit testLink id, and use testLink { $("#testLink") } in LinkPage1.groovy, the page content not found error persists.
hmmmm...
It should be to LinkPage1 and not at LinkPage1 here if you want to go to /person/page1.gsp. Have a look at the Book of Geb, the difference between at() and to() is described there.
Cucumber is complaining that I have an ambiguous match for when I tell it to click a link: Ambiguous match, found 4 elements matching link "Spirits" (Capybara::Ambiguous). So I am trying to match the "Spirits" link exactly.
I looked through this: https://github.com/jnicklas/capybara#exactness and found the exact: true option so I changed my code from:
When(/I click on the (.*) link/) do |link_name|
click_link(link_name)
end
to:
When(/I click on the (.*) link/) do |link_name|
click_link(link_name, exact: true)
end
But now it's complaining with wrong number of arguments (2 for 1) (ArgumentError). I'm on Rails 3.2.13, capybara (2.0.3), cucumber (1.2.3). Anyone know why there is an error?
Your Capybara version is not the latest.
exact method added in 2.1.0. https://github.com/jnicklas/capybara/blob/master/History.md
You need to upgrade the gem.
Problem Background: "cucumber declarative step definitions using web_steps.rb" Stack Overflow Question
In troubleshooting the problem in question two contradictory error messages are arrived at; with the statement:
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
check(field)
end
added to 'features/step_definitions/movie_steps.rb' execution of 'bundle exec cucumber features/filter_movie_list.feature' results in:
Ambiguous match of "I uncheck "ratings_G"":
features/step_definitions/movie_steps.rb:65:in '/^(?:|I )uncheck "([^"]*)"$/
features/step_definitions/web_steps.rb:65:in '/^(?:|I )uncheck "([^"]*)"$/
However, removal of the step does not result in the step definition from 'web_steps.rb' being utilized; rather, a different error message is displayed:
When I uncheck the following ratings: G, PG-13 # features/step_definitions/movie_steps.rb:44
Undefined step: "When I uncheck "ratings_G"" (Cucumber::Undefined)
./features/step_definitions/movie_steps.rb:52:in `block (2 levels) in <top (required)>'
./features/step_definitions/movie_steps.rb:49:in `each'
./features/step_definitions/movie_steps.rb:49:in `/I (un)?check the following ratings: (.*)/'
features/filter_movie_list.feature:30:in `When I uncheck the following ratings: G, PG-13'
How is it possible for Cucumber to complain that a step is redundant when there are two definitions in two places but then later complain that the very same step is not defined when its duplicate is removed? Is it possible the second error message really means something other than what is stated?
PS: The configuration was arrived at by way of a Cucumber installation with training wheels for CS169.x1 # edX...
It seems that you have one definition called When I uncheck "ratings_G" that is somewhat matched with the call When I uncheck the following ratings: G, P-13 that occurs in the error message. Cucumber is complaining that nothing matches the latter one. Does it exist in your code?
The somewhat matching would possibly explain the ambiguity warning you got initially. The definition matches but not what is found inside the string.