Testing Your Site with Mac OS, iOS, and Android

Scouting with iOS Here at Sauce Labs, we're always looking forward to the next big thing in testing. That's why we're proud to announce support for Mac OS X, iOS, and Android! If you're a developer and designing websites for mobile devices, it is increasingly important to test those sites on a mobile device. Now, you can run tests on iOS and Android in Sauce's automated and manual testing tools. To get started running tests on OS X, just modify the tests you already have. Our cloud supports the most common browsers, so running tests in OS X is as easy as changing your Selenium 1 browser object or Selenium 2 desired capabilities to use OS X. Here's a simple example for Selenium 1:

from selenium import selenium
import unittest

class sauce(unittest.TestCase):
    def setUp(self):
        self.browser = selenium(
            'ondemand.saucelabs.com',
            80,
            """{"username": USERNAME,
                "access-key": ACCESS_KEY,
                "os": "Mac 10.6",
                "browser": "firefox",
                "browser-version": "3.6",
                "name": "Testing Selenium 1 in Python at Sauce"
               }""",
            'http://saucelabs.com')
        self.browser.start()

    def test_sauce(self):
        browser = self.browser
        browser.open("/test/guinea-pig")

And here's an example using WebDriver:

import unittest
from selenium import webdriver

class Selenium2OnSauce(unittest.TestCase):

    def setUp(self):
        desired_capabilities = webdriver.DesiredCapabilities.FIREFOX
        desired_capabilities['browser'] = 'firefox'
        desired_capabilities['version'] = '8'
        desired_capabilities['platform'] = 'Mac 10.6'
        desired_capabilities['name'] = 'Testing Selenium 2 in Python at Sauce'

        self.driver = webdriver.Remote(
            desired_capabilities=desired_capabilities,
            command_executor="http://USERNAME:ACCESS_KEY@ondemand.saucelabs.com:80/wd/hub"
        )

    def test_sauce(self):
        self.driver.get('http://saucelabs.com/test/guinea-pig')

 Using OS X in our manual testing tool is as easy as selecting 'Mac OS' and your preferred browser.

Mobile Testing in Sauce

Android Job in OnDemandThe most exciting feature we are launching is support for iOS and Android in our cloud. Using iOS and Android in our manual testing tool follows the same process as any other browser, so let's focus on running automated tests in iOS and Android. Before running tests in the iOS simulator or Android emulator, make sure you are using Selenium WebDriver for your Selenium testing. Running tests on iOS is almost the same as any other browser, with two caveats. First, the iOS simulator runs inside OS X so you'll need to make sure to specify 'Mac 10.6' as the platform. Secondly, you will need to select an orientation for tests to run in (portrait or landscape). We support both iPhone and iPad. Here's an example for iOS:

import unittest
from selenium import webdriver

class Selenium2OnSauce(unittest.TestCase):

    def setUp(self):
        desired_capabilities = webdriver.DesiredCapabilities.IPHONE
        desired_capabilities['browser'] = 'iphone'
        desired_capabilities['version'] = '4.3'
        desired_capabilities['platform'] = 'Mac 10.6'
        desired_capabilities['name'] = 'Testing Selenium 2 on iOS!'
        desired_capabilities['deviceOrientation'] = 'portrait'

        self.driver = webdriver.Remote(
            desired_capabilities=desired_capabilities,
            command_executor="http://USERNAME:ACCESS_KEY@ondemand.saucelabs.com:80/wd/hub"
        )

    def test_sauce(self):
        self.driver.get('http://www.saucelabs.com/')

That's all there is to it! If you'd rather run your tests on ipad, just switch out iphone and ipad like so:

desired_capabilities = webdriver.DesiredCapabilities.IPAD
desired_capabilities['browser'] = 'ipad'

And you can run tests with landscape devices too! Just use the 'deviceOrientation' capability:

desired_capabilities['deviceOrientation'] = 'landscape'

So what about Android? The process is very similar to iOS, except the 'platform' should be 'linux' instead of 'Mac 10.6'; of course you'll use 'android' instead of 'iphone' or 'ipad' where appropriate:

desired_capabilities = webdriver.DesiredCapabilities.ANDROID
desired_capabilities['browser'] = 'android'
desired_capabilities['version'] = '4'
desired_capabilities['platform'] = 'linux'
desired_capabilities['name'] = 'Testing Selenium 2 on Android!'
desired_capabilities['deviceOrientation'] = 'portrait'

Android uses a special capability called 'deviceType'. You can set it to 'phone' or 'tablet' like so:

desired_capabilities['deviceType'] = 'tablet'

That's it! If you've followed along to this point, congratulations, you've run your first tests on Android, iOS and Mac in the Sauce cloud! If you want to see iOS and Android in action, check out our screencast.

Happy Testing!

Written by

Adam Christian

Topics

Mobile testing