Tell Cucumber tests to run on https - https

I am running cucumber tests with Webrat in external mode that is using Selenium. In production we are running behind https and so we are required to run our cucumber tests on https.
Is there any place we can specify that cucumber, webrat, or selenium needs to be using https? Ideally this could be specified through a parameter that is given to Webrat.
I have seen some stuff that looks like it might be possible if I override the default SeleniumClientDriver that comes bundled under the selenium.rb file.
env.rb =>
Webrat.configure do |config|
config.mode = :selenium
config.aplication_address = 'localhost'
config.aplication_port = 11090
config.selenium_server_address = 'localhost'
config.selenium_server_port = 4444
config.selenium_browser_key = '*iexploreproxy'
config.application_framework = :external
end
World do
session = Webrat::SeleniumSession.new
session.extend(Webrat::Methods)
session.extend(Webrat::Selenium::Methods)
session.extend(Webrat::Selenium::Matchers)
session
end
Thanks for any help!

This apparently is not something that the webrat team has decided to support.
So a team member changed the source to allow that this can be specified through env.rb properties. The pull request can be found here.

Related

Setting the headless option for my selenium driver

I'm setting up tests using rspec and capybara within wsl2. I have had to use a remote selenium server because wsl2 can't open browser windows. I would like to set the headless option on my configuration but I am unable to find documentation that would help me.
My code is as follows within rails_helper.rb:
`
Rspec.configure do |config|
config.before(:each, type: :system) do
driven_by :selenium, using: :remote,
options: {
browser: :chrome,
url: 'http://192.168.56.1:4444'}
end
end
`
I want to put something into options like args: 'headless', but that just gives me an unknown keyword error. I've tried looking up documentation in the webdrivers gem, chromedriver, rspec, selenium, and capybara. They either don't have anything or they will have a different format that won't work when I try to include it.
I can't think of any more places to look so I'm asking a question.

Why does Watir-webdriver open two browsers?

I'm working on website test automation using Cucumber/Ruby/Selenium-Webdriver/Capybara. I want to switch to Watir-Webdriver in combination with Cucumber and Ruby, but I'm struggling with the following:
Every time I run my cucumber test, Watir opens two browser windows, a blank screen to the site I configurated as default, plus another in which the actual test steps are executed.
My 'Support/env.rb' file has:
require 'allure-cucumber'
require 'rspec'
require 'watir-webdriver'
AllureCucumber.configure do |c|
c.output_dir = 'D:\Test\result'
c.clean_dir = true
c.tms_prefix = '#PRACTEST--'
c.issue_prefix = '#JIRA++'
c.severity_prefix = '#URGENCY:'
c.tms_prefix = ''
end
My steps file begins with:
require 'watir-webdriver'
require 'cucumber'
require 'rspec'
require_relative 'D:\EntelTest\src\PageObject\home_page.rb'
Before do
#test = AbstractPage.new(Watir::Browser.new :ff)
#test.full_size
end
After do
#test.quit
end
home_page = nil
When(/^Go to home page$/) do
home_page = #test.goToHomePage
end
Can you put these before do and after do in hooks.rb? In the steps.rb file, just mention the code for your cucumber steps, and before that declare browser = Watir::Browser.new :ff
The best practice is to put it in hooks.rb. env.rb usually should consist the desired capabilities plus server environment codes. :)
What you have put in step file should go in hooks.rb file.
Please install gem called testnow.
It will help you to create most standard and easy to use watir-webdriver framework with all pre-configured browsers.
Steps:
1) gem install testnow
2) testnow watir_cucumber_now
It will as you to install dependecies, enter Y to set it up completely.
It will create robust framework with a sample scenario.
Just run the sample scenario with any of the following commands.
rake testnow BROWSER=firefox
rake testnow BROWSER=chrome
rake testnow BROWSER=opera
This will only work provided you have browsers pre-installed and webdriver present in PATH variable.
Please comment for more information.
Hope it helps!!

Easy selection of APKs in appium when testing same application but different APK files for different environments

