This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
21 / 28
Apr 2018

Hi there,

are there any examples (preferably for a node js client) to create event listeners within a Appium Test?

I would like to listen for certain events might happen in a running App but have no idea where to start here.

best regards

Second question with no reply. Seems like a great support forum here :slight_smile: Are there better places to maybe reach more Appium developers while looking for help?

best regards.

@Aleksel

thanks but is this only possible to a Java Client? What about JavaScript?

Also is it possible with one Appium Test to process multiple operations on one device at the same time / parallel ?

Lets say i want to automate the following:

  1. Listen for incoming messages inside the app.
  2. Sending a message inside the app.

I have no idea how something like this would most likely be realized in the Appium Universe :slight_smile:

Appreciate any further help

No idea about javascript. Never used. Open Appium github and look for JavaScript-Client.

Regarding listners. You are talking about some your app. Appium does not care how messagers working inside any private app. All you can do is send some event to device in a way your accept. To move further and start from something - did you manage to send such events to your app manually first? I believe it is also a platform specific e.g. in Android one way in iOS should be another one.

@Aleskel.

No because i could not find how to listen for events for a JS Client…

The main application is based on Node JS. I need Appium because the App doesn’t provide any API and i need to create REST API endpoints for the following

  1. GET - Fetching incoming messages retrieved in the App.
  2. PUT - Send messages through the app.

In any case you will be able to listen with Appium ONLY system OS events! Not your app.

Your app should provide api interface how to listen it events and get e.g. count of unread messages. Using this api you first must be able to make it manually using any method. E.g. send. Http get request to url and port that listen your app.

The app does not provide any API. And its not my own app.

The question is how to automatically listen with Appium for a specific action (like an incoming message to the app) and trigger some action like saving the body of the message or what ever.

So basically the Appium “Test” Script should be sit and wait, do nothing until a message comes in to the app, then catch up on this “event” and do something with the message arrived.

So I am not sure what you mean by “manually”?

What means message coming to your app? Is it Push notification or?

I talk about WhatsApp.

I want to realize something like a chat bot but instead of replying to the incoming message the code should save all phone numbers from incoming messages to contacts for e.g

you can not listen private app events like push. only owner of app has access to it.

it is NOT native android app BUT web version :slight_smile: with web you can do much more.

your example does not listen for anything BUT just in loop looking for appearing some web elements and read them.

Yes. Thats actually what i mean. And the same functionlity can be done within a Appium JavaScript Client? Just with the difference instead of just replying the message i want to save the phone numbers of the messages received and add them to the contact list.

@lddd you can. but i can not help you with Appium JavaScript. never used it as client for appium.

Ok thanks a lot.

I am very new to both Java and JavaScript :blush:

Now 2 more questions:

  1. Lets say it´s a Java Client. How to keep such Test running in the background so it´s continuously waiting for new messages and do something with the results? I would have to execute such Client Script every second by cronjob or how is this be done?

  2. Would it be possible to do other actions in the same Appium Test like sending a message? What if both actions would happen to the same time? I guess its not possible for Appium to parallel execute two functions on the same App window running only 1 Test for the same device?

thanks for all the kind help so far. Very nice.

Do you need really do it with phone browser but not with normal on PC?

Sorry? Don´t understand what you mean by normal on PC?

I want to run my “tests” on a headless linux server environment.

but you going to connect device/emulator to some PC anyway

Yes sure Android emulated device, but whats your point?

ok. at least now we have details. i suggest use 2 driver strategy. one driver opens web (no matter on computer or on some emulated device) and looking for messages. another driver does another job with another device/web (depending what exactly you need). i made test like a chat - when 2 apps open on different devices and one sending something, another one respond.

Hey Aleksel.

One automation test for each task sounds like a good idea. 1 for reading messages, 1 for sending messages.

I think browser automation for my case is not possible because on WhatsApp (web.whatsapp.com) you cannot add new contacts. And i want to automatically save phone numbers for all incoming messages containing a specific keyword

For example: A person sends “subscribe”

Now i want to have one Appium Test running in the background of my server doing this. It should permanently scan all incoming messages on the emulated device and add numbers to the contact list.

no test is ONE. in one test open first driver to device 1. and second driver to device 2. and start you steps with checks. but is all depends on your needs. maybe as you said background scan is fine for you.

I think you cannot run the same app with same SIM number on 2 devices at the same time.

I think i know what to do now (at least in theory) i will try some things within the next days and let you know if i have further questions.

thanks for your kind help so far.