Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introducing browserstack-sdk to the sample repo #24

Merged
merged 16 commits into from
Jan 4, 2023
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ target/
local.log
.idea
*.iml
.DS_Store
**/logs/*
kamal-kaur04 marked this conversation as resolved.
Show resolved Hide resolved
Binary file added android/testng-examples/LocalSample.apk
Binary file not shown.
Binary file added android/testng-examples/WikipediaSample.apk
Binary file not shown.
73 changes: 73 additions & 0 deletions android/testng-examples/browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# =============================
# Set BrowserStack Credentials
# =============================
# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
# BROWSERSTACK_ACCESS_KEY as env variables
userName: BROWSERSTACK_USERNAME
accessKey: BROWSERSTACK_ACCESS_KEY

# ======================
# Organizing your tests
# ======================
# Use `projectName`, `buildName`, `name` capabilities to organise your tests
# `name` is the name of your test sessions and is automatically picked from your
# test name and doesn't need to be set manually when using BrowserStack SDK
# `buildName` is used to name your CI/CD job or the execution of your test suite.
# Ensure you add a dynamic identifier, like an incremental build number from your
# CI/CD or timestamp at the end of every build; otherwise tests from different
# executions will be grouped together on BrowserStack
buildName: browserstack-build-1
# Use `projectName` to set the name of your project. Example, Marketing Website
projectName: BrowserStack Samples
mattonem marked this conversation as resolved.
Show resolved Hide resolved
# Use `framework` to set the framework of your project. Example, testng, cucumber, cucumber-testng
framework: testng

source: testng:archetype-integrate:v1.2
kamal-kaur04 marked this conversation as resolved.
Show resolved Hide resolved

# =======================================
# 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)
app: ./WikipediaSample.apk
kamal-kaur04 marked this conversation as resolved.
Show resolved Hide resolved

platforms:
- device: Samsung Galaxy S22 Ultra
osVersion: 12.0
- deviceName: Samsung Galaxy S21
osVersion: 11.0
- deviceName: Google Pixel 7
osVersion: 13.0


# =======================
# 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: 2
kamal-kaur04 marked this conversation as resolved.
Show resolved Hide resolved

# ==========================================
# 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: true # <boolean> (Default false)
#browserStackLocalOptions:
#Options to be passed to BrowserStack local in-case of advanced configurations
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
# forceLocal: true # <boolean> (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 # <boolean> # Set to true if you need screenshots for every selenium command ran
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
67 changes: 27 additions & 40 deletions android/testng-examples/pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.browserstack</groupId>
<artifactId>testng-browserstack</artifactId>
<artifactId>testng-browserstack-android</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

Expand All @@ -12,9 +12,10 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<surefire.version>2.19.1</surefire.version>

<test.file></test.file>
<surefire.plugin.version>3.0.0-M5</surefire.plugin.version>
<config.file>default</config.file>
</properties>

Expand Down Expand Up @@ -49,6 +50,12 @@
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>browserstack-java-sdk</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -57,6 +64,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-javaagent:${com.browserstack:browserstack-java-sdk:jar}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -67,6 +77,18 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
kamal-kaur04 marked this conversation as resolved.
Show resolved Hide resolved
<version>3.3.0</version>
<executions>
<execution>
<id>getClasspathFilenames</id>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand All @@ -87,40 +109,5 @@
</plugins>
</build>
</profile>

<profile>
<id>local</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/com/browserstack/run_local_test/local.testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>parallel</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.browserstack.run_first_test;

import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

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


public class AppiumTest {

public AppiumDriver<AndroidElement> driver;

@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
kamal-kaur04 marked this conversation as resolved.
Show resolved Hide resolved
driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}

@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
driver.quit();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.browserstack.run_first_test;

import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidElement;
import java.util.List;

import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;

public class FirstTest extends BrowserStackTestNGTest {
import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidElement;

public class FirstTest extends AppiumTest {

@Test
public void test() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.browserstack.run_local_test;
package com.browserstack.run_first_test;

import org.testng.Assert;
import org.testng.annotations.Test;
Expand All @@ -15,14 +15,14 @@
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;

public class LocalTest extends BrowserStackTestNGTest {
public class LocalTest extends AppiumTest {

@Test
public void test() throws Exception {
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action")));
searchElement.click();
AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until(
new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView")));

AndroidElement testElement = null;
Expand All @@ -45,4 +45,4 @@ public void test() throws Exception {
Assert.assertTrue(matchedString.contains("The active connection is wifi"));
Assert.assertTrue(matchedString.contains("Up and running"));
}
}
}
kamal-kaur04 marked this conversation as resolved.
Show resolved Hide resolved
Loading