Run multiple tests on single device one after the other

Hi,

I am trying to execute 2 tests on same Android device:
1)Calculators test on real device
2)Web Application on a real device

It executes first test perfectly, but when i am expecting that web application would be started once the calculator app is tested, I am getting error saying A new session could not be started and also says that a session already exists.

In my calculator test i have added driver.quit() in the @AfterMethod which closes the current session.

But the second test case which launches the webapplication i have re-initialized the AppiumDriver in @BeforeMethod. During this the tests are failing.

I am trying to use Appium with testng. All my tests are defined in Testng.xml and i have declared the tests not to riun in parallel.

Please suggest what needs to be done so that the tests start to execute one after the other on a same device.

Thanks and regards,
M.Karthik

I am not sure whether this will work or not … but you can try starting your appium server with ‘session-override’ flag.

Again, not sure whether this will work or not.

Hi Pratyush,

I tried the above approach by setting the override-session. It Did not work. :frowning:

Is there any other approach to run test sequentially on a same device?

Thanks and regards,
M.Karthik

I can’t think of anything else as I never encountered such issue. Can you post the exact logs of the failure so that others can also have a look at the issue?

My bad i had specified wrong port. It worked after changin the setting to override session.
Thank you Pratyush :smile:

regards,M.Karthik

Ahh! No problem! Cheers!

Try to run the testcases using testng framework.
if you are using testng framework, You can able to run the testcases one by one or parallel execution too without getting the session issues.

Test Automation

Hi Karthik,

I am new to appium. I would like to start Appium Run two apps one after the other in single sessions. Seems from above, you had some exp on it. It would be great if you can assist me with Which will be great help some sample code.

Hi Karthik,

@karthik_holla

I am new to appium. I would like to start Appium Run two apps one after
the other in single sessions. Seems from above, you had some exp on it.
It would be great if you can assist me with Which will be great help
some sample code.

@siva_sankar_s

I am new to appium. I would like to start Appium Run two apps one after
the other in single sessions. Seems from above, you had some exp on it.
It would be great if you can assist me with Which will be great help
some sample code.

Watch my videos. May be it will help you


1 Like

@Srikanth_Katakam: Thanks for the Videos but I have already done basic setup but for my project I need help with "How to launch Two apps one after the other in same session or even one after the other app should be fine.

Please let me know how to do it.

@yeruva7:- Please start you appium session with –session-override flag

node appium.js -a localhost -p 4568 --udid 10.0.0.4:5555 -bp 5557 --nodeconfig C:/json/nodeconfig_serial1.json –session-override
Create two classes with different app capability and test cases
Like
facebook.class
Define-
@BeforeMethod
facebook app capability
@Test
facebook test cases
Calculator.class
@BeforeMethod
calculator app capability
@Test
calculator test cases
Create testNG.xml like below
testng.txt (363 Bytes)
I hope it will work.

Can someone provide me code on how to override session with step by step.

Thanks in advance

@Jawlitkp :- session override is a flag, So you can set the flag while starting the appium server

  1. Open command prompt and Navigate to appium.js location
  2. node appium.js –session-override

Hi Karthik,

I want to open two chrome browser instances parallel in real android device using appium. i have started two appium servers with two ports, but when i tried to start second session, first one is killing. Please help me on running two appium sessions parallel

Hi @Krishna_Murthy,

Can you post the sample code And the log information…will be able to get more information from that

Thanks and regards,
Karthik

You might to use Selenium Grid for this.

http://www.tutorialspoint.com/selenium/selenium_grids.htm

This might help you.

Hi Karthik,

I am using two android devices to test chrome broswer parallel, but if i open second instance of chromein the second device first instance is killing, though i am starting two different appium servers on two different ports.

command to start appium servers:
appium -p 4724 -bp 4726 -U EGxxxxxxxxx
appium -p 4723 -bp 4725 -U EGxxxxxxxxx

code: ( using ruby)
driver initilization:

def setup_appium_for_ne_on_android
Capybara.app_host = ‘https:/abcd.com’
Capybara.server_port = 3001
Capybara.always_include_port = false

Capybara.default_selector = :css

