Our application after a certain transaction need to login to a third party system and enter some data. Made a system test with Capybara and selenium and that works great, however that's when running it at a test. I'd like to create a class/service that will run in an ActiveJob to do the same so after the save of the transaction I'd like to call ActiveJob.perform_later(params) and the params should pass to the 'external_system_integration' class and run headless to login to the third party site and enter the data received in params.
How to do this?
My Class
require 'capybara/dsl'
require 'capybara/rspec'
require "selenium/webdriver"
class OrderDeskService
Capybara.default_driver = :webkit
include Capybara::DSL
def self.login
Capybara.register_driver :chrome do |app|
profile = Selenium::WebDriver::Chrome::Profile.new
profile["download.default_directory"] = DOWNLOAD_PATH
Capybara::Selenium::Driver.new(app, :browser => :chrome, :profile => profile)
end
Capybara.configure do |config|
config.run_server = false
config.app_host = 'https://app.orderdesk.me'
end
visit '/login'
sleep 10
end
end
EDIT after the feedback:
Capybara.configure do |c|
c.run_server = false
c.app_host = 'https://app.orderdesk.me'
end
#Configure
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Chrome::Profile.new
profile["download.default_directory"] = DOWNLOAD_PATH
Capybara::Selenium::Driver.new(app, :browser => :chrome, :profile => profile)
end
#headless
Capybara.register_driver :headless_chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: %w[headless disable-gpu enable-features=NetworkService,NetworkServiceInProcess]
}
)
Capybara::Selenium::Driver.new app,
browser: :chrome,
desired_capabilities: capabilities
end
#make it thread safe
Capybara.threadsafe = true
Capybara.default_driver = Capybara.javascript_driver = :headless_chrome
class OrderDeskService
include Capybara::DSL
def self.login
session = Capybara::Session.new(:selenium)
session.visit '/login'
sleep 3
session.quit
end
end
Trying to run in headless mode but it still opens Chrome browser.