Smart tv testing on BrowserStack App Automate
A quickstart guide to running your Appium tests on smart tv devices with BrowserStack App Automate.
Getting Started
Run your first smart tv test suite on BrowserStack in few simple steps. This quick start guide helps you get started with smart tv testing on BrowserStack App Automate.
1. Configure your BrowserStack credentials
After you get access to the alpha version of Smart TV testing, you will need the BrowserStack username and access key to get started with the tests. Go to your account settings to obtain your credentials.
You need to set the environment variables BROWSERSTACK_USERNAME
and BROWSERSTACK_ACCESS_KEY
with your credentials as shown below to run all our sample scripts:
export BROWSERSTACK_USERNAME="YOUR_USERNAME"
export BROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY"
2. Upload your app
.apk
file to upload, you can use our sample Fire OS app to test your scenarios.
Upload your Fire OS app (.apk
) to BrowserStack servers using our REST API. Use the following 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"
}
Ensure that you note the value of the app_url
key returned in the API response. For the example above, this value is bs://j3c874f21852b.....
. This value is used later to set the app
capability, which specifies the application under test in your Appium test scripts.
cURL
command until you get the response.
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.
Before using the sample script, make the following changes to the script:
- Specify the application under test using the
app
capability. Set theapp
capability to theapp_url
value returned when you uploaded the app in Step 2. - Specify the
device
capability asAmazon Fire TV Stick 4K
- Edit and initialize an Appium driver to 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
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();
}
}
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();
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
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
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!