diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8288969 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Ignore all log files +*.log + +# Ignore specific file +secret.txt + +# Ignore all `.DS_Store` files +.DS_Store + +target/ \ No newline at end of file diff --git a/README.md b/README.md index 0f059ad..806888d 100644 --- a/README.md +++ b/README.md @@ -1 +1,43 @@ -# browserstack-example-smartTV-appium-java \ No newline at end of file +# smart_tv_appium + +# BrowserStack smartTV CE demo +This just has basic Appium-JAVA scripts which runs on the following smart TV devices on Browserstack: + +- Amazon Fire TV Stick 4K (Android v7.1) + +- Nvidia Shield TV Pro 2019 (Android v11.0) + +- Apple TV 4k (tvOS v16.3) + +## Install repo + +--- +- Clone the repo +- Set your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) in the browserstack.yml files or set BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY as environmental variables +- This repo was designed to work with smart TV. +- +## You can run any of the following scenerios + + +1. Run a test on Amazon Fire TV Stick 4K +``` +export BROWSERSTACK_CONFIG_FILE="src/resources/conf/browserstack-amazonFireTV.yml" +mvn test -P androidFireTV +``` +2. Run a test on nvidia_shieldTV +``` +export BROWSERSTACK_CONFIG_FILE="src/resources/conf/browserstack-nvidia_shieldTV.yml" +mvn test -P nvidia_shieldTV +``` +3. Run a test on appleTV +``` +export BROWSERSTACK_CONFIG_FILE="src/resources/conf/browserstack-appleTV.yml" +mvn test -P appleTV +``` + +## Notes + +--- +- You can view your test results on the [BrowserStack app automate dashboard](https://app-automate.browserstack.com/dashboard/v2) + + diff --git a/browserstack.yml b/browserstack.yml new file mode 100644 index 0000000..c105976 --- /dev/null +++ b/browserstack.yml @@ -0,0 +1,78 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: +accessKey: + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Smart TV Project +# Set `buildName` as the name of the job / testsuite being run +buildName: BrowserStack Smart TV Build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} +# ======================================= +# App +# ======================================= +# Set `app` to use the appliction under test for Appium sessions. +# Available options: +# app: '/path/to/local/app.apk' +# OR +# app: 'bs://' # App URL returned when uploading the app to BrowserStack manually +# Visit https://www.browserstack.com/docs/app-automate/appium/set-up-tests/specify-app for more options +app: bs://506a7b1c148ce98416d0a7760f56d5dcb3b70774 # BrowserStack Sample App + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) +platforms: + - device: Amazon Fire TV Stick 4K + osVersion: 7.1 + platformName: android + + +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +source: java:appium-intellij:v1.1.2 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: false # (Default false) + +# Options to be passed to BrowserStack local in-case of advanced configurations +# browserStackLocalOptions: + # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. + # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. + # Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/config/amazonFireTV.testng.xml b/config/amazonFireTV.testng.xml new file mode 100644 index 0000000..df6a1e9 --- /dev/null +++ b/config/amazonFireTV.testng.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/config/appleTV.testng.xml b/config/appleTV.testng.xml new file mode 100644 index 0000000..0c4470b --- /dev/null +++ b/config/appleTV.testng.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/config/nvidia_shieldTV.testng.xml b/config/nvidia_shieldTV.testng.xml new file mode 100644 index 0000000..04a08aa --- /dev/null +++ b/config/nvidia_shieldTV.testng.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..28e5ce4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,191 @@ + + 4.0.0 + + org.demo + Demo + 1.0-SNAPSHOT + + Demo + https://github.com/BrowserStackCE/smart_tv_appium.git + + + UTF-8 + 1.8 + 3.0.0-M5 + 1.8 + 7.4.0 + 3.0.0-M5 + config/smartTV.testng.xml + + + + + org.testng + testng + 7.8.0 + test + + + org.seleniumhq.selenium + selenium-java + 4.15.0 + test + + + org.seleniumhq.selenium + selenium-api + 2.53.1 + + + io.github.bonigarcia + webdrivermanager + 5.6.2 + compile + + + io.appium + java-client + 9.0.0 + + + + org.seleniumhq.selenium + selenium-remote-driver + 4.16.1 + + + com.browserstack + browserstack-java-sdk + LATEST + compile + + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin-javaagent:"${com.browserstack:browserstack-java-sdk:jar}" + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + maven-dependency-plugin + 3.3.0 + + + getClasspathFilenames + + properties + + + + + + maven-surefire-plugin + ${surefire.version} + + + ${config.file} + -javaagent:"${com.browserstack:browserstack-java-sdk:jar}" + + + + + + + androidFireTV + + + + maven-surefire-plugin + ${surefire.version} + + + config/amazonFireTV.testng.xml + -javaagent:"${com.browserstack:browserstack-java-sdk:jar}" + + + + + + + nvidia_shieldTV + + + + maven-surefire-plugin + ${surefire.version} + + + config/nvidia_shieldTV.testng.xml + -javaagent:"${com.browserstack:browserstack-java-sdk:jar}" + + + + + + + appleTV + + + + maven-surefire-plugin + ${surefire.version} + + + config/appleTV.testng.xml + -javaagent:"${com.browserstack:browserstack-java-sdk:jar}" + + + + + + + \ No newline at end of file diff --git a/src/resources/conf/browserstack-amazonFireTV.yml b/src/resources/conf/browserstack-amazonFireTV.yml new file mode 100644 index 0000000..5d810c3 --- /dev/null +++ b/src/resources/conf/browserstack-amazonFireTV.yml @@ -0,0 +1,78 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: +accessKey: + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Smart TV Project +# Set `buildName` as the name of the job / testsuite being run +buildName: BrowserStack Smart TV Build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} +# ======================================= +# App +# ======================================= +# Set `app` to use the appliction under test for Appium sessions. +# Available options: +# app: '/path/to/local/app.apk' +# OR +# app: 'bs://' # App URL returned when uploading the app to BrowserStack manually +# Visit https://www.browserstack.com/docs/app-automate/appium/set-up-tests/specify-app for more options +app: bs://506a7b1c148ce98416d0a7760f56d5dcb3b70774 # BrowserStack Sample App + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) +platforms: + - device: Amazon Fire TV Stick 4K + osVersion: 7.1 + platformName: android + + +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +source: java:appium-intellij:v1.1.2 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: false # (Default false) + + # Options to be passed to BrowserStack local in-case of advanced configurations + # browserStackLocalOptions: + # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. + # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. + # Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/src/resources/conf/browserstack-appleTV.yml b/src/resources/conf/browserstack-appleTV.yml new file mode 100644 index 0000000..741d0c5 --- /dev/null +++ b/src/resources/conf/browserstack-appleTV.yml @@ -0,0 +1,77 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: +accessKey: + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Smart Apple TV Project +# Set `buildName` as the name of the job / testsuite being run +buildName: BrowserStack Smart Apple TV Build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} +# ======================================= +# App +# ======================================= +# Set `app` to use the appliction under test for Appium sessions. +# Available options: +# app: '/path/to/local/app.apk' +# OR +# app: 'bs://' # App URL returned when uploading the app to BrowserStack manually +# Visit https://www.browserstack.com/docs/app-automate/appium/set-up-tests/specify-app for more options +app: bs://5b83fd8bc9834fc223e47460750658ead51d043c # BrowserStack Sample App + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) +platforms: + - device: Apple TV 4k + osVersion: 16.3 + platformName: tvos +automationName: xcuitest +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +source: java:appium-intellij:v1.1.2 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: false # (Default false) + + # Options to be passed to BrowserStack local in-case of advanced configurations + # browserStackLocalOptions: + # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. + # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. +# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/src/resources/conf/browserstack-nvidia_shieldTV.yml b/src/resources/conf/browserstack-nvidia_shieldTV.yml new file mode 100644 index 0000000..945be84 --- /dev/null +++ b/src/resources/conf/browserstack-nvidia_shieldTV.yml @@ -0,0 +1,78 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: +accessKey: + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Smart NVIDIA TV Project +# Set `buildName` as the name of the job / testsuite being run +buildName: BrowserStack Smart NVIDIA TV Build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} +# ======================================= +# App +# ======================================= +# Set `app` to use the appliction under test for Appium sessions. +# Available options: +# app: '/path/to/local/app.apk' +# OR +# app: 'bs://' # App URL returned when uploading the app to BrowserStack manually +# Visit https://www.browserstack.com/docs/app-automate/appium/set-up-tests/specify-app for more options +app: bs://506a7b1c148ce98416d0a7760f56d5dcb3b70774 # BrowserStack Sample App + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) +platforms: + - device: Nvidia Shield TV Pro 2019 + osVersion: 11.0 + platformName: android + + +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +source: java:appium-intellij:v1.1.2 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: false # (Default false) + + # Options to be passed to BrowserStack local in-case of advanced configurations + # browserStackLocalOptions: + # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. + # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. + # Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/src/test/java/org/demo/amazonFireTV.java b/src/test/java/org/demo/amazonFireTV.java new file mode 100644 index 0000000..594db33 --- /dev/null +++ b/src/test/java/org/demo/amazonFireTV.java @@ -0,0 +1,91 @@ +package org.demo; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.CommandExecutionHelper; +import java.net.URL; +import java.time.Duration; +import java.util.HashMap; + +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.logging.LogEntries; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import static io.appium.java_client.MobileCommand.pressKeyCodeCommand; + +public class amazonFireTV { + + public AppiumDriver driver; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + MutableCapabilities capabilities = new MutableCapabilities(); + HashMap bstackOptions = new HashMap<>(); + bstackOptions.putIfAbsent("source", "testng-java:sample-sdk:v1.0"); + capabilities.setCapability("bstack:options", bstackOptions); + driver = new AndroidDriver(new URL("https://hub-cloud.browserstack.com/wd/hub"), capabilities); + } + @Test + public void testt() throws Exception { + + Thread.sleep(5000); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + WebElement next_button = (WebElement) wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.view.View[@content-desc=\"Next\"]"))); + next_button.click(); + Thread.sleep(5000); + next_button.click(); + Thread.sleep(5000); + next_button.click(); + + WebElement get_started_button = (WebElement) wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.tvleanback:id/button_start"))); + get_started_button.click(); + + Thread.sleep(2000); + WebElement menu_sideitems = (WebElement) wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.tvleanback:id/header_label"))); + menu_sideitems.click(); + Thread.sleep(2000); + + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(22)); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + + Thread.sleep(2000); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + Thread.sleep(2000); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + Thread.sleep(2000); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + Thread.sleep(2000); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + Thread.sleep(2000); + + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(4)); + Thread.sleep(2000); + + WebElement overview_panel = (WebElement) wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.tvleanback:id/details_overview_actions"))); + JavascriptExecutor jse = (JavascriptExecutor)driver; + + if (overview_panel.isDisplayed()) + jse.executeScript("browserstack_executor: {\"action\":\"setSessionStatus\", \"arguments\": {\"status\": \"passed\", \"reason\": \"Test Passed\"}}"); + else + jse.executeScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\": \"failed\", \"reason\": \"Test Failed\"}}"); + + + } + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + driver.quit(); + } +} diff --git a/src/test/java/org/demo/appleTV.java b/src/test/java/org/demo/appleTV.java new file mode 100644 index 0000000..89a2553 --- /dev/null +++ b/src/test/java/org/demo/appleTV.java @@ -0,0 +1,63 @@ +package org.demo; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.CommandExecutionHelper; +import io.appium.java_client.android.AndroidDriver; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.net.URL; +import java.time.Duration; +import java.util.HashMap; + +import static io.appium.java_client.MobileCommand.pressKeyCodeCommand; + +public class appleTV { + DesiredCapabilities caps = new DesiredCapabilities(); + String username ="";; + public String accessKey = ""; + private static final String BROWSERSTACK_HUB_URL = "hub-cloud.browserstack.com"; + public AppiumDriver driver; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + + MutableCapabilities capabilities = new MutableCapabilities(); + HashMap bstackOptions = new HashMap<>(); + bstackOptions.putIfAbsent("source", "testng-java:sample-sdk:v1.0"); + capabilities.setCapability("bstack:options", bstackOptions); + driver = new AppiumDriver(new URL("https://hub-cloud.browserstack.com/wd/hub"), capabilities); + } + @Test + public void appleTVTest() throws Exception { + + Thread.sleep(5000); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + System.out.println(driver.getPageSource()); + driver.getScreenshotAs(OutputType.FILE); + boolean status=driver.getScreenshotAs(OutputType.FILE).isFile(); + JavascriptExecutor jse = (JavascriptExecutor)driver; + + if (status) + jse.executeScript("browserstack_executor: {\"action\":\"setSessionStatus\", \"arguments\": {\"status\": \"passed\", \"reason\": \"Test Passed\"}}"); + else + jse.executeScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\": \"failed\", \"reason\": \"Test Failed\"}}"); + + + + } + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + driver.quit(); + } +} diff --git a/src/test/java/org/demo/nvidia_shieldTV.java b/src/test/java/org/demo/nvidia_shieldTV.java new file mode 100644 index 0000000..07836e7 --- /dev/null +++ b/src/test/java/org/demo/nvidia_shieldTV.java @@ -0,0 +1,94 @@ +package org.demo; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.CommandExecutionHelper; +import io.appium.java_client.android.AndroidDriver; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.net.URL; +import java.time.Duration; +import java.util.HashMap; + +import static io.appium.java_client.MobileCommand.pressKeyCodeCommand; + +public class nvidia_shieldTV { + + public AppiumDriver driver; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + MutableCapabilities capabilities = new MutableCapabilities(); + HashMap bstackOptions = new HashMap<>(); + bstackOptions.putIfAbsent("source", "testng-java:sample-sdk:v1.0"); + capabilities.setCapability("bstack:options", bstackOptions); + driver = new AndroidDriver(new URL("https://hub-cloud.browserstack.com/wd/hub"), capabilities); + + } + @Test + public void nvidiaTest() throws Exception { + + Thread.sleep(5000); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + WebElement next_button = (WebElement) wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.view.View[@content-desc=\"Next\"]"))); + next_button.click(); + Thread.sleep(2000); + next_button.click(); + Thread.sleep(2000); + next_button.click(); + + + Thread.sleep(2000); + WebElement get_started_button = (WebElement) wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.tvleanback:id/button_start"))); + get_started_button.click(); + + Thread.sleep(2000); + WebElement menu_sideitems = (WebElement) wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.tvleanback:id/header_label"))); + menu_sideitems.click(); + Thread.sleep(2000); + + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(22)); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + + Thread.sleep(2000); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + Thread.sleep(2000); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + Thread.sleep(2000); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + Thread.sleep(2000); + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(23)); + Thread.sleep(2000); + + CommandExecutionHelper.execute(driver, pressKeyCodeCommand(4)); + Thread.sleep(2000); + + WebElement overview_panel = (WebElement) wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.tvleanback:id/details_overview_actions"))); + JavascriptExecutor jse = (JavascriptExecutor)driver; + + if (overview_panel.isDisplayed()) + jse.executeScript("browserstack_executor: {\"action\":\"setSessionStatus\", \"arguments\": {\"status\": \"passed\", \"reason\": \"Test Passed\"}}"); + else + jse.executeScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\": \"failed\", \"reason\": \"Test Failed\"}}"); + + + + } + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + driver.quit(); + } +}