Skip to main content

Smart tv testing on BrowserStack App Automate

A quickstart guide to running your Appium tests on smart tv devices on BrowserStack

Important: Smart TV testing on BrowserStack (alpha) is not available to all users yet. If you’d like to get access, contact support and request access to the Smart TV alpha release.

Quickstart

Running your first smart tv test suite on BrowserStack is easy. Here’s a quick start guide to help you get started with smart tv testing on BrowserStack App Automate.

1. Configuring BrowserStack credentials

Once you have got access to the alpha version of Smart TV testing, you will need a BrowserStack username and access key that can be found in account settings

All our sample scripts need your BrowserStack credentials to run. Please set the environment variables BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY with your credentials as shown below:

Command Line
export BROWSERSTACK_USERNAME="YOUR_USERNAME"
export BROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY"

2. Upload your app

Note: If you do not have an .apk file handy, you can download and test using our sample Fire OS app.

Upload your Fire OS app (.apk) to BrowserStack servers using our REST API. Here is an example cURL request to upload the app :

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

A sample response for the above request is shown below:

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

Note the value of app_url returned in the API response (bs://j3c874f21852b..... in the above example). This value will be used later to set the app capability to specify application under test in your Appium test scripts.

Note: App upload will 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 back.

3. Setup 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. You will need to make the following changes in your test script :

  • Specify the application under test using the app capability. Use the app_url value returned at the time of app upload (Step 2) to set this capability.
  • Specify the device capability as Amazon Fire TV Stick 4K
  • In order to initialize an Appium driver, use a remote BrowserStack URL along with your BrowserStack access credentials as shown below :
      https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub
    

If you are using your own app, modify the following code as per your test case :

package android;

import java.net.URL;
import java.util.List;
import java.util.function.Function;
import java.net.MalformedURLException;

import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;


public class BrowserStackSample {

	public static void main(String[] args) throws MalformedURLException, InterruptedException {
		
    	DesiredCapabilities caps = new DesiredCapabilities();
    	
    	// Set your access credentials
    	caps.setCapability("browserstack.user", "<username>");
    	caps.setCapability("browserstack.key", "<access_key>");
    	
    	// Set URL of the application under test
    	caps.setCapability("app", "<app_hashed_id>");
    	
    	// Specify device and os_version for testing
    	caps.setCapability("device", "Amazon Fire TV Stick 4K");
    	caps.setCapability("os_version", "7.1");
        
    	// Set other BrowserStack capabilities
    	caps.setCapability("project", "First Java Project");
    	caps.setCapability("build", "browserstack-build-1");
    	caps.setCapability("name", "first_test");
       
    	
    	// Initialise the remote Webdriver using BrowserStack remote URL
    	// and desired capabilities defined above
        AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(
        		new URL("http://hub-cloud.browserstack.com/wd/hub"), caps);

		Thread.sleep(5000);
		driver.pressKey(new KeyEvent(AndroidKey.DPAD_DOWN));
		driver.pressKey(new KeyEvent(AndroidKey.DPAD_RIGHT));
		
		AndroidElement videoElement = driver.findElementByXPath("//android.widget.FrameLayout[@selected = 'true']");
		String videoName = videoElement.getAttribute("content-desc");
		System.out.println("Selected Video Name: " + videoName);

		driver.pressKey(new KeyEvent(AndroidKey.DPAD_CENTER));
		Thread.sleep(5000);
		driver.pressKey(new KeyEvent(AndroidKey.MEDIA_PLAY_PAUSE));
		Thread.sleep(3000);
		driver.pressKey(new KeyEvent(AndroidKey.MEDIA_PLAY_PAUSE));
		Thread.sleep(3000);
		driver.pressKey(new KeyEvent(AndroidKey.MEDIA_REWIND));
		Thread.sleep(3000);
		driver.pressKey(new KeyEvent(AndroidKey.BACK));

		AndroidElement focusedVideoElement = driver.findElementByXPath("//android.widget.FrameLayout[@selected = 'true']");
		String focusedVideoName = focusedVideoElement.getAttribute("content-desc");

		assert(focusedVideoName == videoName);

        // Invoke driver.quit() after the test is done to indicate that the test is completed.
        driver.quit();
		
	}

}

If you are using your own app, modify the following code as per your test case :

let wd = require('wd');
let assert = require('assert');
let asserters = wd.asserters;

desiredCaps = {
  // Set your BrowserStack access credentials
  'browserstack.user' : '<username>',
  'browserstack.key' : '<access_key>',

  // Set URL of the application under test
  'app' : '<app_hashed_id>',

  // Specify device and os_version for testing
  'device' : 'Amazon Fire TV Stick 4K',
  'os_version' : '7.1',

  // Set other BrowserStack capabilities
  'project' : 'First NodeJS project',
  'build' : 'Node Android',
  'name': 'first_test'
};

// Initialize the remote Webdriver using BrowserStack remote URL
// and desired capabilities defined above
driver = wd.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");

// Test case for the BrowserStack sample Android app. 
// If you have uploaded your app, update the test case here. 
driver.init(desiredCaps)
  .then(function () {
    return driver.pressKeycode(20);
  })
  .then(function() {
    return driver.pressKeycode(22);
  })
  .then(function(){
    return driver.elementByXPath("//android.widget.FrameLayout[@focused = 'true']");
  })
  .then(async function(videoElement) {
    let videoName = await videoElement.getAttribute("content-desc");
    console.log("Selected Video Name: " + videoName);
  })
  .then(function() {
    return driver.pressKeycode(23);
  })
  .then(function() {
    return driver.pressKeycode(85);
  })
  .then(function() {
    return driver.pressKeycode(85);
  })
  .then(function() {
    return driver.pressKeycode(89);
  })
  .then(function() {
    return driver.pressKeycode(4);
  })
  .then(function() {
    return driver.elementByXPath("//android.widget.FrameLayout[@focused = 'true']");
  })
  .then(async function(videoElement) {
    let videoName = await videoElement.getAttribute("content-desc");
    assert(videoName.length > 0);
  })
  .fin(function() { 
    // Invoke driver.quit() after the test is done to indicate that the test is completed.
    return driver.quit(); 
  })
  .done();

If you are using your own app, modify the following code as per your test case :

require 'rubygems'
require 'appium_lib'

username = '<username>'
access_key = '<access_key>'

desired_caps = {
    'build': 'Ruby Appium Sample',
    'device': 'Amazon Fire TV Stick 4K',
    'osVersion': '7.1',
    'browserstack.debug': 'true',
    'app': '<app_hashed_id>'
}

appium_driver = Appium::Driver.new({
    'caps' => desired_caps,
    'appium_lib' => {
        :server_url => "https://#{username}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
    }}, true)
driver = appium_driver.start_driver

sleep 5
driver.press_keycode(20) # DPAD_DOWN
driver.press_keycode(22) # DPAD_RIGHT

video_element = driver.find_element(:xpath, "//android.widget.FrameLayout[@focused = 'true']")
video_name = video_element.attribute('content-desc')
puts "Selected Video Name: #{video_name}"

driver.press_keycode(23) # DPAD_CENTER
sleep(5)
driver.press_keycode(85) # MEDIA_PLAY_PAUSE
sleep(3)
driver.press_keycode(85) # MEDIA_PLAY_PAUSE
sleep(3)
driver.press_keycode(89) # MEDIA_REWIND
sleep(3)
driver.press_keycode(4) # BACK

focussed_element = driver.find_element(:xpath, "//android.widget.FrameLayout[@focused = 'true']")
focussed_video_name = focussed_element.attribute('content-desc')

if focussed_video_name == video_name
  puts "Video played - Test passed"
else
  puts "Video Could not be played - Test Failed"
end

driver.quit

4. Viewing test results

You can access results of your test sessions on the App Automate dashboard as well as using our REST API. 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.

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