Using testingbot, video can not be acquired at zalenkum dashboard - zalenium

1. Summarize the problem
Using testingbot, when testing is completed, video can not be acquired at dashboard.
In the following path of zalenium container, video did not exist.
/home/seluser/videos
On the other hand, I use the local elgalu/selenium, I can get the video at dashboard without any problems.
Can I get video with zalenium + testingbot?
2. I've already tried
The zalenium seems to get video from the URL shown by the following code at the end of the test.
https://github.com/zalando/zalenium/blob/4d27dde9cf04e95fa49f4bc7e5d0b781af7761de/src/main/java/de/zalando/ep/zalenium/proxy/TestingBotRemoteProxy.java#L103
https://api.testingbot.com/v1/tests/<session_id>
In zalenium container, I confirmed that I can access this API with my key and secret.
3. some codes and component version
docker: 18.06.1-ce
docker-compose: 1.17.1
dozel/zalenium
id: 150b95a0aa6b
created: 2019-06-17T06:23:59.635702925Z
elgalu/selenium
id: 4afe4ce965ee
created: 2019-06-05T06:01:05.71727027Z
OS: ubuntu 18.04.2
docker-compose.yml
version: '2'
services:
selenium-hub:
container_name: selenium-hub
env_file:
- ./env/env.secret
environment:
TESTINGBOT_KEY: <my_key>
TESTINGBOT_SECRET: <my_secret>
TESTINGBOT_URL: http://hub.testingbot.com:80
image: dosel/zalenium:latest
ports:
- 4444:4444
volumes:
- /dev/shm:/dev/shm
- /var/run/docker.sock:/var/run/docker.sock
- /tmp/videos:/home/seluser/videos
privileged: true
stdin_open: true
tty: true
command: >
start
--timeZone "Asia/Tokyo"
--testingBotEnabled true
mytest script about driver (base.rb)
require 'selenium-webdriver'
require 'test/unit'
require 'common/capabilities'
module TestSets
class Base < Test::Unit::TestCase
attr_accessor(:driver, :target_host)
self.test_order = :defined
def setup
set_driver
#target_host = <target url>
#accept_next_alert = true
#verification_errors = []
set_window_size
# set timezone
ENV['TZ'] = "Asia/Tokyo"
end
def teardown
#driver.quit
assert_equal [], #verification_errors
end
def set_window_size
#driver.manage.window.resize_to(1600, 1024)
end
def set_driver
set_driver_remote(Capabilities.win10_ie11)
end
private
def set_driver_remote(caps)
#driver = Selenium::WebDriver.for(
:remote,
url: remote_url,
desired_capabilities: caps,
http_client: http_client,
)
end
def http_client
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 90
client
end
def remote_url
testingbot_url
end
def testingbot_url
%(https://#{Settings.testingbot.key}:#{Settings.testingbot.secret}#hub.testingbot.com/wd/hub)
end
end
end
common/capabilities.rb
module Capabilities
def self.win10_ie11
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["name"] = "win10_ie11"
caps["browserName"] = "Internet Explorer"
caps["version"] = "11"
caps["platform"] = "Windows 10"
caps["record_video"] = "true"
caps["timeZone"] = "Tokyo" # for TestingBot
caps
end
end

Thank you for your help.
I understand the cause.
The URL specified when creating the selenium driver directly specified the test bot without specifying the zalenium hub.
Right:
http://selenium-hub:4444/wd/hub
Wrong:
https://#{Settings.testingbot.key}:#{Settings.testingbot.secret}#hub.testingbot.com/wd/hub
The problem was simple.

Related

Issue with Selenium WebDrive with Docker image and Cucumber.io

Im trying to follow along with the following tutorial.
https://www.youtube.com/watch?v=cPF3GKkBHHY
I was getting the following error.
sh: 1: /sbin/ip: not found
But I managed to resolve that doing apt update then apt install iproute2 -y.
I am now getting the following error
cucumber
Feature: Search for things on Google and see results.
Scenario: See related words when searching. # features/basic.feature:3
When I search for "puppies" # features/step_defs.rb:1
Selenium::WebDriver::Remote::Driver needs :options to be set (ArgumentError)
./features/step_defs.rb:2:in `"I search for {string}"'
features/basic.feature:4:in `I search for "puppies"'
Then I should see "dog" # features/step_defs.rb:7
The error im looking to resolve is this one.
Selenium::WebDriver::Remote::Driver needs :options to be set (ArgumentError)
this is my .env.rb file.
require 'rspec' #for page.shoud etc
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'pry'
#if you're accessing an internal app behind a firewall, you may not need the proxy. You can unset it like so:
#ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
#get IP of host which has 4444 mapped from other container
docker_ip = %x(/sbin/ip route|awk '/default/ { print $3 }').strip
Capybara.register_driver :remote_chrome do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:desired_capabilities => :chrome,
:url => "http://#{docker_ip}:4444/wd/hub",
:options => chrome_options)
end
Capybara.configure do |config|
config.run_server = false
config.default_driver = :remote_chrome
config.app_host = 'http://www.google.com' # change this to point to your application
end
Any help with this would be greatly appreciated.
Thanks!
You need to create an instance of Selenium::WebDriver::Chrome::Options and pass it to the options argument. Add this chrome_options = Selenium::WebDriver::Chrome::Options.new in your code like below.
require 'rspec' #for page.shoud etc
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'pry'
#if you're accessing an internal app behind a firewall, you may not need the proxy. You can unset it like so:
#ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
#get IP of host which has 4444 mapped from other container
docker_ip = %x(/sbin/ip route|awk '/default/ { print $3 }').strip
# Add options for the Chrome browser
chrome_options = Selenium::WebDriver::Chrome::Options.new
# Disable notifications
chrome_options.add_argument("--disable-notifications")
Capybara.register_driver :remote_chrome do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:browser_name => :chrome,
:url => "http://#{docker_ip}:4444/wd/hub",
:options => chrome_options)
end
Capybara.configure do |config|
config.run_server = false
config.default_driver = :remote_chrome
config.app_host = 'http://www.google.com' # change this to point to your application
end
Solution:
Update env.rb file.
Before:
require 'rspec' #for page.shoud etc
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'pry'
#if you're accessing an internal app behind a firewall, you may not need the proxy. You can unset it like so:
#ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
#get IP of host which has 4444 mapped from other container
docker_ip = %x(/sbin/ip route|awk '/default/ { print $3 }').strip
Capybara.register_driver :remote_chrome do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:desired_capabilities => :chrome,
:url => "http://#{docker_ip}:4444/wd/hub")
end
Capybara.configure do |config|
config.run_server = false
config.default_driver = :remote_chrome
config.app_host = 'http://www.google.com' # change this to point to your application
end
After:
require 'rspec' #for page.shoud etc
require 'capybara/cucumber'
require 'cucumber'
require 'pry'
require "selenium-webdriver"
# Ask capybara to register a driver called 'selenium'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(
app,
#what browser do we want? Must match whatever is in our seleniarm stand-alone image
browser: :firefox,
#where does it live? By passing a URL we tell capybara to use a selenium grid instance (not local)
url: "http://#{ENV['SELENIUM_HOST']}:#{ENV['SELENIUM_PORT']}"
)
end
# make the driver we just registered our default driver
Capybara.default_driver = :selenium
# set the default URL for our tests
Capybara.app_host = "https://www.google.com/"
Update basic.feature
Before:
Feature: Search for things on Google and see results.
Scenario: See related words when searching.
When I search for "puppies"
Then I should see "dog"
Scenario: Don't see unrelated words when searching.
When I search for "dachshund"
Then I should NOT see "fish"
After:
Feature: Search for things on Google and see results.
Background:
Given I accept cookies
Scenario: See related words when searching.
When I search for "puppies"
Then I should see "dog"
Scenario: Don't see unrelated words when searching.
When I search for "dachshund"
Then I should NOT see "fish"
Update step_defs.rb
Before:
When("I search for {string}") do |string|
visit "/"
fill_in "q", with: string
click_on "Google Search", match: :first
end
Then("I should see {string}") do |string|
page.should have_content(string)
end
Then("I should NOT see {string}") do |string|
page.should_not have_content(string)
end
After:
Given('I accept cookies') do
visit "/"
click_on "Accept all"
end
When("I search for {string}") do |string|
visit "/"
fill_in "q", with: string
click_on "Google Search", match: :first
end
Then("I should see {string}") do |string|
page.should have_content(string)
end
Then("I should NOT see {string}") do |string|
page.should_not have_content(string)
end
# a handy debugging step you can use in your scenarios to invoke 'pry' mid-scenario and poke around
When('I debug') do
binding.pry
end
Update Dockerfile
Before:
#start with the base ruby image
FROM ruby
#make sure we have a folder called /app
RUN mkdir /app
#cd into our app folder each time we start up
WORKDIR /app
#copy our Gemfile and Gemfile.lock
COPY Gemfile* /app/
#install the gems
RUN bundle
CMD cucumber
After:
#start with the base ruby image
FROM ruby
#always a good idea to update and have an editor
RUN apt-get update; apt-get install -y vim
#make sure we have a folder called /app
RUN mkdir /app
#cd into our app folder each time we start up
WORKDIR /app
#copy our Gemfile and Gemfile.lock
COPY Gemfile* /app/
#install the gems
RUN bundle
CMD cucumber
Update Gemfile
Before:
source 'https://rubygems.org'
gem 'cucumber'
gem 'capybara'
#gem 'capybara-cucumber'
gem 'capybara-screenshot'
gem 'pry'
gem 'rspec'
gem 'selenium-webdriver'
After:
source 'https://rubygems.org'
gem 'cucumber'
gem 'capybara'
gem 'capybara-screenshot'
gem 'pry'
gem 'rspec'
#gem 'selenium-webdriver', '3.142.7' # Haven't been able to make 4.x work, yet...
gem 'selenium-webdriver', '~> 4.4.0'
Update docker-compose.yml
Before:
version: '3'
services:
browser:
# See inside via VNC with the "debug" version
image: selenium/standalone-chrome-debug
# Slightly faster headless version
#image: selenium/standalone-chrome
ports:
- "5900:5900" #for VNC access
- "4444:4444" #for webdriver access
ruby:
build: .
volumes:
- .:/app
depends_on:
- browser
After:
version: '3'
services:
browser:
#use for Apple Silicon
#image: seleniarm/standalone-chromium
# Chrome is crashing for me so I'm using firefox for now
image: seleniarm/standalone-firefox
ports:
- "5900:5900" #for VNC access
- "4444:4444" #for webdriver access
- "7900:7900" #for web VNC access
ruby:
build: .
volumes:
- .:/app
depends_on:
- browser
environment:
- SELENIUM_HOST=browser
- SELENIUM_PORT=4444

