Я пытаюсь следовать следующему руководству.
https://thewikihow.com/video_cPF3GKkBHHY
Я получал следующую ошибку.
sh: 1: /sbin/ip: not found
Но мне удалось решить это, делая apt update
то apt install iproute2 -y
.
Теперь я получаю следующую ошибку
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
Ошибка, которую я ищу, чтобы решить, это одна.
Selenium::WebDriver::Remote::Driver needs :options to be set (ArgumentError)
это мой файл .env.rb.
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
Любая помощь в этом будет принята с благодарностью.
Спасибо!
🤔 А знаете ли вы, что...
Ruby поддерживает интернационализацию и работу с различными языками и символами.
Вам нужно создать экземпляр Selenium::WebDriver::Chrome::Options
и передать его в options argument
. Добавьте это chrome_options = Selenium::WebDriver::Chrome::Options.new
в свой код, как показано ниже.
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
Решение:
Обновите файл env.rb.
До:
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
После:
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/"
Обновить базовую.функцию
До:
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"
После:
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"
Обновление step_defs.rb
До:
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
После:
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
Обновить Dockerfile
До:
#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
После:
#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
Обновите Gemfile
До:
source 'https://rubygems.org'
gem 'cucumber'
gem 'capybara'
#gem 'capybara-cucumber'
gem 'capybara-screenshot'
gem 'pry'
gem 'rspec'
gem 'selenium-webdriver'
После:
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'
Обновить docker-compose.yml
До:
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
После:
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