5

I am automating some tests a real device (iOS) using Appium and Cucumber. My idea is to do the following steps:

  • Open the app
  • Do some tasks
  • Launch Safari
  • Navigate to a website, lets say google.com for example

My approach is the following:

  • I create the Driver with my app capabilities
  • Do what I need
  • Clear the Driver
  • Create a new driver with Safari capabilities
  • Navigate to www.google.com

The code looks something like this:

Appium::Driver.new(app_capabilities, true)
# do what I need on the app
driver.driver_quit

Appium::Driver.new(browser_capabilities, true)
# do what I need on the browser
driver.driver_quit

The problem I am having is that Safari doesn't launch. Although if I use only one Driver with the browser capabilities it does launch.

Anyone has any idea this is happening? Or maybe a better strategy?

I'm writing ruby but I don't mind code in other languages.

2

2 Answers 2

0

Based on the code you've provided, it looks like you're trying to create two separate drivers for the app and Safari. However, it seems that only the first driver for the app is created and quitting it will close the app as well as the session. So when you're creating a new driver for Safari, it's not able to launch the browser because the session has been closed.

One possible solution would be to keep the same driver instance throughout the test and switch the contexts between the app and Safari. You can use the switch_to.context method to switch between the contexts.

# Create the driver for the app
driver = Appium::Driver.new(app_capabilities, true)

# Do what you need on the app
# ...

# Switch to the Safari context
driver.switch_to.context("Safari")

# Do what you need on Safari
# ...

# Switch back to the app context
driver.switch_to.context("app")

# Do more tasks on app
# ...

# Once all tasks are done, quit the driver
driver.driver_quit

It's worth noting that the switch_to.context method may not work on all platforms, it's only available on iOS and Android devices with webviews.

-1

You can just get chrome to run as if it's on the iPhone , this is easier than driving the browser on the phone. http://sites.google.com/a/chromium.org/chromedriver/mobile-emulation

This might not be suitable for everything but it's fine for reasonably simple usages and works for other devices not just iPhones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.