Select Page
OTT Testing

How to Perform Android TV Automation Testing using Appium?

With the rise of OTT platforms, knowing how to perform Android TV Automation Testing has become a must-know skill for all testers.

How to Perform Android TV Automation Testing using Appium - Blog
Listen to this blog

Automating an Android smart TV using Appium is not as same as automating an Android smartphone. For starters, the lack of touch input means that you should know how to automate remote control functions. And with the rise of OTT in recent years, knowing how to perform Android TV Automation Testing using Appium will be an important skill every automation tester must possess. Being a leading OTT testing company, we have written this blog that covers how to connect your computer to the smart TV and shows how to automate important actions such as search, video, and so on.

Enable Developer Options in Android TV:

Enabling Developer options is the first step in the Android TV Automation Testing process and it will make it possible to connect your computer with the TV. Being an Android device, enabling this mode is the same as doing it on an Android smartphone.

  • Click the ‘Settings’ Icon.
  • Go to ‘Device Preference’.
  • Go to ‘About’.
  • Find the ‘Build Option’ inside the About.
  • Click the build option until the “you are now a developer” message will appear in the display.
  • Go back to ‘Device Preference’ and scroll to the bottom.
  • Select the ‘Developer Options’ that you find there.
  • Find the USB Debugging Option and enable it.

Obtain the required information from the Smart TV

Though we need just the IP address of the smart TV to connect it with the computer, getting the Device Name, Platform Name, and Platform Version will come in handy when writing your automation script. So follow the below-mentioned steps

  • Click the ‘Settings’ Icon.
  • Choose Additional Settings.
  • Go to Device Preference.
  • Click the About option.
  • Get the Device Name, Platform Name, and Platform Version as you will need them for the script.
  • You will also see the Status option (Network) in About.
  • Click on it and obtain the IP Address of the Android TV.

How to Perform Android TV Automation Testing using Appium - Blog

Connect your Computer with the Smart TV

Now that everything has been set up, you can perform the below-mentioned steps to connect your computer with the Android smart TV.

  • Open Command Prompt.
  • Enter the Command “adb connect
  • Now, you can see the list of connected devices in Command Prompt.

Note: You should have configured all the Appium setups on your laptop before initiating the adb command.

Android TV Automation Testing

Testing an OTT platform is no simple task as there are so many aspects such as Core Functionality, UI & UX, Subscriptions, and so on a QA team would have to cover. In this automation guide of ours, we will be exploring how you can automate your core functionality tests such as

Launching the App

Now that we have all the prerequisites ready, let’s find out how to launch the app you wish to automate on your Android Smart TV, and then we will move on to the other actions later in the blog

