How to automate already installed ios Apps using Appium - mobile

How to automate already installed ios Apps using Appium. I want to automate like whatsap ebay and other installed apps in my iphone using appium.

You should be able to automate the app if you know the bundleId of the application. For WhatsApp the bundleId is net.whatsapp.WhatsApp
If your Appium set up is correct and have python installed then, start an Appium Server and Run the sample python code. You can attach the session to the Appium inspector to inspect the elements.
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '12.4.6'
desired_caps['name'] = 'Sample Test'
desired_caps['deviceName'] = 'iPhone 6'
desired_caps['udid'] = 'add_your_device_udid_here'
desired_caps["bundleId"] = "net.whatsapp.WhatsApp"
desired_caps["noReset"] = True
desired_caps["newCommandTimeout"] = 50000
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

You need to add bundle ID capability with existing capabilities.
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.UDID, "udid");
caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12.4");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
caps.setCapability("unicodeKeyboard", true);
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
caps.setCapability(MobileCapabilityType.NO_RESET, true);
caps.setCapability("bundleId", "com.company.appname");
caps.setCapability("usePrebuiltWDA", true);
IOSDriver<WebElement> driver = new IOSDriver<WebElement>(new URL("http://127.0.0.1:4444/wd/hub"), caps)
I have added UDID capability which is used for real device.

this work for me
{
"automationName": "XCUITest",
"platformName": "iOS",
"deviceName": "iPhone",
"udid": "...",
"xcodeOrgId": "...",
"platformVersion": "xx.y",
"updatedWDABundleId": "com.facebook.WebDriverAgentRunner"
}

Related

In Selenium webdriver, for remote Firefox how to use OSS bridge instead of w3c bridge for handshaking

I am using selenoid for remote browser testing in ruby.
In that I am using 'selenium-webdriver', 'capybara', 'rspec' for automation. And I am using attach_file method for uploading file to browser
I want to upload file on Firefox and Chrome browser but it raises error on both;
In chrome
Selenium::WebDriver::Error::UnknownCommandError: unknown command: unknown command: session/***8d32e045e3***/se/file
In firefox
unexpected token at 'HTTP method not allowed'
So After searching I found the solution for chrome which is to set w3c option false in caps['goog:chromeOptions'] > caps['goog:chromeOptions'] = {w3c: false}
So now chrome is using OSS bridge for handshaking but I don't know how to do it in Firefox. Similar solution is not available for Firefox.
My browser capabilities are following:
if ENV['BROWSER'] == 'firefox'
caps = Selenium::WebDriver::Remote::Capabilities.new
caps['browserName'] = 'firefox'
# caps['moz:firefoxOptions'] = {w3c: false} ## It is not working
else
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browserName"] = "chrome"
caps["version"] = "81.0"
caps['goog:chromeOptions'] = {w3c: false}
end
caps["enableVNC"] = true
caps["screenResolution"] = "1280x800"
caps['sessionTimeout'] = '15m'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :remote,
:desired_capabilities => caps,
:url => ENV["REMOTE_URL"] || "http://*.*.*.*:4444/wd/hub"
)
end
Capybara.configure do |config|
config.default_driver = :selenium
end
I have found the problem. There is bug in selenium server which run on java so I have to change my selenium-webdriver gem version 3.142.7 and monkey-patch.
You can find more information here about the bug and resolution.
For now I have to change my gem and monkey patch the selenium-webdriver-3.142.7\lib\selenium\webdriver\remote\w3c\commands.rb file. check for below line which is on line no 150.
upload_file: [:post, 'session/:session_id/se/file']
and update it to
upload_file: [:post, 'session/:session_id/file']
i had a similar issue with rails 7. the issue is connected with the w3c standard. the core problem is that the webdriver for chrome uses a non-w3c standard url for handling file uploads. when uploading a file, the webdriver uses the /se/file url path to upload. this path is only supported by the selenium server. subsequently, the docker image provided by selenium works fine. yet, if we use chromedriver, the upload fails. more info.
we can solve this, by forcing the webdriver to use the standard-compliant url by overriding the :upload_file key in Selenium::WebDriver::Remote::Bridge::COMMANDS. since, the initialization of this the COMMANDS constant does not happen when the module is loaded, we can override the attach_file method to make sure the constant is set correctly. here the hacky code:
module Capybara::Node::Actions
alias_method :original_attach_file, :attach_file
def attach_file(*args, **kwargs)
implement_hacky_fix_for_file_uploads_with_chromedriver
original_attach_file(*args, **kwargs)
end
def implement_hacky_fix_for_file_uploads_with_chromedriver
return if #hacky_fix_implemented
original_verbose, $VERBOSE = $VERBOSE, nil # ignore warnings
cmds = Selenium::WebDriver::Remote::Bridge::COMMANDS.dup
cmds[:upload_file] = [:post, "session/:session_id/file"]
Selenium::WebDriver::Remote::Bridge.const_set(:COMMANDS, cmds)
$VERBOSE = original_verbose
#hacky_fix_implemented = true
end
end
In Firefox images we support /session/<id>/file API by adding Selenoid binary which emulates this API instead of Geckodriver (which does not implement it).

Setting downloads directory for chrome driver suddenly stopped working after upgrade