Capybara.default_wait_time = 20
register_appium_android
Capybara.default_driver = :chrome
end

def register_appium_android
Capybara.register_driver(:chrome) do |app|
appium_lib_options = {
server_url: “http://127.0.0.1:4723/wd/hub
}
all_options = {
appium_lib: appium_lib_options,
caps: desired_caps_android
}
Appium::Capybara::Driver.new(app, all_options)
end
end

def desired_caps_android
{
platformName: ‘android’,
platformVersion: ‘4.4.2’,
deviceName: ‘Android’,
browserName: ‘Chrome’,
appActivity: ‘com.google.android.apps.chrome.Main’,
appPackage: ‘com.android.chrome’,
}
end

Could you help me on how to switch between the sessions without killing the previous session.

Appium server1 log:
info: [debug] Proxied response received with status 200: {“sessionId”:“9990a8335794fedfb1dbbe4bb0a32213”,“status”:0,“value”:[{“ELEMENT”:“0.01748935179784894-3”}]}
info: <-- POST /wd/hub/session/9990a8335794fedfb1dbbe4bb0a32213/elements 200 82.021 ms - 105
info: --> GET /wd/hub/session/9990a8335794fedfb1dbbe4bb0a32213/element/0.01748935179784894-3/displayed {}
info: [debug] Proxying command to 127.0.0.1:9515
info: [debug] Making http request with opts: {“url”:“http://127.0.0.1:9515/wd/hub/session/9990a8335794fedfb1dbbe4bb0a32213/element/0.01748935179784894-3/displayed",“method”:"GET”}
info: [debug] Proxied response received with status 200: “{“sessionId”:“9990a8335794fedfb1dbbe4bb0a32213”,“status”:0,“value”:true}”
info: <-- GET /wd/hub/session/9990a8335794fedfb1dbbe4bb0a32213/element/0.01748935179784894-3/displayed 200 90.443 ms - 72
info: --> DELETE /wd/hub/session/9990a8335794fedfb1dbbe4bb0a32213 {}
info: Shutting down appium session
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“shutdown”}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {“value”:“OK, shutting down”,“status”:0}
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 99.774
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] Sent shutdown command, waiting for UiAutomator to stop…
info: [debug] UiAutomator shut down normally
info: [debug] Killing chromedriver
info: [debug] Chromedriver exited with code null
info: [debug] (killed by signal SIGTERM)
info: [debug] executing cmd: /home/jitendra/Softwares/android-sdk-linux_x86/platform-tools/adb -s EGxxxxxxxxx shell “am force-stop com.android.chrome”
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {“status”:0,“value”:null,“sessionId”:“9990a8335794fedfb1dbbe4bb0a32213”}
info: <-- DELETE /wd/hub/session/9990a8335794fedfb1dbbe4bb0a32213 200 526.796 ms - 72 {“status”:0,“value”:null,“sessionId”:“9990a8335794fedfb1dbbe4bb0a32213”}

Appium server2 log:
info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
info: Appium REST http interface listener started on 0.0.0.0:4724
info: [debug] Non-default server args: {“udid”:“EGxxxxxxxxxxx”,“port”:4724,“bootstrapPort”:4726}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {“desiredCapabilities”:{“platformName”:“android”,“platformVersion”:“4.4.2”,“deviceName”:“Android”,“browserName”:“Chrome”,“appActivity”:“com.google.android.apps.chrome.Main”,“appPackage”:“com.android.chrome”}}
info: Client User-Agent string: Ruby
info: Set mode: Proxying straight through to Chromedriver
info: [debug] Looks like we want chrome on android
info: [debug] Creating new appium session 76caa26e-6706-4b81-87db-c06a2b73c4cc
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Not checking whether app is present since we are assuming it’s already on the device
info: [debug] Checking whether adb is present
info: [debug] Using adb from /home/android-sdk-linux_x86/platform-tools/adb
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices…

Hello Krishna,

Greetings!!

I am new to appium- Mobile Automation, trying to make a simple mobile browser automation demo. My goal is to use appium with capybara along with Ruby, so that the appium inherits all capybara DSL. Please can you help me with any sample code, so that it can help me with start up. It will be a great help.

Thanks.