public class LionsGateDemo {
    public static AppiumDriver<MobileElement> driver;
    public static WebDriverWait wait;
   public static void main(String[] args) throws IOException, InterruptedException {
        try {
            //Set the Desired Capabilities
            DesiredCapabilities caps = new DesiredCapabilities();
    //Set the Smart TV Name
            caps.setCapability("deviceName", "Redmi TV");
    //Set the Smart TV Platform
            caps.setCapability("platformName", "Android");
    //Set the Smart TV platform version
            caps.setCapability("platformVersion", "11");
    //Set the App package and app activity details
            caps.setCapability("appPackage", "com.xiaomi.lionsgateplay.videoapp");
            caps.setCapability("appActivity", "com.parsifal.starz.ui.features.splash.SplashActivity");
            caps.setCapability("unicodeKeyboard", true);
            caps.setCapability("resetKeyboard", true);
            caps.setCapability("noReset", "true");
            driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            System.out.println(">>>>  APP launched::::");
            wait = new WebDriverWait(driver, 30);

Note: Ensure that you use the exact name of your Smart TV as it is shown in the menu to avoid any errors.

Using Search Functionality

Since we have chosen Lionsgate for our Android TV Automation Testing explanation, we will be automating the user journey to reach the search bar. Kindly note that this user journey might vary depending on the platform or app you wish to automate.

You will also be able to verify if your automation script is working as intended by using our script. We have used the same input text used in the script to search and pick the first movie title manually. We then validate if both the manual and automation results are the same.

 // Finding & Clicking button One
            WebElement buttonOne = driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView"));
            wait.until(ExpectedConditions.elementToBeClickable(buttonOne));
            buttonOne.click();
    // Find & Click the bIcon
            WebElement bIcon = driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView"));
            wait.until(ExpectedConditions.elementToBeClickable(bIcon));
            bIcon.click();
            wait.until(ExpectedConditions.elementToBeClickable(bIcon));
            bIcon.click();
 
// Locate the Search Bar
            WebElement searchBox = driver.findElement(By.id("com.xiaomi.lionsgateplay.videoapp:id/lb_search_text_editor"));
// Enter the values in the Search input textbox 
           searchBox.sendKeys("a");
// Store the Movie name in a webelement 
            WebElement firstMovieName = driver.findElement(By.xpath("//androidx.recyclerview.widget.RecyclerView[@content-desc='Top results for: a']/android.widget.FrameLayout[1]/android.widget.ImageView"));
 
// Wait for the movie to become clickable and then click to open it
                        wait.until(ExpectedConditions.elementToBeClickable(firstMovieName));
            firstMovieName.click();
// Store our expected Movie name in the STRING
            String movieName = "Amores Perros";
 
// Finding Actual Movie name  
            WebElement OutputMovieName = driver.findElement(By.id("com.xiaomi.lionsgateplay.videoapp:id/titleText"));
// Get and Store our Actual Movie name in String
            String OutComeMovie = OutputMovieName.getText();
            System.out.println(OutComeMovie);
//Verify Actual and expected Movie name by using if condition
            if (movieName.equals(OutComeMovie)) {
                System.out.println("Both are same name");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

Playing a Movie

Now that we have successfully completed the search operation, the next course of action would be to automate a movie from the search results. We have given a sample code to help you to do it. Please note that you can use the same concepts we have seen now to play a video not just from search, but also from the home screen and so on. Just make sure to update the XPath as per your need.

// Finding Play button 
        WebElement playButton = driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.TextView"));
        playButton.isDisplayed();
// Wait for the Playbutton to be clickable and Click the Playbutton 
        wait.until(ExpectedConditions.elementToBeClickable(playButton));
        playButton.click();
        System.out.println("Play button is selected ");

Android TV Test Automation for Remote actions

Since you will be simulating button clicks from a remote control, you should know what element is currently in focus for ease of use. Once you have figured out how to automate the TV Remote actions, you will use them as a foundation to automate more actions like browsing the platform, turning on subtitles, and so on.

// To press the Up button
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_UP));
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_UP));
 // To Press the Center button
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_CENTER));
 // To Press the Down button
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_DOWN));
        // To Press the Center button
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_CENTER));
        System.out.println("None option inside the subtitle is selected");
        Thread.sleep(5000);
       // To Press the Up button
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_UP));
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_UP));
        // To Press the Center button
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_CENTER));
       // To Press the Up button
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_UP));
      // To Press the Center button
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_CENTER));
        System.out.println("English option inside the subtitle is selected");
        Thread.sleep(5000);
       // To Press the Right button for Forward the video
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_RIGHT));
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_RIGHT));
        ((PressesKey) driver).longPressKey(new KeyEvent(AndroidKey.DPAD_RIGHT));
        System.out.println("Forwarding is done successfully");
        System.out.println("Remote action done");
    }
}

Conclusion

We hope you found this blog useful in helping you perform Android TV Automation Testing for OTT platforms. The above-discussed actions are the foundational and must-know basics in OTT automation testing. You can easily expand your OTT automation by using them effectively. Being a leading QA company in all domains, we will be publishing more OTT testing content that you will find very useful. So make sure to stay subscribed to our newsletter.

Comments(0)

Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility