-
Notifications
You must be signed in to change notification settings - Fork 16
enable local management using Java SDK #9
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
base: main
Are you sure you want to change the base?
Changes from all commits
ac21588
8309b86
7cf8f03
c60f3e4
4583b15
36ab011
e7f8827
93b54b9
ad7fdec
7701455
bf96630
a577798
89a56d0
c230390
1dc926a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,8 @@ target/ | |
| .vscode | ||
| browserstack.err | ||
| .idea/ | ||
| logs/ | ||
| /bin/ | ||
| .classpath | ||
| .project | ||
| .settings | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,33 +8,25 @@ Make sure `maven` is installed in your system. See if it is properly installed. | |
| mvn --version | ||
| ``` | ||
|
|
||
| ## Steps to run test | ||
|
|
||
| In every test file (JavaSample, JavaLocalSample, JavaParallelSample) make sure you set your credentials. | ||
| ```java | ||
| public static final String AUTOMATE_USERNAME = "BROWSERSTACK_USERNAME"; | ||
| public static final String AUTOMATE_ACCESS_KEY = "BROWSERSTACK_ACCESS_KEY"; | ||
| ``` | ||
| ## Steps to run local test (using Java SDK) | ||
|
|
||
| 1. Clone and navigate to the repo. | ||
| ``` | ||
| git clone -b sdk https://github.com/browserstack/java-selenium-browserstack.git | ||
| cd java-selenium-browserstack | ||
| ``` | ||
|
|
||
| ``` | ||
| git clone https://github.com/browserstack/java-selenium-browserstack.git | ||
| cd java-selenium-browserstack | ||
| ``` | ||
| 2. Set your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) in [browserstack.yml](browserstack.yml) | ||
|
|
||
| 2. Change capabilities of test. | ||
|
|
||
| ```java | ||
| HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); | ||
| browserstackOptions.put("os", "OS X"); | ||
| browserstackOptions.put("osVersion", "Sierra"); | ||
| browserstackOptions.put("local", "false"); | ||
| browserstackOptions.put("seleniumVersion", "4.0.0"); | ||
| capabilities.setCapability("bstack:options", browserstackOptions); | ||
| capabilities.setCapability("sessionName", "BStack-[Java] Sample Test"); // test name | ||
| capabilities.setCapability("buildName", "BStack Build Number 1"); // CI/CD job or build name | ||
| ``` | ||
| 3. Add `browserstack-java-sdk` in your `pom.xml` as below. | ||
| ``` | ||
| <dependency> | ||
| <groupId>com.browserstack</groupId> | ||
| <artifactId>browserstack-java-sdk</artifactId> | ||
| <version>LATEST</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| ## Build and run test using maven. | ||
|
|
||
|
|
@@ -47,15 +39,51 @@ mvn install | |
|
|
||
| a. To run single test session. | ||
| ``` | ||
| mvn -Dexec.mainClass="com.browserstack.app.JavaSample" -Dexec.classpathScope=test test-compile exec:java | ||
| mvn exec:exec -Dexec.executable="java" -Dexec.classpathScope=test -Dexec.args="-cp %classpath -javaagent:/path/to/.m2/repository/browserstack-java-sdk/jar com.browserstack.app.JavaSample" | ||
| ``` | ||
|
|
||
| b. To run local test session. | ||
| - Ensure that you have set `browserstackLocal: true` in your `browserstack.yml` config. | ||
| ``` | ||
| mvn exec:exec -Dexec.executable="java" -Dexec.classpathScope=test -Dexec.args="-cp %classpath -javaagent:/path/to/.m2/repository/browserstack-java-sdk/jar com.browserstack.app.JavaLocalSample" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a sample command, for windows and osx as mentioned in docs. |
||
| ``` | ||
|
|
||
| b. To run parallel test session. | ||
| ### Arguments | ||
|
|
||
| For the full list of arguments that can be passed in `browserStackLocalOptions`, refer [BrowserStack Local modifiers](https://www.browserstack.com/docs/local-testing/binary-params). For examples, refer below - | ||
|
|
||
| #### Verbose Logging | ||
| To enable verbose logging - | ||
| ```java | ||
| browserStackLocalOptions: | ||
| v: true | ||
| logFile: /browserstack/logs.txt | ||
| ``` | ||
| mvn -Dexec.mainClass="com.browserstack.app.JavaParallelSample" -Dexec.classpathScope=test test-compile exec:java | ||
|
|
||
| #### Force Start | ||
| To kill other running Browserstack Local instances - | ||
| ```java | ||
| browserStackLocalOptions: | ||
| force: true | ||
| ``` | ||
|
|
||
| c. To run local test session. | ||
| #### Only Automate | ||
| To disable local testing for Live and Screenshots, and enable only Automate - | ||
| ```java | ||
| browserStackLocalOptions: | ||
| onlyAutomate: true | ||
| ``` | ||
| mvn -Dexec.mainClass="com.browserstack.app.JavaLocalSample" -Dexec.classpathScope=test test-compile exec:java | ||
|
|
||
| #### Force Local | ||
| To route all traffic via local(your) machine - | ||
| ```java | ||
| browserStackLocalOptions: | ||
| forcelocal: true | ||
| ``` | ||
|
|
||
| #### Local Identifier | ||
| If doing simultaneous multiple local testing connections, set this uniquely for different processes - | ||
| ```java | ||
| browserStackLocalOptions: | ||
| localIdentifier: randomstring | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # ============================= | ||
| # Set BrowserStack Credentials | ||
| # ============================= | ||
| # Add your BrowserStack userName and accessKey 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 | ||
|
|
||
| platforms: | ||
| - os: OS X | ||
| osVersion: Big Sur | ||
| browserName: Chrome | ||
| browserVersion: latest | ||
| - os: Windows | ||
| osVersion: 10 | ||
| browserName: Edge | ||
| browserVersion: latest | ||
| - device: Samsung Galaxy S22 Ultra | ||
| browserName: chrome # Try 'samsung' for Samsung browser | ||
| osVersion: 12.0 | ||
|
|
||
| # ========================================== | ||
| # 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: browserStackSDK # <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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,97 +16,85 @@ | |
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <maven.compiler.source>1.8</maven.compiler.source> | ||
| <maven.compiler.target>1.8</maven.compiler.target> | ||
| <browserstack.sdk.version>1.0.8</browserstack.sdk.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.11</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>commons-io</groupId> | ||
| <artifactId>commons-io</artifactId> | ||
| <version>1.3.2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.seleniumhq.selenium</groupId> | ||
| <artifactId>selenium-java</artifactId> | ||
| <version>4.1.0</version> | ||
| <version>4.4.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.browserstack</groupId> | ||
| <artifactId>browserstack-local-java</artifactId> | ||
| <version>1.0.3</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.googlecode.json-simple</groupId> | ||
| <artifactId>json-simple</artifactId> | ||
| <version>1.1.1</version> | ||
| <artifactId>browserstack-java-sdk</artifactId> | ||
| <version>LATEST</version> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 1.0.8 version as we are using it below in exec plugin. |
||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
| <plugins> | ||
| <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
| <plugin> | ||
| <artifactId>maven-clean-plugin</artifactId> | ||
| <version>3.1.0</version> | ||
| </plugin> | ||
| <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
| <plugin> | ||
| <artifactId>maven-resources-plugin</artifactId> | ||
| <version>3.0.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>3.8.0</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>2.22.1</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <version>3.0.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-install-plugin</artifactId> | ||
| <version>2.5.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-deploy-plugin</artifactId> | ||
| <version>2.8.2</version> | ||
| </plugin> | ||
| <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
| <plugin> | ||
| <artifactId>maven-site-plugin</artifactId> | ||
| <version>3.7.1</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-project-info-reports-plugin</artifactId> | ||
| <version>3.0.0</version> | ||
| </plugin> | ||
| </plugins> | ||
| </pluginManagement> | ||
| </build> | ||
| <profiles> | ||
| <!-- To run sample-test profile, mvn exec:exec -P sample-test --> | ||
| <profile> | ||
| <id>sample-test</id> | ||
| <build> | ||
| <pluginManagement> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>exec-maven-plugin</artifactId> | ||
kamal-kaur04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <version>3.1.0</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>java</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| <configuration> | ||
| <classpathScope>test</classpathScope> | ||
| <executable>java</executable> | ||
| <arguments> | ||
| <argument>-classpath</argument> | ||
| <classpath/> | ||
kamal-kaur04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <argument>-javaagent:${settings.localRepository}/com/browserstack/browserstack-java-sdk/${browserstack.sdk.version}/browserstack-java-sdk-${browserstack.sdk.version}.jar</argument> | ||
| <argument>com.browserstack.app.JavaSample</argument> | ||
| </arguments> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </pluginManagement> | ||
| </build> | ||
| </profile> | ||
| <profile> | ||
| <id>single</id> | ||
| <!-- To run sample-local-test profile, mvn exec:exec -P sample-local-test --> | ||
| <id>sample-local-test</id> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
karanshah-browserstack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <includes> | ||
| <include>com/browserstack/app/JavaSample.java</include> | ||
| </includes> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| <pluginManagement> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>exec-maven-plugin</artifactId> | ||
| <version>3.1.0</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>java</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| <configuration> | ||
| <classpathScope>test</classpathScope> | ||
| <executable>java</executable> | ||
| <arguments> | ||
| <argument>-classpath</argument> | ||
| <classpath/> | ||
| <argument>-javaagent:${settings.localRepository}/com/browserstack/browserstack-java-sdk/${browserstack.sdk.version}/browserstack-java-sdk-${browserstack.sdk.version}.jar</argument> | ||
| <argument>com.browserstack.app.JavaLocalSample</argument> | ||
| </arguments> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </pluginManagement> | ||
| </build> | ||
| </profile> | ||
| </profiles> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.