Appium ios automation nodejs scripts - ios

I am trying to automate an iOS native app on a real device using Appium(from terminal) and nodejs script. I am able to install and launch the app till the first screen of the app but after that no nodejs scripts other than sleep is getting executed. I need to type in some text in the the textfields present in the screen but the cursor is getting pointed and nothing happens after that. Please tell me whether I am using the correct nodejs commands here.
NB:The same nodejs script was working fine for android automation
var wd = require("wd");
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var capture = require("capture");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var host, port, username, accessKey, desired;
console.log("Print 1");
var desired = {
'browserName': '',
'automationName': 'Appium',
'platformName': 'iOS',
'platformVersion': '6.1.4',
'deviceType':'iPhone',
'deviceName' :'xxx’s iPhone',
// 'nativeInstrumentsLib' : 'true',
'app': "/Users/Desktop/xxx_my_appname-358.ipa",
'bundleId': 'com.xxx.myapp',
'deviceOrientation': 'portrait'
};
host = "localhost";
port = 4723;
// Instantiate a new browser session
var browser = wd.promiseChainRemote(host, port, username, accessKey);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
// Run the test
browser.init(desired)
// then(function () {
browser
// yield.elementByName("userNameTextField").click()
.sleep(30000) // **** WORKING FINE**
.elementByName('User Id').type('userID') // ** NOT WORKING **
.elementByName('Next').click() // ** NOT WORKING **
.elementByName('Password').type('password') // ** NOT WORKING *
.sleep(30000) // **** WORKING FINE**
.fin(function () {
return browser
.sleep(30000)
.quit()
console.log("inside click");
// });
})
.catch(function (err) {
console.log(err);
console.log("Entering into error Catch...")
throw err;
})
.done();

Try using the Appium app inspector to get the xpath of the elements:
.elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]").sendKeys("userID")
.elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]").sendKeys("password")

Related

Ionic - Some functionnalities are not working while compiling on IOS

