appium icon indicating copy to clipboard operation
appium copied to clipboard

Appium Capabilities to run tests of currently open application.

Open qaDream77 opened this issue 11 years ago • 12 comments

So there are capabilities for installing a new application, for launching an already installed application.

I am looking into splitting my infrastructure testing from my actual testing. Meaning, I have a python test script to install or launch the application and check if the application has crashed or is running.

i have a second python script (separate) which i would like to do all of the testing, however, i do not want to relaunch or attempt to reinstall the application. i just want it to proceed to do that test with the currently open application, i went through the documentation and i couldn't figure out if this was doable or not.

Thank you!

qaDream77 avatar Jul 15 '15 21:07 qaDream77

Did you try "Capability noReset" to true + start again the current Activity? With java-client for example :

first script :

capabilities.setCapability("noReset", "true");

second script : could be include in first script then :

driver.startActivity(appPackage, appActivity);

This way (inclusion) you could also use the same driver as you set in your first script (so don't need the startActivity). Though if your driver crashes, it is necessary to create a new one anyway so the app has to be launched again.

With java (JUnit), we have @before to setCapabilities and @test for the tests. The noReset to true will get back the previous state of your app. (app reflated) .

Related to your question, I think it could be nice if appium could detect the currentActivity opened on smartphone -not driver- (the last one, I guess it's not too difficult with adb shell), and get back these infos to automatically set device/package/activity on new session, just to specify the driver url.

This way we could manually go to an activity for a specific case, without launching the entire scenario (for example when we have problem with an element) or look at activity name -driver.CurrentActivity()- then modify appActivity capability according to it and launch an appium test with "auto capabilities" (e.g : desiredCapabilities : "lastOpenedActivity"). Useful too when we have a trouble; to easily go back to the previous state (for debugging).

It would also allow us to manually bypass some appium limitations (example : deep link which permits to open app -> from web context to app context), then execute the appium script to end the scenario (semi-auto).

You want to manage all crash from appium/app in first script then launch the test script in the second one when you are sure all is fine, don't you?

Fanch- avatar Jul 16 '15 08:07 Fanch-

Sorry for the delayed reply, i just got in. To answer your question, that is exactly what i am trying to do. I noticed that both on iOS and Android that the test scripts fails around 10% of the time but those tests aren't actual failures on part of the script. In the emulators case, it crashes when it tries to launch the application. So i am looking to have script 1

Open application, check it's integrity and either allow a downstream job from jenkins to proceed, if it fails. attempt to reopen the failed application a set amount of time, and if it fails at that point. Kill the job.

The second script would run the actual test script for the app and close all current applications.

I am using python and robot framework. My capabilities for the first script are: platformName, platformVersion, deviceName, app, automationName, bundleId waitForAppScript=true locationServicesEnabled=true locationServicesAuthorized=true autoAcceptAlerts=true noReset=true

I am now looking into the python code to see if i there is something similar to driver.startActivity(appPackage, appActivity);

I thought that noReset would not reset the app's state before this session, why would that be in the first script and not the second? If it is a clean install of the app, it's state would be reset regardless from my understanding.

qaDream77 avatar Jul 16 '15 14:07 qaDream77

In the second script, i have to use the bundle ID or it won't recognize that an application is open, however, adding no reset doesn't let me use the currently open instance of it. Instead it closes the current and relaunches the application.

EDIT: it closes the iOS Simulator and relaunches it then launches the application :( I really wanted to do this from 2 separate scripts but it might have to end up being the same script.

EDIT 2: putting them in the same script but as two separate test cases, even with noReset set to true, doesn't work. It will close the application and relaunch for the next test. Is this a bug or intended behavior?

qaDream77 avatar Jul 16 '15 14:07 qaDream77

Yes it is the intended behavior, it just keeps data between relaunching. To do what you want to do smoothly, you have to use the same driver instance between your launcher and test script.

I guess you can do it with the equivalent of a singleton, in @before you call this singleton which sets capabilities and create driver (if it crashes use your code until it works) -and won't do it again if it is set-.

In other @test cases, just use the driver created.

Fanch- avatar Jul 17 '15 08:07 Fanch-

When you say, singleton do you mean a single instance of the driver?

When we establish the driver, we send an http json request to the server with the url and desired capabilities. I've been going through the Selenium WebDriver api and i can't find any function related to retrieving a current list of drivers, only to start a new remote session :(

Sorry if i misunderstood you, but do you know of any way to find the available/active webdrivers, because in my second script, i do not want to set the capabilities, i want it to find an available webdriver and use it.

qaDream77 avatar Jul 17 '15 17:07 qaDream77

We can discuss it on appium chat if you want : https://gitter.im/appium/appium

Fanch- avatar Jul 21 '15 12:07 Fanch-

Great thanks, i'm working on setting up ubuntu system for appium right now but i'll go onto chat in an hour or so. Thanks for the help! =D

qaDream77 avatar Jul 21 '15 17:07 qaDream77

On iOS I don't think it is possible because Appium run a special loop command script which need to be launched at the same time as Instruments. It might be possible with Android as the automation is more Flexible. @moizjv , is it possible to automate an already opened application on Android?

sebv avatar Jul 31 '15 16:07 sebv

Closing due to inactivity

rkavalap avatar Dec 17 '16 22:12 rkavalap

with Android python client works fine with below settings capabilities.setCapability("noReset", "true"); driver.startActivity(appPackage, appActivity);

anand853 avatar Jun 12 '17 21:06 anand853

We can't create two driver instances at the same time, We can create a main class and define instance of the driver and set your capabilities in @before function in @After function, make sure you don't quit the driver instance. you can create multiple test classes and use the same driver instance created in the main class in @Test function. and finally, you can quit your driver in the last class in your test suite. Hope it help :)

DoaaAhmed92 avatar Apr 03 '18 12:04 DoaaAhmed92

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Apr 23 '19 20:04 lock[bot]