how to generate allure reports using page-object and watir

I have used the configuration mentioned in the allure-ruby-commons in the below link
https://github.com/allure-framework/allure-ruby/tree/master/allure-ruby-commons
But am unable to generate allure reports using the same. Can any one please help me on that.
How to generate allure reports using watir and page-object gem
require 'watir'
require 'page-object'
class GithubPage
include PageObject
link(:sign_in, text: /Sign in/)
text_field(:user_id, id: 'login_field')
text_field(:password, id: 'password')
button(:login_btn, value: 'Sign in')
link(:notification, href: '/notifications')
list_items(:name_count, xpath: "//p[text()='Repositories']/following-sibling::ul/li")
span(:select_all, text: /Select all/)
button(:select_remaining, text: /Select all/)
button(:done_all, css: "div[class*='notifications-mark-all-actions'] button[title='Done']")
button(:done, css: "div[class*='notifications-mark-selected-actions'] button[title='Done']")
h3(:no_notifications, text: 'All caught up!')
def login(username, password)
sign_in
self.user_id = username
self.password = password
login_btn
end
def check_and_read_notifications
notification_element.when_visible.click
if no_notifications?
puts 'There are no Notifications left'
else
name_count_elements.each do |name|
puts name.text
end
select_all_element.click
if select_remaining?
select_remaining
done_all
else
done
end
sleep 1
notification
end
end
end
require_relative 'github_page.rb'
require 'allure-ruby-commons'
browser = Watir::Browser.new :chrome, headless: true
browser.window.resize_to(1920, 1080)
github = GithubPage.new(browser)
github.navigate_to 'http://github.com'
github.login('test', 'tester')
github.check_and_read_notifications
Allure.configuration
Allure.configure do |config|
config.results_directory = "./Results"
config.clean_results_directory = true
config.logging_level = Logger::INFO
end