After I've upgraded my project to use latest java selenium webdriver 3.7.1 and latest chrome driver 2.33 I noticed that my tests dealing with Excel export started to fail.
After debugging I see that for some reasons downloads directory is not being set to custom location and instead the default one is used. Nothing shows up in logs or whatsoever.
Any help appreciated.
Setting downloads directory is like usual:
val prefs = Map(
"profile.default_content_settings.popups" -> Integer.valueOf(0),
"download.default_directory" -> downloadsDir,
"credentials_enable_service" -> false,
"profile.password_manager_enabled" -> false
)
val chromeOptions:ChromeOptions = new ChromeOptions()
chromeOptions.setExperimentalOption("prefs", prefs)
val d = new ChromeDriver(chromeOptions)
I use WebDriver 3.7.1 and Chromedriver 2.33 and of course Chrome v.62 (try check Your Version of Chrome), and I can download files.
I'm using folder
public static String javaIoTmpDir = System.getProperty("java.io.tmpdir")+"/autotest/";
and I create/clean it with script in TestNG annotation: #BeforeSuite
File theDir = new File(javaIoTmpDir);
// if the directory does not exist, create it
if (!theDir.exists()) {
System.out.println("creating directory: " + theDir.getName());
boolean result = false;
try{
theDir.mkdir();
result = true;
}
catch(SecurityException se){
se.printStackTrace();
}
if(result) {
System.out.println(javaIoTmpDir+" created");
}
}
FileUtils.cleanDirectory(new File(javaIoTmpDir));
}

Unable to pass a profile to Capybara when creating a new driver

I'm using a ruby/cucumber/capybara framework with versions:
capybara (2.10.1)
selenium-webdriver (3.0.0)
ruby 2.3.1p112 (2016-04-26 revision 54768) [x64-mingw32]
and I'm trying to register a new driver with some settings passed in the profile to capybara. My code looks like this:
Capybara.register_driver :debug do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end
and I've tried as well with:
Capybara::Selenium::Driver.new(app, :profile => profile)
Then I just use the following to select that driver:
Capybara.default_driver = :debug
but in both cases, when I try to run any test, I get the following error:
ArgumentError: unknown option: {:profile=>#<Selenium::WebDriver::Firefox::Profile:0x000000068ca798 #model=nil, #native_events=true, #secure_ssl=false, #untrusted_issuer=true, #load_no_focus_lib=false, #additional_prefs={}, #extensions={}>}
Any idea what the problem could be? and how to ammend it?
Firefox Profiles are not yet supported in Ruby bindings for geckodriver, which is needed for Firefox 48+. Watch this issue for (hopefully very soon) resolution: https://github.com/SeleniumHQ/selenium/issues/2933

Selenium 3.0.1, gekodriver v0.11.1, firefox 49.0.2 "Unable to connect to host 127.0.0.1 on port 7055" exception

Trying to upgrade to Selenium 3.0 from Selenium 2.53. I can not put firefox in path, nor can put the gekodriver in path. I was using this in Selenium 2:
String firefoxLocation = System.getenv("ProgramFiles(X86)") + "\\Mozilla Firefox_42\\firefox.exe";
System.setProperty("webdriver.firefox.bin", firefoxLocation);
driver = new FirefoxDriver();
This worked perfectly. I upgraded to Selenium 3.0, installed firefox 49 and downloaded the latest geko. I now have this:
String firefoxLocation = System.getenv("ProgramFiles(X86)") + "\\Mozilla Firefox_49\\firefox.exe";
String gekoLocation = "..\\common\\geko\\gekodriver.exe";
System.setProperty("webdriver.firefox.bin", firefoxLocation);
System.setProperty("webdriver.firefox.marionette", gekoLocation);
driver = new FirefoxDriver();
Firefox opens to a blank window, then times out. I tried instead of setting webdriver.firefox.marionette, setting webdriver.geko.driver, but got the error that I must use "webdriver.geko.driver" (which I was using). How do I arrange it so I can specify a different firefox.exe location and a different gekodriver.exe location?
spelling wrong.
try this:
System.setProperty("webdriver.gecko.driver", gekoLocation);
use gecko instead of geko

Can I run a functional test using theintern js framework without setting up a standalone selenium server?

I have a working webdriver javascript test script for my html page that runs using ChromeDriver without needing to start up a selenium standalone server:
test.js
'use strict';
var path = require('path');
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var options = new chrome.Options();
var logging_prefs = new webdriver.logging.Preferences();
logging_prefs.setLevel(webdriver.logging.Type.BROWSER, webdriver.logging.Level.ALL);
options.setLoggingPrefs(logging_prefs);
var driver = new webdriver.Builder().withCapabilities(options.toCapabilities()).build();
driver.get('file://' + path.resolve('./index.html'));
// Do some testing
driver.quit();
I want to port this test to use theintern.io, but I'd prefer not to have to run a standalone selenium server. Is this possible?
[Edit: Add info on the error and theintern config]
I see the error [POST http://localhost:4444/wd/hub/session] connect ECONNREFUSED which I guess is because I don't have the standalone server running.
My theintern config looks like this:
define({
environments: [
{ browserName: 'chrome' }
],
// Name of the tunnel class to use for WebDriver tests
tunnel: 'NullTunnel',
// Non-functional test suite(s) to run in each browser
suites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */ ],
// Functional test suite(s) to run in each browser once non-functional tests are completed
functionalSuites: [ 'tests/functional/index' ],
// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^(?:tests|node_modules)\//
});
My theintern test looks like this:
define([
'intern!object',
'intern/chai!assert',
'require'
], function (registerSuite, assert, require) {
registerSuite({
name: 'index',
'first test': function () {
return this.remote
.get(require.toUrl('index.html'))
... //more test logic
}
});
});
Intern speaks the standard WebDriver protocol so can be used with any server that implements the specification, not just Selenium. In this case if you are trying to connect to ChromeDriver just make sure that it is running first (chromedriver --port=4444 --url-base=wd/hub) and then run intern-runner config=mid/of/config and you should be good to go with the configuration that you currently have.

Resources