def create_browserstack_session(scenario, bs_app_id)
Capybara.register_driver :appium do |app|
desired_caps = {
caps:
{
platformName: 'ios',
connectHardwareKeyboard: false,
automationName: 'XCUITest',
processArguments: '{"args": [],"env": {"TESTING":"YES"}}',
device: ENV['IOS_DEVICE'],
os_version: ENV['IOS_VERSION'],
udid: ENV['IOS_DEVICE_UDID'],
build: ENV['IOS_TESTING_BUILD_CUSTOM_ID'],
testing_app: ENV['IOS_TESTING_BUILD_CUSTOM_ID'],
app: bs_app_id,
name: scenario.location.to_s.split('tests/').last,
newCommandTimeout: ENV['NEW_COMMAND_TIMEOUT'],
},
appium_lib: {
server_url: ENV['BROWSERSTACK_SERVER'],
set_wait: ENV['SELENIUM_IMPLICIT_WAIT'].to_i
}
}
I need to Add this caps to "desired_caps = {caps:} if app name is "provider"
if ENV[APP_NAME] = 'PROVIDER'
autoAcceptAlerts: = 'true'
end
Appium::Capybara::Driver.new app, desired_caps
end
end
I know we have to use merge but unclear how to get it accomplished
Related
How can I initiate appium driver for android using ruby capybara framework
def register_cloud_mobile_driver
Capybara.register_driver :cloud_mobile do |app|
opts = Selenium::WebDriver::Remote::Capabilities.firefox(
securityToken: #sec_token,
platformVersion: 'xx',
platformBuild: 'xxxxx',
manufacturer: 'xxx',
model: 'Galaxy S22',
resolution: '1080x2340',
deviceStatus: 'CONNECTED',
location: 'xxxx',
appPackage: 'xxxxx',
appActivity: 'xxxxx.activity.SplashActivityV2',
takesScreenshot: false,
screenshotOnError: true
)
Capybara::Selenium::Driver.new(app, browser: :remote, url: $server_url, desired_capabilities: opts)
Capybara.default_driver = cloud_mobile
end
end
Result:
"undefined method `testExecutionTags' for nil:NilClass
"WARN: Screenshot could not be saved. `page.current_path` raised exception:
#<ArgumentError: rack-test requires a rack application, but none was given>.
App automation flow is working fine on using uiautomator, but on adding uiautomator2 in capabilities it's not able to detect the elements on hybrid and web pages of an app.
require 'appium_lib'
require 'pry'
def caps
{
caps: {
deviceName: "nexus",
platformName: "Android",
app: (File.join(File.dirname(__FILE__), "googlerelease.apk")),
appPackage: "com.redmond.android",
newCommandTimeout: "3600",
autoGrantPermissions: true,
automationName: "UiAutomator2"
}
}
end
Appium::Driver.new(caps, true)
Appium.promote_appium_methods Object
url = 'SomeUrl'
args{ someKey: 'Value',
key2: 'Value2'
}
The method currently uses both of these as arguments. I combined both these arguments into a single hash as:
opts = {
Hello: {
Name: 'John',
Version: '1.0'
},
World: {
platformVersion: '3.4x',
helloVersion: '2.3'
}
}
What I'm trying is Combine these two hashes and separate them at runtime in this method:
def initialize(opts)
#this is how it was done before
SomeClass.for(:remote, opts)
#What I want here is to split that hash into two arguments
end
opts = {
Hello: {
Name: 'John',
Version: '1.0'
},
World: {
platformVersion: '3.4x',
helloVersion: '2.3'
}
}
def initialize(opts)
SomeClass.for(:remote, opts[:Hello], opts[:World])
end
This is what you want?
SomeClass.for method will receive three arguments:
:remote
{ Name: 'John', Version: '1.0' }
{ platformVersion: '3.4x', helloVersion: '2.3' }
I'm trying to debug why when running remote webdriver tests on a headless linux host download dialogs are presented in chrome. I believe the chrome version is 45.
Couple of Env Details
Selenium 2.53 (gem)
Selenium 2.53 Server Jar
Chrome Driver 2.21
The framework/Tests are written in Ruby utilizing Capybara for driving web tests. Here is a brief snippet of how the remote driver is initialized.
prefernces = {
:download => {
:prompt_for_download => false,
:default_directory => '/home/john.doe/Downloads/'
}
}
caps = Selenium::WebDriver::Remote::Capabilities.chrome()
caps['chromeOptions'] = {'prefs' => prefernces}
http_client = Selenium::WebDriver::Remote::Http::Default.new
http_client.timeout = 240
options = {
browser: :remote,
url: "http://<server_url>:4444/wd/hub",
desired_capabilities: caps,
http_client: http_client
}
# Returns Remote Driver
Capybara::Selenium::Driver.new(app, options)
I have verified via the hub that the chromeOptions are set, but when a file is downloaded, we're presented with a file dialog prompt.
I've burned the candle looking for a solution to this problem. Thanks for the help and consideration!
try removing the / from the end of the default_directory and also setting directory_upgrade: true. Other than that make sure the browser has permission to write to the selected directory (note also the correct spelling of preferences)
preferences = {
:download => {
:default_directory => '/home/john.doe/Downloads',
:directory_upgrade => true,
:prompt_for_download => false,
}
}
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => {'prefs' => preferences}
)
Here is an example to download a file with Capybara / Selenium / Chrome :
require 'capybara'
require 'selenium-webdriver'
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
:url => "http://localhost:4444/wd/hub",
:browser => :chrome,
:desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => {
'prefs' => {
'download.default_directory' => File.expand_path("C:\\Download"),
'download.directory_upgrade' => true,
'download.prompt_for_download' => false,
'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
}
}
)
)
end
session = Capybara::Session.new(:chrome)
session.visit "https://www.mozilla.org/en-US/foundation/documents"
session.click_link "IRS Form 872-C"
sleep 20
I am using Watir for a data fetching job where I don't need any images to be loaded. Is it possible to block them?
I think it can be:
profile = Selenium::WebDriver::Chrome::Profile.new
profile['webkit.webprefs.loads_images_automatically'] = false
#browser = Watir::Browser.new :chrome, :profile => profile
See: http://watir.github.io/docs/chrome/
Use :
webkit: { webprefs: { loads_images_automatically: false } } or profile: { default_content_setting_values: { images: 2 } }
Disable displaying images in the browser Watir drives manually, and then run Watir script. As far as I know, you can not do it from Watir itself.
prefs = {
:profile => {
:managed_default_content_settings => {
:images => 2
}
}
}
b = Watir::Browser.new :chrome, :prefs => prefs
Watir 7.1.0
Selenium 4.1.0
prefs = {
profile: {
managed_default_content_settings: {
images: 2
}
}
}
Watir::Browser.new(:chrome, options: { prefs: prefs })
If you need to specify the URL of the Selenium server/grid:
Watir::Browser.new(:chrome, options: { prefs: prefs }, url: url)