Watir/Page Object Existence Methods Timing Out

I recently upgraded from:
Page Object 1.2.2
Watir-Webdriver 0.9.9
Selenium WebDriver 2.53.0
Firefox 45.8.0
To:
Page Object 2.2.0
Watir 6.3.0
Selenium-Webdriver 3.4.3
Firefox 52.2.0
After a little bit of pain, I've finally gotten my tests to start running! One small snag though. The methods #present?, #exists?, and #visible? don't return anything, they just timeout instead. Similarly, #wait_until, x_element.when_present?, and similar methods all hit the same problem!
Here is my page object:
class LoginPage < TeamConnectPage
MAX_LOGIN_ATTEMPTS = 3
button :ok, value: /^OK$/i
button :submit, value: 'Login'
button :new_session, value: 'New Session'
link :logout, id: 'LINK_default_logout'
span :error_message, class: 'texterror'
text_field :username, name: 'j_username'
text_field :password, name: 'j_password'
def login_as(username)
username = username.to_s
do_logout if logged_in?
attempts = 0
try_login(username)
while username_element.present?
fail "#{MAX_LOGIN_ATTEMPTS} logins attempted unsuccessfully for user #{username}" if (attempts+=1) == MAX_LOGIN_ATTEMPTS
try_login(username)
end
if new_session_element.present?
new_session
logout_element.when_present(10)
end
end
private
def try_login(username)
self.username = username
self.password = 'test'
submit
wait_for_login_submit
end
def wait_for_login_submit
wait_until(10) { !username_element.present? || (username_element.present? && username_element.value.empty?) }
wait_until(10) { error_message_element.present? || logout_element.present? || new_session_element.present? }
end
def do_logout
logout
end
def logged_in?
logout_element.present?
end
end
Here's the step definition where I'm calling the page object:
def login_role role
caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
#browser ||= Watir::Browser.new(:firefox, desired_capabilities: caps)
#browser.driver.manage.window.maximize
#browser.goto('http://ntdmatters-it4.nwie.net/TeamConnect/login')
#logged_in_user = User[RoleMapping[role]]
on_page(LoginPage).login_as(#logged_in_user.userid)
end
Here's my load order:
require 'pry'
require 'active_support'
require 'active_support/core_ext'
require 'chronic'
require 'page-object'
require 'rspec'
require 'watir'
require 'selenium-webdriver'
And here's the error I'm getting:
timed out after 30 seconds, waiting for #<Watir::Anchor: located: false; {
:id=>"LINK_default_logout", :tag_name=>"a"}> to be located (Watir::Exception::UnknownObjectException)
(eval):1:in `process_watir_call'
./features/support/env.src/pages/login_page.rb:48:in `do_logout'
./features/support/env.src/pages/login_page.rb:15:in `login_as'
./features/step_definitions/login_steps.rb:24:in `login_role'
./features/step_definitions/login_steps.rb:2:in `/^I login to Project
with role (.*)$/'
What happens is that the script will hit that the #logged_in? method and just sit there. Then it will time out and give me the above error message.
I can't help and wonder if this is some sort of configuration problem and that things just need to be loaded correctly or if there's some sort of deeper trap I have fallen into.
EDIT:
When I changed the Selenium logger level to 'Info', I got the following repeated for 30 seconds:
2017-07-12 12:11:21 INFO Selenium >>> http://127.0.0.1:4444/session/8d74a28f-
d8fc-4db6-a851-4f238edf7d70/element | {"using":"css selector","value":"#LINK_def
ault_logout"}
2017-07-12 12:11:21 INFO Selenium <- {"value":{"error":"no such element","messag
e":"Unable to locate element: #LINK_default_logout","stacktrace":"stack backtrac
e:\n 0: 0x4bd56f - <no info>\n 1: 0x4bdcc9 - <no info>\n
2: 0x43dc4d - <no info>\n 3: 0x44db84 - <no info>\n 4
: 0x44a1ca - <no info>\n 5: 0x4207bc - <no info>\n 6:
0x405e47 - <no info>\n 7: 0x6db3d9 - <no info>\n 8:
0x417847 - <no info>\n 9: 0x6d56d3 - <no info>\n 10: 0x
776c59cd - BaseThreadInitThunk"}}
EDIT2: This occurs whether or not the element is actually present or not.

How to properly debug with Capybara/Poltergeist?

I am playing around with capybara/poltergeist perfect duo, but I am having trouble to properly debugging.
I was testing a simple script:
logger = Logger.new "./log/who-scored-com.log"
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: false,
debug: true,
logger: logger)
end
browser = Capybara.current_session
browser.visit 'https://www.whoscored.com/LiveScores'
browser.save_page 'page.html'
I am expecting that the script grap the page normally and saves it, but the page is empty and this is returned:
`Capybara::Poltergeist::StatusFailError: Capybara::Poltergeist::StatusFailError
from /home/vagrant/local/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/browser.rb:351:in `command'
from /home/vagrant/local/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/browser.rb:34:in `visit'`
Now, this don't give me nothing about this error. I catch the exception and print it and it gives me:
"Request to 'https://www.whoscored.com/LiveScores' failed to reach server, check DNS and/or server status"
Even if I have no idea why the address do not respond for capybara (and any hint would be appreciate :) ) I don't understand why the :debug options used in configuration doesn't seem to give me no info
You have a couple of issues
the poltergeist logger option is defined as '(Object responding to puts) - The ruby 2.3.0 standard library Logger object doesnt respond to puts so it's not valid.
You're example doesn't have Capybara.current_driver = :poltergeist so I'm not sure if it is actually using the driver you're configuring there or a previously defined one (I would have expected an error on the Logger object if it was)
debug: true will add debugging for poltergeist to the log, but there is also debugging info from phantomjs. That is generated by passing phantomjs_options: ['--debug=true'], phantomjs_logger: <an IO object - again not a Logger object> to the driver
The error you're actually hitting is the connection being refused due to not being able to negotiate an ssl protocol - to fix it add the required ssl protocol as a phantomjs option - `phantomjs_options: ['--ssl-protocol=TLSv1.2']
I'd use something like the following in a standalone ruby script, adjust driver_options to suit your taste.
require 'capybara'
require 'capybara/poltergeist'
class NilLogger
def puts * ; end
end
def setup_session
driver_options = { js_errors: false,
logger: NilLogger.new,
phantomjs_logger: STDOUT,
phantomjs_options: ['--debug=true'],
debug: false }
Capybara.configure do |conf|
conf.run_server = false
conf.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new app, driver_options
end
conf.current_driver = :poltergeist
end
Capybara.current_session
end
browser = setup_session()
browser.visit 'https://www.whoscored.com/LiveScores'
browser.save_page 'page.html'
Have you tried
Capybara.register_driver :poltergeist_debug do |app|
Capybara::Poltergeist::Driver.new(app, :inspector => true)
end
Capybara.javascript_driver = :poltergeist_debug
as shown here?

