Appium/Protractor tests do not run on real device .APK - android

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

Related

Ionic3-Cordova-UWP : Ionic Storage doesn’t work when app is running

I have a problem with Ionic storage in my Ionic App for Windows (UWP app). I already tested and deployed my app for Android without any trouble.
Now I would like to generate an UWP app.
The app I’m developing is a workshop’s dashboard. The indicators change every day and I need to save them from one day to another. To do this I usethe storage module of Ionic.
When launching the command
$ionic serve
the app responds exactly as it should in the web browser (Firefox). From one launch to another my data are still there.
When I use
$ionic cordova run windows
the installation and launch steps of my app work fine. Every function of my app runs fine, but the call to storage (get and set) doesn’t work : when I close, and then reopen it as an autonomous application, I loose all data every time. It is the same when I run the app from Visual Studio.
Moreover, I write some console.log in the result of the promise and none of them is written in the Javascript console. It is like Windows does not recognize the command.
I tried with Visual Studio 2015 Update 3 and Visual Studio 2017, the result is identical. I followed the recommendation of Ionic Doc and add the target platform windows10 in the config.xml.
Does anyone have an idea of what I’m doing wrong ? Is there an incompatibility between Windows and Ionic ?
Thanks for any help.
Config :
Windows 10 64-bits
Ionic CLI: 3.19.1
Cordova CLI : 8.0.0
Node : v6.11.2
Visual Studio Community 2017 (15.5.27130.2036)
Extract of my code maPage.ts :
import { Storage } from '#ionic/storage';
export class maPage {
constructor(public storage: Storage) {
this.downloadData();
}
ionViewWillLeave()
{
this.saveData();
}
TabData = {
id: 0,
label: '',
Tab1: [],
Tab2: [],
attri1 : 0,
attri2: false
}
Param = {
Objet1: {NbObj1: 7},
Objet2: {NbObj2: 5}
}
saveData()
{
var Data: object;
Data =
{
TData: this.TabData,
TParam: this.Param
}
this.storage.set('Data', Data).then(_=> {
console.log('Backup done!');
}, error => {
console.log('erreur : ', JSON.stringify(error))
});
}
downloadData()
{
this.storage.ready().then(()=>{
console.log('storage ready');
this.storage.get('Data').then((val) => {
this.TabData = val.TData;
this.Param = val.TParam;
console.log('Récupération terminée !');
}).catch(erreur => {
console.log('La variable Data est vide ou n\'existe pas!');
console.log('erreur : ', JSON.stringify(erreur));
}).catch(err => {
console.log('storage not ready');
console.log('err : ', JSON.stringify(err));
});
}
}
On Windows platform, console.log is not supported. To do that, you should install cordova-plugin-console, or need to use alert function.
Regarding storage, I am suggesting you could use localstorage or cordova-sqlite-storage.

Debugging Jest unit tests with breakpoints in VS Code with React Native

I created a React Native project using the popular Ignite CLI v2.0.0 with the default boilerplate.
Then I adorned it with a bunch of nodejs shims, because I'll have some node-based dependencies.
Everything is working and I can run the Jest tests from the command line. So far, so good.
However, now one of my unit tests is timing out. This is probably due to an async call failing that invokes a mocked out node function. But there is no information on error, location, etc.
So I want to debug using Visual Studio Code v1.13.1 and here problem starts. I can't for the life of me figure out how to configure this so I can set breakpoints both in the tests as in the app code + node_modules.
I have installed the React Native Tools v0.3.2 and can start the debugger using the default Debug Android configuration:
[vscode-react-native] Finished executing: adb -s emulator-5554 shell am broadcast -a "com.myexample.RELOAD_APP_ACTION" --ez jsproxy true
[vscode-react-native] Starting debugger app worker.
[vscode-react-native] Established a connection with the Proxy (Packager) to the React Native application
[vscode-react-native] Debugger worker loaded runtime on port 13746
Running application "MyApplication" with appParams: {"rootTag":1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
But no breakpoints are hit. VS says: Breakpoint ignored because generated code not found (source map problem?). (btw: both index.android.bundle and index.android.map have just been generated in .vscode/.react).
And also I don't see a way to debug through the test code (which lives in ${projectRoot}/Tests).
Based on much googling I created another debug configuration for running Jest in VS Code:
{
"type": "node",
"request": "launch",
"name": "Jest Tests",
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
"args": [
"--config",
"package.json",
"--runInBand",
"--verbose",
"--no-cache",
"-u"
],
"runtimeArgs": [
"--nolazy"
],
"console": "internalConsole",
"sourceMaps": true,
"address": "localhost",
"port": 8081,
"outFiles": [
"${workspaceRoot}/.vscode/.react"
],
"env": {
"NODE_ENV": "test"
}
}
This at least runs the tests, showing test report in the VS debug console, but once again no breakpoint anywhere gets hit.
I also tried setting outFiles to the location where ignite generates the bundle, i.e. ${workspaceRoot}/android/app/build/intermediates/assets/debug/* with same results.
Can anyone please point me in the right direction?
PS. I am on Ubuntu 16.04:
System
platform linux
arch x64
cpu 4 cores Intel(R) Core(TM) i7-4500U CPU # 1.80GHz
JavaScript
node 8.1.2 /usr/local/bin/node
npm 4.6.1 /usr/local/bin/npm
yarn 0.24.6 /usr/bin/yarn
React Native
react-native-cli 2.0.1
app rn version 0.45.1
Ignite
ignite 2.0.0 /usr/local/bin/ignite
Android
java 1.8.0_111 /usr/bin/java
android home - undefined
Finally found the solution. It seems there are still a number of issues with the new inspector protocol in Node 8.*. In short the support for --inspect is still quite experimental.
For example the NodeJS Inspector Manager (NiM 0.13.8) was crashing and disconnecting websocket after few second (See: NiM Github issue #17 and Chromium bug #734615).
So I downgraded NodeJS 8.1.2 --> 7.10.1
Now finally things work as expected. I can do all debugging in VS code, hit all the breakpoints, with the following debug configuration:
{
"type": "node",
"request": "launch",
"name": "Launch Tests",
"program": "${workspaceRoot}/node_modules/.bin/jest",
"args": [
"--runInBand",
"--no-cache"
],
"runtimeArgs": [
"--debug-brk=127.0.0.1:5858"
],
"port": 5858
}
Wasted more than a day on something that should be a 5 min. no-brainer. But luckily its working now!

Http requests fails only while releasing Android APK

I'm struggling in making my app work on Android APK release, the only scenario it fails is at generating and signing the apk. All http requests doesn't work. (The server is running under SSL)
All Scenarios I've tried already:
ionic serve -> Works fine.
ionic cordova run android --device -> Works fine.
Works on emulators as well.
Also works fine generating the iOS build:
ionic cordova build ios.
On Xcode, running build targeting a real device.
On Xcode, archiving and uploading it to Itunesconnect then downloading it from AppStore once it's accepted by Apple.
So, the only case it doesn't work is when I try to generate it's apk through ionic cordova build android --prod --release and signing it.
Google Play also accepts the new APK, so there's no problem with the package sign at all.
Since it works on iOS and running directly on android device, it isn't a CORS or HTTPS certificate problem.
The code:
snippet of login.ts:
this.userService.loginUser(this.user).then(
(data) => {
let response = data.json();
loading.dismiss().then(loadData => {
if (response.access_token) {
this.global.access_token = response.access_token;
this.getUserData();
}
});
}, err => {
let error = err.json();
loading.dismiss().then(response => {
if (error.message) {
this.showToast(error.message, 3000, 'bottom');
}
});
}
);
userService.loginUser method:
loginUser(data) {
let headers = new Headers();
headers.append('Access-Control-Allow-Origin', '*');
headers.append('auth-token', '*');
return this.abs.post('/authenticateMobile',
{
login_ds_email: data.email,
login_ds_password: data.pass
}, headers);
}
Where abs is:
constructor(http) {
this.abs = new ApiService(http);
}
ApiService.post method:
public post(api, params, header): any {
if (!header) {
header = this.getHeaders();
}
let options = new RequestOptions({headers: header});
let url = this.global.urlGlobal + api;
return this.http.post(url, params, options).toPromise();
}
The App gets stuck when I fire "login" button and the request is made. There's no exception thrown by the server, so the loading screen is shown forever.
I've running out of solutions for this and I hope you guys can help me out.
Ionic info:
global packages:
#ionic/cli-utils : 1.4.0
Cordova CLI : 6.4.0
Gulp CLI : CLI version 3.9.1 Local version 3.9.1
Ionic CLI : 3.4.0
local packages:
#ionic/app-scripts : 1.3.0
#ionic/cli-plugin-cordova : 1.4.0
#ionic/cli-plugin-gulp : 1.0.1
#ionic/cli-plugin-ionic-angular : 1.3.1
Cordova Platforms : android 6.0.0 ios 4.3.1
Ionic Framework : ionic-angular 3.0.1
System:
Node : v7.8.0
OS : macOS Sierra
Xcode : Xcode 8.3.3 Build version 8E3004b
ios-deploy : 1.9.0
ios-sim : 5.0.6
npm : 5.0.3
I had this exact same issue some time ago. In my case the problem was an invalid certificate. The certificate looked fine to me in the browser (chrome even showed the green lock), on iOS and while testing on Android. But I had android-users complain it wasn't working for them.
After hours of researching it turned out that requests to websites with invalid certificates just get silently dropped, which means there is no feedback whatsoever. No errors, nothing. (If I remember correctly, the js code just stopped executing without returning or executing any callbacks.) This happens ONLY when building in release mode.
A workaround is described here:
http://ivancevich.me/articles/ignoring-invalid-ssl-certificates-on-cordova-android-ios/
The best way to handle it would be to pin the certificate in your app.
My issue was incomplete SSL chain, solve it by reconfiguring nginx to have the entire chain of SSL certificates as described here:
http://nginx.org/en/docs/http/configuring_https_servers.html#chains
My problem was with SSL as well. If you get an "A+" rating from this website, it should work. My original grade was "B".
https://www.ssllabs.com/ssltest
You can use this site to correct it.
https://whatsmychaincert.com/

Using Android UIAutomator in Python or Ruby

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

Appium can't find 'appPackage' parameter

I'm trying to run simple RSpec test on real Android device using Appium. My config is:
apk = {
device: :android,
app_path: *path_to_apk*,
app_package: *app_package*,
app_activity: '.Start'
}
Then I'm starting driver by:
Appium::Driver.new(apk).start_driver
Script fails with error:
Selenium::WebDriver::Error::WebDriverError: Parameter 'appActivity' is
required for launching application
I tried to debug by steps and found out, that in Selenium::WebDriver::Remote::Http::Default inside request method script sends post request with path: "/wd/hub/session" and body: {"desiredCapabilities":{"platform":"OS X 10.9","platformName":"android","name":"Ruby Console iOS Appium","device-orientation":"portrait","app":*path_to_apk*}}. The response is HTTPInternalServerError object with body:
"{ "status": 33, "value": {
"message": "A new session could not be created. (Original error: Parameter 'appActivity' is required for launching application)",
"origValue": "Parameter 'appActivity' is required for launching application" }, "sessionId": null }"
I can't understand what's the problem and find any solutions in google. Maybe value of 'app_package' parameter is wrong? So my second question is how can I get it?
P.S. Before all, appium was run in terminal by command appium & and started successfully
How to get app package?
Answer: Open 'Dev Tools' in emulator/device, then go to package browser then select your application , there you will get the app package along with available activities.
What is the problem with your code:
Ensure to include these stuffs:
platformName: 'Android',
appActivity: '.activity_name',
appPackage: 'package_name'

Categories

Resources