I am trying to automate android apps using python (or possibly ruby), by linking into the provided UIAutomator in the android SDK.
Right now I am trying to use a Python tool here, but I am having issues connecting (getting TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Code snipped of what i am trying to do with the Python tool:
def print_info():
print('Getting info...')
d = ui.Device('SERIAL_NUMBER', adb_server_host='192.168.1.20', adb_server_port='5037')
print(d.info)
Is there something wrong with how I am trying to send commands? Alternatively, is there a better ruby/python tool for testing android devices?
Update I am now using the Appium library Ruby gem to test. Got applications to launch, however things like tapping the screen result in this error
assert_ok': A session is either terminated or not started
(Selenium::WebDriver::Error::NoSuchDriverError)`
This is the code
desired_caps = {
caps: {
appiumVersion: '1.6.5',
platformName: 'Android',
platformVersion: '4.4',
browserName: '',
deviceName: 'DEVICE_SERIAL',
app: 'APK',
appActivity: 'mainactivity',
appWaitDuration: '60000', # wait a minute (set to 20000 by default)
clearSystemFiles: 'true'
},
appium_lib: {
sauce_username: nil,
sauce_access_key: nil
}
}
$driver = Appium::Driver.new(desired_caps)
$driver.start_driver
sleep(60) # wait a minute for app to fully load, before tring to tap anything
touch_action = Appium::TouchAction.new
touch_action.press(x: 243, y: 288).wait(5).release.perform
touch_action.press(x: 311, y: 165).wait(5).release.perform
This is how I do it for an emulator
app_path = File.absolute_path('automateme.apk', 'data')
caps = {
:platformName => "android",
:deviceName => "android",
:app => app_path,
:noReset => 'true',
:newCommandTimeout => "30"
}
#driver = Appium::Driver.new(:caps => caps).start_driver
try this and let me know if it helps... :)
There is an one good mobile test automation tool available - Appium.
Currently I have been using ruby,appium,cucumber,selenium webdriver for android automation. I am suggesting that you will try to use Appium tool for mobile automation. below is important link,
http://www.software-testing-tutorials-automation.com/2015/09/appium-tutorials.html
https://community.perfectomobile.com/posts/1103155-ruby-example-for-appium-android
http://appium.io/slate/en/tutorial/android.html?ruby#troubleshooting
following is the example to start
require 'appium_lib'
desired_caps = {
caps: { appiumVersion: '1.6.0',
platformName: 'Android',
platformVersion: '4.4.2',
browserName: '',
deviceName: 'Samsung Galaxy S4 Emulator',
app: 'D:\Workspace\android-sample-app.apk',
name: 'Ruby Appium Sauce example'
} }
driver = Appium::Driver.new(desired_caps)
puts driver
begin
driver.start_driver
rescue Exception => e
puts e
end
driver.first_textfield.send_key 10
driver.last_textfield.send_key 20
driver.first_button.click
driver.driver_quit
download "android-sample-app.apk" and put in any path and also set this path
in desired_caps.
Thanks,
Kapil Chothe
Related
hope you are well, I am trying to configure Codeceptjs to work with Appium, for proof of concept I only need the configuration to naviagte to a website amazon.com for example and create an account.
I have been reading the appium documentation and the following is stated for Chrome on Andriod 'For web tests, to automate Chrome instead of your own application, leave the app capability empty and instead set the browserName capability to Chrome.' Can be found here https://appium.io/docs/en/drivers/android-uiautomator2/
So I have left 'app' blank as it tells me to do, but every time i run my test I get the following error
Error: Failed to create session.
An unknown server-side error occurred while processing the command. Original error: 'app' option is required for reinstall
My config is as follows, I have been changing settings for the past few days with no luck, any help or pointing me in the right direction would be really appreciated, thank you in advance.
```exports.config = {
tests: './*_test.js',
output: './output',
helpers: {
// WebDriver: {
// url: 'https',
//browser: 'chrome'
// },
Appium: {
path: '/wd/hub',
port: 4723,
platform: 'Android',
url: 'https://www.test.com',
desiredCapabilities:{
deviceName: "emulator-5554",
platformVersion: "11.0",
platformName: 'Android',
deviceName: 'Android Emulator',
automationName: 'UIAutomator2',
browserName: 'Chrome'
}
}
},
include: {
I: './steps_file.js'
},
bootstrap: null,
mocha: {},
name: 'CodeceptJS',
plugins: {
wdio: {
enabled: true,
services: ['selenium-standalone']
},
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
}
} ```
Configuration issue on my end, incompatable chrome browser version to to the chrome driver, has been resloved with a simple appium command
I've got a selenium grid with chrome, firefox and android node running
and I have this protractor configuration within an angular cli project:
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const {SpecReporter} = require('jasmine-spec-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var screenshotReporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html'
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
multiCapabilities: [{
'browserName': 'chrome'
}, {
'browserName': 'firefox'
}, {
'browserName': 'android',
'platformName': 'Android',
'platformVersion': '7.1.1',
'deviceName': 'Nexus 5'
}],
// directConnect: true,
seleniumAddress: "http://localhost:4444/wd/hub",
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function () {
}
},
beforeLaunch: function () {
return new Promise(function (resolve) {
screenshotReporter.beforeLaunch(resolve);
});
},
onPrepare: function () {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}}));
jasmine.getEnv().addReporter(screenshotReporter);
},
afterLaunch: function (exitCode) {
return new Promise(function (resolve) {
screenshotReporter.afterLaunch(resolve.bind(this, exitCode));
})
}
};
When I launch my ng e2e task, tests are running fine on firefox and chrome node. However, I've got this error coming from the android capability:
WebDriverError: An unknown server-side error occurred while processing the command. Original error: The desired capabilities must include either an app, appPackage or browserName
...
If I get it right the android webdriver asks me to include a browserName although I already provide it one. Does anyone have an idea?
the andriod capability in your protractor config file will failed to get any matched node for you. Because you use one wrong name and one wrong value in capability.
you use 'platformVersion', but on selenium gird is 'version'.
you set 'deviceName' to 'Nexus 5', but on selenium gird is 'nexus_5_7.1.1'
please change 'platformVersion' to 'version' and correct 'Nexus 5' to 'nexus_5_7.1.1' in your protractor config file, then try again.
My last concern is on your selenium grid the browserName is 'android', I'm not sure testing can open the browser.
In most case, we install Chrome on andriod device and set browserName to 'Chrome' when register device to selenium grid and in protractor config file.
I indeed not know 'andriod' represents which browser, the build-in browser bind with andriod OS?
I am unable to launch the android emulator to run my automation script.
However my automation script works when I launch the android emulator manually from the /Android/sdk/tools directory using emulator -avd Pixel_API_25 -port 5557.
I want to be able to load the android emulator within my automation script.
Please see my env.rb file below.
require 'rubygems'
require 'rspec/expectations'
require 'selenium-webdriver'
require 'pry'
require 'appium_lib'
APP_PATH = '/Users/shafiq.malik/Documents/Projects/nuff-class-booking-
mobile/platforms/ios/build/emulator/HelloCordova.app'
desired_caps = {
caps: {:platformName => "Android",
:platformVersion => "7.1.1",
:deviceName => "Pixel_API_25",
:app => "/Users/shafiq.malik/Documents/Projects/nuff-
class-booking-
mobile/platforms/android/build/outputs/apk/android-
debug.apk",
:appPackage => "com.android.settings",
#:appActivity => ".Settings",
:browserName =>''
}
}
#driver = Appium::Driver.new(desired_caps).start_driver
Appium.promote_appium_methods self.class
def server_url
'http://localhost:8000/wd/hub'
end
Does anyone have any suggestions?
Try adding this to your desired capability . You need avd capability in order to start the emulator.
In java
capabilities.setCapability("avd","AndroidTestDevice");
In case of ruby, Any one of these two.
avd: "AndroidTestDevice",
:avd => "AndroidTestDevice",
Your desired caps should something look like this
desired_caps = {
caps: {:platformName => "Android",
:platformVersion => "7.1.1",
:deviceName => "Pixel_API_25",
:app => "/Users/shafiq.malik/Documents/Projects/nuff-
class-booking-
mobile/platforms/android/build/outputs/apk/android-
debug.apk",
:appPackage => "com.android.settings",
`:avd => "AndroidTestDevice",`
#:appActivity => ".Settings",
:browserName =>''
}
}
On a side note, don't give a root directory as a file path to your application. This might later cause problems if you are using CI's , instead have a generic code where you only indicate, the .apk or .app/.ipa name.
I am trying to use Protractor tests already working nice on PC to hybrid apps thanks to Appium.
As you guess there is a failure that ruin the chain and no way to find help on google.
This problem is quite hard because there is many software engaged so let me list them :
• Gulp (classic server that launch commands)
• Protractor (test language running over webdriver)
• Phonegap (compile website to app ex: .apk)
• Appium (intermediate server that control mobile device)
• Real device (debug-mode: on)
The process is almost working, I mean the apk is well installed, the application start and after 10 sec waiting, instead of starting the test, it crash/ignore the app.
I present here two scenario because I am not sure which configuration is the good one for my setup.
I leave the details under but in short: first case the app.apk is installed but ignored, and in the other apk start but crash (~3sec later)
Here is Gulp start command :
gulp.task('appium', ['webdriver_update'], function (cb) {
return gulp.src(['packages/custom/*/public/tests/e2e/*.spec.js']).pipe(protractor({
configFile: __dirname + '/../protractor.appium.conf.js',
args: ['--baseUrl', 'http://10.56.160.74:3000'] //My Local IP: Website Port
})).on('error', function (e) {
console.log(e);
});
});
Here is my Protractor/Appium config :
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4723/wd/hub',
capabilities: {
fullReset: true,
browserName: 'android',
deviceName: "Galaxy Note S3",
platformName: "Android",
platformVersion: "5.1.1",
app: "C:/Projet/Spherea/appca/packages/custom/appca/public/apk/appca.apk",
'app-package': 'com.spherea.appca',
'app-captivity': 'MainActivity',
autoWebview: true //<= On/Off change the scenario
},
onPrepare: function () {
var wd = require('wd'),
protractor = require('gulp-protractor').protractor,
wdBridge = require('wd-bridge')(protractor, wd);
wdBridge.initFromProtractor(exports.config);
}
};
When autoWebview = true :
The application freeze at start, and after 10 sec of failing starting protractor tests, Appium give up and launch the browser and deal with test there, which is NOT what I need.
Error when autoWebview = false :
[launcher] Running 1 instances of WebDriver
ERROR - Unable to start a WebDriver session.
[launcher] Error: UnknownError: Not yet implemented. Please help us: http://appium.io/get-involved.html
at new bot.Error (C:\Projet\Spherea\appca\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
at Object.bot.response.checkResponse (C:\Projet\Spherea\appca\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:
109:9)
at C:\Projet\Spherea\appca\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:379:20
at [object Object].promise.ControlFlow.runInFrame_ (C:/Projet/Spherea/appca/node_modules/gulp-protractor/node_modules/protractor/node_modules/selenium-webdriver/lib/goog
/../webdriver/promise.js:1857:20)
at [object Object].goog.defineClass.notify (C:/Projet/Spherea/appca/node_modules/gulp-protractor/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webd
river/promise.js:2448:25)
at [object Object].promise.Promise.notify_ (C:/Projet/Spherea/appca/node_modules/gulp-protractor/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webd
river/promise.js:564:12)
at Array.forEach (native)
at [object Object].promise.Promise.notifyAll_ (C:/Projet/Spherea/appca/node_modules/gulp-protractor/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../w
ebdriver/promise.js:553:15)
at goog.async.run.processWorkQueue (C:\Projet\Spherea\appca\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:13
0:15)
at runMicrotasksCallback (node.js:337:7)
[launcher] Process exited with error code 100
I hope someone can help me, I already wasted 10 days trying this and I'm now out of idea to solve this issue.
i have tried the same, conclusion is protractor with jasmine/cucumber has no support for native apps it only supports web automation for desktop & web & hybrid apps automation for mobile.
you can find the responses in below link
https://github.com/angular/protractor/issues/1798
Thanks
I want to execute protractor script on android emulator using Appium, but the problem emulator isn't launched when i tap: " protractor conf.js " on terminal. The test is passed in chrome browser of windows instead of browser in the emulator. Shall i add other capabilities ? or i should change the base url ?
// An example configuration file.
exports.config = {
seleniumAddress: 'http://localhost:4733/wd/hub',
specs: ['todo-spec.js'],
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome',
'device': 'android',
'deviceName' : '5554:AndroidDevice',
device: 'android',
'appium-version': "1.4.16.1",
deviceName : '5554:AndroidDevice',
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
baseUrl: 'http://127.0.0.1:5858',
// Spec patterns are relative to the current working directly when
// protractor is called.
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
//------------------todo-spec.js----------------------------------------
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('https://angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
});
});
Remove the directConnect to allow it to use the selenium server:
// An example configuration file.
exports.config = {
seleniumAddress: 'http://localhost:4733/wd/hub',
specs: ['todo-spec.js'],
directConnect: true, <-- remove this line
...
}
A related topic that should help clearing things up:
Difference running Protractor with/without Selenium?