Skip to main content

Smart TV testing on BrowserStack App Automate

A guide to running your Appium tests on smart TV devices with BrowserStack App Automate.

Important: BrowserStack currently supports an alpha version of smart TV testing, and thus, it is not available to all users yet. If you want to get access to smart TV testing, contact support and request access to the Smart TV alpha release.

App Automate lets you test your apps on smart TV. We currently support testing apps on:

  • Amazon Fire TV Stick 4K (Android v7.1)
  • Nvidia Shield TV Pro 2019 (Android v11.0)

1. Setup your environment

  • Access to the alpha version of smart TV testing
  • You will need a BrowserStack username and access key. To obtain your access credentials, sign up for a free trial or purchase a plan.
  • Access to a Smart TV app (.apk file) that runs on Fire TV or Nvidia Shield TV pro.

2. Upload your app

Note: If you do not have a .apk file and want to try out a test on Smart TV, you can download and test our sample app.

Upload your app (.apk) file to BrowserStack servers using our REST API request as follows:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@/path/to/apk/file"

# Ensure that `@` symbol is prepended to the file path in the request.
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" ^
-X POST "https://api-cloud.browserstack.com/app-automate/upload" ^
-F "file=@/path/to/apk/file"

# Ensure that `@` symbol is prepended to the file path in the request.

A sample response for the request is as follows:

{
    "app_url":"bs://j3c874f21852ba57957a3fdc33f47514288c4ba4"
}

Note the value of app_url returned in the response to the REST API request. This value will be used later to specify the application under test for your test execution.

Important: App upload might take a few seconds to about a minute depending on the size of your app. Do not interrupt the cURL command until you get the response in your command-line/terminal.

3. Configure and run your test

In this step, you will learn how to configure your Appium test script using desired capabilities to test remotely on BrowserStack’s real device cloud along with a sample test script.

Update your test script with the following changes:

  • Set the app capability to the app_url of the app you uploaded
  • Set device capability to either of the following two options:
    • Amazon Fire TV Stick 4K - run tests on Fire TV
    • Nvidia Shield TV Pro 2019 - run tests on Nvidia Shield TV
  • Initialize an Appium driver using a remote BrowserStack URL along with your BrowserStack credentials as follows:
      https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub
    

Sample test script

The following sample Ruby test script includes device capabilities to run a test on the Fire TV app. If you want to run a test on Nvidia Shield TV Pro, uncomment the capabilities from the test script:

Ruby
require 'rubygems'
require 'appium_lib'

caps = {}
caps['build'] = 'BrowserStack Build'
caps['project'] = 'Example Smart TV Project'
caps['name'] = 'single_test'
caps['platformName'] = 'android'
caps['browserstack.debug'] = true

## set the app ID
caps['app'] = 'bs://<app_id>'

## capability to run test on Fire TV
caps['deviceName'] = 'Amazon Fire TV Stick 4K'
caps['platformVersion'] = '7.1'

## uncomment these capabilities to run test on Nvidia Shield
# caps['deviceName'] = 'Nvidia Shield TV Pro 2019'
# caps['platformVersion'] = '11.0'

## initialize the Appium driver with BrowserStack credentials
appium_driver = Appium::Driver.new({
    'caps' => caps,
    'appium_lib' => {
        :server_url => "http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub"
    }}, true)
driver = appium_driver.start_driver
puts "Appium driver started"
driver.press_keycode(85)
driver.press_keycode(20)
driver.press_keycode(23)
sleep 5
descList = driver.find_elements(:id, "com.example.android.tvleanback:id/description")
puts descList.to_s
sleep 5
if (descList.size > 0)
  puts "Desc found"
end
driver.press_keycode(22)
driver.press_keycode(22)
driver.press_keycode(22)
driver.press_keycode(23)
sleep 5

headerList = driver.find_elements(:id, "com.example.android.tvleanback:id/browse_headers_dock")
if (headerList.size > 0)
  puts "Headers found"
end
puts "key pressed"
driver.press_keycode(20)
driver.press_keycode(20)
driver.press_keycode(23)
sleep 5
driver.press_keycode(22)
driver.press_keycode(22)
driver.press_keycode(23)
sleep 5
driver.press_keycode(23)
sleep 5
cardList = driver.find_elements(:id, "com.example.android.tvleanback:id/controls_card")
if (cardList.size > 0)
  puts "Control cards found"
end
sleep 5
driver.press_keycode(85) #pause
sleep 5
driver.press_keycode(85) #play
sleep 5
driver.press_keycode(89)
driver.press_keycode(21)
sleep 5
driver.press_keycode(90)
driver.press_keycode(22)
sleep 5
driver.press_keycode(4)
driver.press_keycode(4)
sleep 5
driver.quit

4. View test execution results

After you start the test execution, visit your App Automate dashboard to view your test results.

You can drill down into the details of a specific test session to view its execution details and debugging information such as video recording, screenshots and appium logs.

You can also use API requests to view test results.

Need some help?

If you have any queries, contact support.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert