RSpec, Appium: provide desired capabilities from CLI - ruby

I am using this official Appium page http://appium.io/docs/en/writing-running-appium/default-capabilities-arg/
and I want to override the capabilities which are provided in spec_helper.rb this way
rspec --default-capabilities spec/test_data/new_caps.json spec/cli_test/cli_test_spec.rb
but it is giving me error invalid option: --default-capabilities.
Appium server already running in the background.
What am I doing wrong here?

Related

Capybara with selenium throws Net::ReadTimeout error Intermittently when using `visit` method with cucumber

I am getting Net::ReadTimeout error when using visit methods in a cucumber feature. Unfortunately, I am not able to reproduce this issue on my local system, it only intermittently fail on semaphore. We are using 20 parallel threads in semaphore.
The weired thing is I can see the screen shot of the page using capybara screenshot but still get the timeout error
Here is the test
RSpec.feature do
step 'that I have created a questionnaire' do
safe_visit '/somesite' # getting error on this line sometime
fill_in 'name', with: 'punit'
end
end
We are using rutabaga which is wrapper over turnip gem and allow to run features as rspecs.
What I have already tried (and did not work):
Increase timeout to 120 and retries Net::ReadTimeout (Net::ReadTimeout) Selenium Ruby
Add the selenium driver desired capabilities
Getting Net::ReadTimeout: visiting a website in Ruby Capybara Cucumber
NOTE: Please dont mark this as a duplicate of any other question because I have done a lot of search for quite a few days and then posted this question. Also one key difference in my issue is it is flakey and only happened rarely.
Please let me know in comment if I need any more info is needed.

How to get the user agent for a headless browser

I am running my tests on headless chrome browser and need to get the user agent of the headless browser.
For a Chrome browser, that is not headless I use this code to get the user agent:
page.execute_script("navigator.userAgent"); ==> which works as required
But for a headless browser this doesn't seem to work. Is there a way to get the userAgent?
PS: I use ruby, capybara in my framework
Your issue is that you're using execute_script when you need to be using evaluate_script because you want a response. That being said, your code shouldn't have worked without headless set either so I'm not sure what version of Capybara you're running.
page.evaluate_script("navigator.userAgent")

I am getting an RPC error message when running my cucumber tests against a password protected https url

So what am I using:
I am using the following gems on Ruby 1.9.3:
capybara, commander, cucumber, cucumber-rails, fakeweb, factory_girl_rails, flexmock, gherkin, parallel, parallel_tests, poltergeist, rspec, rspec-rails, sauce, sauce-connect, sauce-cucumber, selenium-webdriver'
For my config file I am using yaml. so config.yml
Now to access the homepage of the site I am testing in my config I have
base_url: https://<username>:<password>#the.url.com
When running my cucumber tests (using poltergeist) the following message is shown several times while the tests are running:
Invalid rpc message origin. https://username#the.url.com vs https://the.url.com
It does not cause the tests to fail but is incredibly untidy and I would really like to get rid of it.
I have been, and still am, investigating a solution to this but if someone gets there first that would be amazing.
Some things that I have tried/know what is happening:-
I know my tests are working as I have run them using the browser (firefox) and it is fine with none of these messages.
Also if I remove the s from https the message dissapears. But alas that will not work for the site as require https.
Putting the url in double quotes does not solve the problem.
I have pinpointed the issue directly to the config and specifying the UN and PW in the url.
It looks like your username and password have gone AWOL:
Invalid rpc message origin. https://#the.url.com vs https://the.url.com
The first part should be https://username:password#the.url.com. Could it be because your config is lacking the double slashes?
base_url: https:<username>:<password>#the.url.com
should probably be
base_url: https://<username>:<password>#the.url.com

Function already created: concat. Watir webdriver, ChromeDriver 2.2, mobile user agent

I am getting the error
Selenium::WebDriver::Error::UnknownError: unknown error: Function already created: concat.
(Session info: chrome=29.0.1547.62)
(Driver info: chromedriver=2.2,platform=Windows NT 6.1 SP1 x86_64)
when running a Cucumber test via Jenkins, command-line or from RubyMine.
I am using Watir webdriver, Chromedriver 2.2, the webdriver-user-agent Gem (to set the user agent to a mobile user agent). The error occurs after getting to the PayPal sandbox site and executing:
assert #browser.link(:class=>"scTrack bn:payWithCard").present?
or:
assert #browser.text.include?(str)
I have tried asserting text exists earlier on in the test and it works fine. Maybe it has something to do with the redirect that occurs during the PayPal page:
Please wait while we transfer you to PayPal
If you have not been connected within 1 minute click here
There are no definitions for anything called concat in our code. I have 63 other tests with the same initialisation code, mobile user agent etc. and none of those throw exceptions. I doubt it matters, but I'm using Windows 7 Professional 64-bit.

capybara-webkit: automatically save a screenshot on an RSpec test failure

How can I automatically save the html and a screenshot when a test fails using capybara-webkit with Rspec? How can I execute a callback when an RSpec test fails.
Bonus points: how can I avoid getting the following error:
Capybara::Driver::Webkit::WebkitInvalidResponseError
when executing this code:
require 'capybara/util/save_and_open_page'
path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
png = Capybara.save_and_open_page_path + "#{path}.png"
page.driver.render Rails.root.join(png)
I have written a gem Capybara-Screenshot specifically for this, check out https://github.com/mattheworiordan/capybara-screenshot
It will automatically create screen shots on failed RSpec or Cucumber steps.
Capybara provides a function for saving and opening a screenshoot during the testing. You just need to call anywhere in your test:
save_and_open_screenshot
and it will open a picture how the test looks like at that point.
No need for any additional gems.
Capybara::save_and_open_screenshot
Found a gist that might help you https://gist.github.com/1156691

Resources