First an introduction to the problem.
We have been testing 5 websites that has 3 instances of testing environments (testing environment, pre-production environment and production environment), so, 3 different URLs, but exact same website.
The workaround with selenium-webdriver and ruby that we use is to set an environment variable, and in the webdriver test cases, we add a "case" in the "before" section of the tests, so is easier to set which instance we need to run our tests.
Now, problem is, that we are starting to use appium to test our APKs, and we are facing the same situation, we have some APKs, that also has 3 instances of testing environments.
Now the question is, if it's possible to implement this with appium, we have the appium.txt but maybe there's another method in which we can have the capabilities and apk in the same ruby file, so we can use a "case" as we do with the websites, because we can't use a case in the appium.txt file.
Here's the appium.txt file:
[caps]
platformName = "Android"
deviceName = "Android"
app = "./application.apk"
appPackage = "com.application.android.player"
appActivity = ".Main"
And here's my spec_helper.rb file:
# encoding: UTF-8
require 'rubygems'
require 'appium_lib'
def setup_driver
return if $driver
#caps = Appium.load_appium_txt file: File.join(Dir.pwd, 'appium.txt')
if using_sauce
upload_app
end
$driver=Appium::Driver.new(#caps)
end
RSpec.configure do |config|
config.before(:each) do
$driver.start_driver
set_wait(10) #Implicit Wait
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
wait.until { find_element(:name,'TÉRMINOS Y CONDICIONES') }
find_element(:id, 'com.application.android.player:id/acceptButton').click
end
config.after(:each) do
$driver.driver_quit
end
end

How do I run Capybara on similar pages from command line?

I have nearly identical versions of webapps on different sites.
What I'd like to do is specify the site at command line...
cucumber --server server1 --tags #tests
....
#servers = {'server1' => 'https://www.tests.com', 'server2' => 'https://www.foobar.com'}
....
Background:
Given I am on {#server1}
Scenario: Happy plan
When I go here
And I see this
Then I get that
What is the best way to running the same script on multiple similar websites? Can it be run from the command line?
Your best option is to use an environment variable for your server name:
cucumber SERVER=server1 --tags #tests
You can create a generic step:
Given I am on the configured test server
Then, in your step definition, you can look that up as you would in any normal Ruby code and set it as Capybara's base URL:
Given /^I am on the configured test server$/ do
server_name = ENV['SERVER']
url = #servers[server_name] or raise "Unknown test server: #{server_name}"
Capybara.app_host = url
end
Note that when using a remote server, you'll need to use a Capybara driver that supports it, such as Selenium: the default RackTest driver does not. You may also want to set run_server to false. See https://github.com/jnicklas/capybara#calling-remote-servers
Create some config and read it before executing scripts.
Put code for parsing config to features/support/env.rb, for example.

Testing server ruby-application with cucumber

My ruby application runs Webrick server. I want to test it by cucumber and want to ensure that it gives me right response.
Is it normal to run server in test environment for testing? Where in my code I should start server process and where I should destroy it?
Now I start server by background step and destroy in After hook. It's slow because server starts before every scenario and destroys after.
I have idea to start server in env.rb and destroy it in at_exit block declared also in env.rb. What do you think about it?
Do you know any patterns for that problem?
I use Spork for this. It starts up one or more servers, and has the ability to reload these when needed. This way, each time you run your tests you're not incurring the overhead of firing up Rails.
https://github.com/sporkrb/spork
Check out this RailsCast for the details: http://railscasts.com/episodes/285-spork
Since cucumber does not support spork any more (why ?) I use the following code in env.rb
To fork a process I use this lib : https://github.com/jarib/childprocess
require 'childprocess'
ChildProcess.posix_spawn = true
wkDir=File.dirname(__FILE__)
server_dir = File.join(wkDir, '../../site/dev/bin')
#Because I use rvm , I have to run the server thru a shell
#server = ChildProcess.build("sh","-c","ruby pageServer.rb -p 4563")
#server.cwd = server_dir
#server.io.inherit!
#server.leader = true
#server.start
at_exit do
puts "----------------at exit--------------"
puts "Killing process " + #server.pid.to_s
#server.stop
if #server.alive?
puts "Server is still alive - kill it manually"
end
end

Resources