How to not close the iOS simulator after each test case?

2,851 views
Skip to first unread message

Fábio Maia

unread,
Feb 7, 2014, 4:16:03 PM2/7/14
to appium-...@googlegroups.com
Hi appium users,

I stared a project in iOS this week and I've been configuring appium to be used for our tests.

Everything seems to be right. I'm able to run the test cases without any problem either in a real device or simulator.

I noticed that appium closes the simulator between test cases but I'm wondering if there is a way to only close the app (without closing the simulator) and open it again for the next test case.

That is the code snippet after using for the setup and tear down methods in my test superclass:

Ruby code

require 'test/unit'
require 'appium_lib'

class BaseTestCase < Test::Unit::TestCase
  def setup
    app = { device: "iPhone Simulator", app_path: '<MY_APP_PATH>' }
    @selenium_driver = Appium::Driver.new(app).start_driver    
  end

  def teardown
    $driver.driver_quit
  end
end

I looked the method of @selenium_driver object and the global $drive object and I found out for the @selenium_driver there is a "close()" method. The method closes the app without closing the simulator but I have no idea which method should I use to open the application for the following test case.

Also, when by calling Appium::Driver.new(app).start_driver always closes the simulator.

The idea behind not closing the simulator is to avoid extra time overhead that exists to open the simulator for every test case.

I appreciate any kind of help.

Regards,

Fabio Maia.

bootstrap online

unread,
Feb 7, 2014, 4:18:51 PM2/7/14
to Fábio Maia, appium-...@googlegroups.com
You can run multiple tests within a single session.
> --
> http://appium.io
> ---
> You received this message because you are subscribed to the Google Groups
> "Appium-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to appium-discus...@googlegroups.com.
> Visit this group at http://groups.google.com/group/appium-discuss.
> For more options, visit https://groups.google.com/groups/opt_out.

Fábio Rodrigo

unread,
Feb 7, 2014, 4:47:40 PM2/7/14
to bootstrap online, appium-...@googlegroups.com

I did not find anything on appium documentation about that. Could you please give an example?

Thanks.

bootstrap online

unread,
Feb 7, 2014, 4:54:28 PM2/7/14
to Fábio Rodrigo, appium-...@googlegroups.com
Here's an example:
https://github.com/appium/ruby_lib_ios/blob/master/lib/ios/specs/ios/element/generic.rb

All those tests run within one session (Appium::Driver.new / driver.quit)

Fábio Rodrigo

unread,
Feb 7, 2014, 7:16:29 PM2/7/14
to bootstrap online, appium-...@googlegroups.com
This is something that does not fit too me.

All the specs I've looked in that link are just simple test cases. What the generic.rb does is reseting the application to the original state before running each test:

before_first do    
    wait { mobile :flick, endX: 0.5, endY: 0.9 } # scroll up
    sleep 1
  end


So before each test, the app scrolls up which means the application was "restored to its original state" and it's ready to run the next test. Since they are just running simple specs it's not needed to call start_driver/$driver.quit in each test since it's each to restore their app to its original state.

What I'm looking for is something different. I'd like to close the application (kill it) in the simulator without closing the simulator and reopen my application in the next test case.

Is it possible at all or I'm justing thinking about something appium was not designed to do?
--
Att.


Fábio Rodrigo Moura Maia

Jonathan Lipps

unread,
Feb 7, 2014, 7:38:34 PM2/7/14
to Fábio Rodrigo, bootstrap online, appium-...@googlegroups.com
Did you try running with --no-reset?

Fábio Rodrigo

unread,
Feb 7, 2014, 7:52:19 PM2/7/14
to Jonathan Lipps, bootstrap online, appium-...@googlegroups.com
Yes,

I tried that but it didn't work.

Just for the record. I'm starting appium server using the command:

node $APPIUM_HOME/bin/appium --launch-timeout 20000 --pre-launch --app "<MY_APP_PATH>.app" --no-reset

That is the code that runs before and after each test case:

class BaseTestCase < Test::Unit::TestCase
  def setup
    app = { device: "iPhone Simulator", app_path: '<MY_APP_PATH>' }
    @selenium_driver = Appium::Driver.new(app).start_driver    
  end

  def teardown
    $driver.driver_quit
  end
end

I tested with these simulators:

Xcode 4.6 / iPhone (3.5-inch)
Xcode 5 / iPhone Retina (4-inch)

I'm using sudo xcode-select -switch two switch between Xcode versions


bootstrap online

unread,
Feb 7, 2014, 9:53:17 PM2/7/14
to Fábio Rodrigo, Jonathan Lipps, appium-...@googlegroups.com
If you post the appium server logs that may help debug the issue.

Fábio Rodrigo

unread,
Feb 7, 2014, 10:00:30 PM2/7/14
to bootstrap online, Jonathan Lipps, appium-...@googlegroups.com
Is the log the messages printed out on console? If so, It's attached below
appium.log

bootstrap online

unread,
Feb 7, 2014, 10:07:53 PM2/7/14
to Fábio Rodrigo, Jonathan Lipps, appium-...@googlegroups.com
IOS.prototype.endSimulator is running as part of prelaunch mode. Based
on that, I don't think there's a way to keep an iOS simulator open
across sessions.

Fábio Rodrigo

unread,
Feb 8, 2014, 1:05:19 PM2/8/14
to bootstrap online, Jonathan Lipps, appium-...@googlegroups.com
Thanks for the clarification.

Is this something that was designed to be like that or do you think it's possible to be changed?

In my opinion a test suite would run faster if the simulator does not close across sessions, right?

Dan Doveralba

unread,
Feb 8, 2014, 2:39:23 PM2/8/14
to Fábio Rodrigo, bootstrap online, Jonathan Lipps, appium-...@googlegroups.com
If I understand the request correctly, "close the app between tests but not the simulator", that’s not possible with Appium because closing the app isn’t something you can do with UIAutomation, right?

—no-reset still closes this sim and restarts, it just doesn’t blow away the folders, so the app starts in the previous state.

If you can parallelize your tests, this won’t be an issue for you.

Fábio Rodrigo

unread,
Feb 8, 2014, 3:04:17 PM2/8/14
to Dan Doveralba, bootstrap online, Jonathan Lipps, appium-...@googlegroups.com
Thanks Dan,

I did not image this is a limitation of UIAutomation. I asked that question because a friend of mine works in a android project and he uses calabash for automation. He told me calabash does not close the simulator between tests and it just uninstall and install the app between tests without closing the simulator.

Since calabash is cross platform (iOS and android), I supposed it had the same behaviour for iOS too. 

Dan Doveralba

unread,
Feb 8, 2014, 4:56:12 PM2/8/14
to Fábio Rodrigo, bootstrap online, Jonathan Lipps, appium-...@googlegroups.com
Ah…on Android ADB is used in place of Instruments AFAIK, so it’s a totally different beast. 

bootstrap online

unread,
Feb 9, 2014, 8:39:58 AM2/9/14
to Fábio Rodrigo, Dan Doveralba, Jonathan Lipps, appium-...@googlegroups.com
On Android, appium will leave the emulator open. For iOS, the
simulator starts almost instantly. instruments is unable to reinstall
the app reliably without restarting the simulator.

Fábio Rodrigo

unread,
Feb 9, 2014, 9:23:50 AM2/9/14
to bootstrap online, Dan Doveralba, Jonathan Lipps, appium-...@googlegroups.com
Thanks for the clarification Matt and everybody on this thread for the help.

I hope to get onboard on appium and I want to contribute to the project somehow.
Reply all
Reply to author
Forward
0 new messages