Context:
Hello, I am working on a Ionic application (made in Typescript). In this application, I control a wifi camera via HTTP Request to the IP (http://192.72.1.1/myCommand to be precise).
Main actions I do with the camera:
Start recording
Stop recording
Get videos list
Download a video
When I use the Ionic DevApp:
With the Ionic DevApp, everything works perfectly, I can do all mains actions without a problem.
When I compile the application on IOS:
I compile with the command ionic cordova build ios --prod, then I archive with Xcode and send it to the AppStore to test it with Test Flight.
I got no errors while compiling / archive the application. But when I try it on my iPhone, I can start / stop recording, but can't download the video.
Problem:
Some commands are not working, but I don't know if it is getting the list or downloading the video, I have no logs. I don't understand why some commands are working but others no.
IOS is blocking download requests? How to solve my problem?
Notes:
I already tried all basic things like delete the IOS platform, recompile, uninstall, ...
I tried different Ionic HTTP plugins, same problem with all of them.
Some code:
Start / Stop the camera: (it is the same command to start / stop).
startCamera(){
var url = "http://192.72.1.1/changeRecordStatus";
var result = this.http.get(url);
result.subscribe(data => {
console.log("Works");
},
err => {
console.log("Error" + err);
}
);
}
Getting the name of the last video:
getLastVideo(){
var url = "http://192.72.1.1/listVideos";
this.http.get(url, {}, {})
.then(data => {
var xml = data.data
var xmlDOM = new DOMParser().parseFromString(xml, 'text/xml');
var temp = this.xmlToJson(xmlDOM); // function that convert XML to JSON
var resultArray = Object.keys(temp).map(function(i){
let ite = temp[i];
return ite;
});
resultArray = resultArray[0]['file'].reverse();
this.lastVideo = resultArray[0]['name']; // lastVideo is a global variable
},
(error) =>{
console.log("Error while getting the name of the last video" + error);
});
}
Downloading the file from the camera:
downloadFileFromCamera() {
this.getLastVideo();
var basename_file = this.lastVideo;
var url = "http://192.72.1.1" + basename_file;
this.fileTransfer.download(encodeURI(url), this.file.dataDirectory + '/videos/' + basename_file, true).then((entry) => {
this.video[this.counterVideos] = entry; // video is a global array
this.counterVideos +=1;
}, (error) => {
console.log("Error while downloading the last video" + error);
});
}
If someone knows how to solve my problem, I would be so grateful! Thanks in advance.

"Error: no such session" Webdriver-IO, Appium

I have setup Cucumber, Webdriver-IO, and Appium. Everything appears to be talking to each other, however I'm getting Error: no such session when trying to navigate to http://google.com.
On the Android device it opens up the Chrome browser, then closes it really fast.
webdriverio.js
//webdriverio.js
let client = WebDriverIO.remote({
desiredCapabilities: {
platformName: 'Android',
browserName: 'chrome',
deviceName: 'test',
},
host: 'localhost',
port: 4723,
waitForTimeout: 120 * 1000,
});
global.client = client;
module.exports = function() {
this.registerHandler('BeforeFeatures', function(event, done) {
client.init().call(done);
});
this.registerHandler('AfterFeatures', function(event, done) {
client.end().call(done);
});
};
env.js
// env.js
module.exports = function() {
// added because default 50000 ms was long enough
this.setDefaultTimeout(60 * 1000);
};
search_steps.js
// search_steps.js
module.exports = function() {
this.Given('I have visited Google', function (done) {
client
.url('http://google.com')
.call(done);
});
this.When('I search for {arg1:stringInDoubleQuotes}', function (arg1, done) {
// Write code here that turns the phrase above into concrete actions
client
.setValue('input[name="q"]', 'Kittens')
.call(done);
});
this.Then('I see {arg1:stringInDoubleQuotes}', function (arg1, done) {
// Write code here that turns the phrase above into concrete actions
client
.getValue('input[name="q"]').then(function(text){
expect('Kittens').to.eql(text);
})
.call(done);
});
};
The issue is chromedriver 2.21.371459 that is shipped with my version of Appium (1.3.5) for Mac. I downloaded the latest version of chromedriver and overwritten the existing one that is shipped with Appium. See the answer here Chrome opens for a second and the crashes for windows. For mac the location of the chromedriver exec shipped with Appium is. /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac

React-Native Websocket Event data property is missing

I am trying to connect to the Watson TTS API over a Websocket connection in React-Native. The connection is established and I can send a message to the server, however the data that I get back from the server somehow always is empty.
It seems as if the event.data property is completely missing. If I log it to the console in react-native I get 'undefined' as a result. If i use the same code in the browser everything works perfectly.
I am using react-native 0.33 and here's my code:
function connectTTS(token) {
var voice = "de-DE_BirgitVoice";
var format = 'audio/basic';
var token = token;
var wsURI = "wss://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=" + voice + "&watson-token=" + token;
function onOpen(evt) {
var message = {
text: "Hello world.",
accept: format
};
// note: the Text to Speech service currently only accepts a single message per WebSocket connection
websocket.send(JSON.stringify(message));
}
var audioParts = [];
var finalAudio;
function onMessage(evt) {
console.log(evt.data);
if (typeof evt.data === 'string') {
console.log('Received string message: ', evt.data)
} else {
console.log('Received ' + evt.data.size + ' binary bytes', evt.data.type);
audioParts.push(evt.data);
}
}
function onClose(evt) {
console.log('WebSocket closed', evt.code, evt.reason);
console.log(audioParts);
console.log(format);
finalAudio = new Blob(audioParts, {type: format});
console.log('final audio: ', finalAudio);
}
function onError(evt) {
console.log('WebSocket error', evt);
}
var websocket = new WebSocket(wsURI);
websocket.onopen = onOpen;
websocket.onclose = onClose;
websocket.onmessage = onMessage;
websocket.onerror = onError;
}
It would be great if somebody with more react-native / websocket experience could help me find the solution. Thanks.
In react-native up to 0.53 (latest version at the moment), react-native WebSocket event processing relies on event-target-shim 1.1.1 lib which wraps an event and does not include data to the wrapped event, so in order to get WebSocket event data you may use one of two approaches:
Get data from __proto__;
Rewrite event-target-shim 1.1.1;
The first approach:
use <your event>.__proto__.__proto__.data
The second approach:
fork event-target-shim and reset to event-target-shim 1.1.1;
fork react-native;
Add the code listed below to the event-target-shim/lib/event-wrapper.js;
rewrite react-native package.json to use forked version of the event-target-shim;
rewrite package.json of your project;
Code to add in exports.createEventWrapper after var propertyDefinition = {...}:
if (event.type === "message"){
propertyDefinition.data = {value: event.data, enumerable: true};
}

A signalr function is not working in firefox

I want to redirect on a specific page after file download in MVC. And in my application signalr is already configured. So I used following code in controller
var hubContext = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
hubContext.Clients.All.RedirectToBatch(BatchID, Convert.ToInt32(Session["AgencyUserID"]));
return File(stream, "text/plain", (BatchName + "." + ediExtension));
And in view I used following code
var chat = $.connection.chatHub;
chat.client.redirectToBatch = function (BatchID, AgencyUserID) {
if (currentUserID == AgencyUserID) {
var claimlist = $('#ClaimListGrid');
if (claimlist.length > 0) {
window.location = "/Billing/ClaimSummary/" + BatchID;
}
}
};
$.connection.hub.start().done();
$.connection.hub.disconnected(function () {
setTimeout(function () {
$.connection.hub.start();
}, 5000); // Restart connection after 5 seconds.
});
I think this code will work for redirect to a page after file download. And this works in chrome proper but In firefox this is not working fine.
In firefox following error is occurring
no element found
AND
Firefox can't establish a connection to the server at ws://localhost:2804/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=4p2zZ%2B%2F0ok4B9uAxcslDlTv4kpT%2BGbW2nav6S%2Fe5RlSqQgS2gaFr7%2BlQiIrHZu5cPapvjoeZNB8bXM6AeF%2B1b1RS0P6y%2FETaNeAC5hDQkGrwH5xgDfjDHWt%2B%2B52K7yaD&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&tid=10.
What should I do for this problem?

phonegap app connected to node server by socket.io works on browser but not in app

i setted up a node server, this sends data via socket.io to the clients and use that in a phonegap projekt,
it works fine when i test it in browsers & mobile browsers but it does not work when i build a ios app which i run in the emulator,
part of node server code:
define(['node-static','http'],function (Static,Http) {
return FileServer = function (server) {
var httpFileServer = new Static.Server('./phonegap/www');
Http.createServer(function (request, response) {
request.addListener('end', function () {
httpFileServer.serve(request, response);
}).resume();
}).listen(server.fileServerHTTPport,"0.0.0.0");
return {
// exampleVariable : function() {return exampleVariable},
// exampleFunction : exampleFunction
}
} });
index.html phonegap
... <script src="js/socket.io.js"></script>
<script src="js/jquery-2.0.3.min.js"></script>
<script>
var socket = io.connect('http://'+document.location.hostname+':54321');
socket.on('display', function (data) {
console.log(data.color);
$("h1").text( data.color.h );
});
</script></head>
<body><h1> hello world</h1> ...
I figured out, i have to use the devices default localhost ip,
so for example in ios: 127.0.0.1
var socket = io.connect('http://127.0.0.1:54321');

Resources