Ruby Thrift::TransportException End of File Reached

I made a Ruby web server based on Apache Thrift, but the client (also in ruby, for unit tests) refuses to work and keeps telling me either Thrift::TransportException: Could not connect to 127.0.0.1:8001: Connection refused - connect(2) for 127.0.0.1:8001, or Thrift::TransportException: end of file reached. Tried a bunch of different server implementations and transports, and that doesn't seem to work.
When the server is running, lsof -i :8001 shows
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 19073 lafickens 9u IPv4 0x878e6fd36b981a71 0t0 TCP *:vcom-tunnel (LISTEN)
So I think the server is functioning.
Here's the server code:
class Server
attr_reader :name
def initialize(name)
#LOGGER = Logger.new $stdout
#name = name
#started = false
#processor = ::Thrift::MultiplexedProcessor.new
#processor.register_processor 'User Service', Thrift::UserService::Processor.new(Handlers::UserServiceHandler.new)
#processor.register_processor 'Sync Service', Thrift::SyncService::Processor.new(Handlers::SyncServiceHandler.new)
end
def start
#transport = ::Thrift::ServerSocket.new(Options.get('port'))
#transport_factory = ::Thrift::BufferedTransportFactory.new
#protocol_factory = ::Thrift::CompactProtocolFactory.new
#server = ::Thrift::ThreadPoolServer.new #processor, #transport, #transport_factory, #protocol_factory
#server_thread = Thread.new {
#server.serve
}
#started = true
#LOGGER.info('Server started successfully')
end
def stop
return if #server_thread.nil?
#server_thread.exit
#transport.close
#started = false
#LOGGER.info('Server stopped successfully')
end
def restart
stop
start
end
def started?
#started
end
end
Client code (actually unit tests)
class TestUserServiceHandler < Test::Unit::TestCase
def setup
#server = Billboard::Server.new 'test handler'
#server.start
#port = Billboard::Options.get 'port'
#transport = ::Thrift::BufferedTransport.new(::Thrift::Socket.new('127.0.0.1', #port))
#binary_protocol = ::Thrift::BinaryProtocol.new #transport
#multiplexed_protocol = ::Thrift::MultiplexedProtocol.new #binary_protocol, 'mprotocol'
#client = Billboard::Thrift::UserService::Client.new #multiplexed_protocol
#transport.open
end
def teardown
#server.stop
#transport.close
end
def test_authenticate
#client.authenticate('test', 'test')
end
# And other tests...
end
Thanks in advance.

Resources