Skip to content
Open
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
f727da4
Merge pull request #6 from browserstack/java_ios
tejasshah93 Sep 6, 2017
b651a88
remove local samples
Sep 17, 2017
26bcce6
Merge pull request #7 from browserstack/java_rm_local
tejasshah93 Sep 17, 2017
f2b96e2
use Android Driver Element instead of Selenium
Sep 21, 2017
2172119
Merge pull request #8 from browserstack/use_native
tejasshah93 Sep 22, 2017
d667cc8
add type to AndroidDriver
Sep 22, 2017
62af473
Merge pull request #9 from browserstack/use_native
tejasshah93 Sep 22, 2017
a32d46c
re-add local samples | update readme
Sep 22, 2017
3411a96
Merge pull request #10 from browserstack/use_native
tejasshah93 Sep 25, 2017
6a58a55
update sendKeys call
Oct 14, 2017
748b7a3
update condition | remove realMobile, automationName cap
Dec 12, 2017
5979031
Merge pull request #11 from browserstack/condition_caps
Dec 12, 2017
1924c16
Changes for new sample app
May 2, 2018
9543190
Merge pull request #12 from browserstack/new_sample_app
agundawar May 14, 2018
1bc5d60
New Maven project
kn-neeraj Aug 29, 2020
ee60227
Adding .DS_Store and IDE Settings to Git Ignore file
kn-neeraj Aug 29, 2020
9e93054
Adding Local script files
kn-neeraj Aug 29, 2020
70a6a4f
Update README.md
kn-neeraj Aug 29, 2020
e4dde43
Updating readme. Removing .classpath from gitignore
kn-neeraj Aug 31, 2020
b19e063
Updated pom to work from terminal
kn-neeraj Sep 1, 2020
39afd53
Bringing all files to the main folder
kn-neeraj Sep 1, 2020
97b8d8b
Adding mvn profiles for all the test scenarios
kn-neeraj Sep 1, 2020
399c107
Updated Readme
kn-neeraj Sep 1, 2020
788a1f8
Removing selenium dependency. Typo fix in Readme
kn-neeraj Sep 1, 2020
eda6352
Updating Local test for Android and iOS.
kn-neeraj Sep 24, 2020
f8ff5f5
Updating Readme with Local test
kn-neeraj Sep 24, 2020
9e698bc
Update README.md
kn-neeraj Sep 25, 2020
2673193
Update README.md
kn-neeraj Sep 25, 2020
c14a791
Updating class names according to QSG. Removing unwanted imports.
kn-neeraj Sep 26, 2020
d834fc4
Updating Readme
kn-neeraj Sep 26, 2020
3d232d6
Reverting to previous imports for android and ios sample tests
kn-neeraj Sep 30, 2020
60ecc20
changing 'capabilities' to 'caps'
kn-neeraj Oct 1, 2020
e7f7f02
Adding Access credentials URL for convenience.
kn-neeraj Oct 1, 2020
ef74b65
Merge pull request #13 from kn-neeraj/new_maven_project
agundawar Oct 7, 2020
db95171
Updated build names as per QIG
nitish-bhardwaj-code Sep 20, 2021
186d775
Merge pull request #16 from nitish-bhardwaj-code/update_build_name
deepwired Sep 29, 2021
3e7d33b
Added support for java-client 8.0.0
innovater21 Mar 10, 2022
10120bb
Updated java-client version to 8.0.0
innovater21 Mar 11, 2022
c1b2e32
added w3c capabilities
innovater21 Mar 11, 2022
15c4e05
added w3c capabilities
innovater21 Mar 11, 2022
8073b7f
Added w3c capabilities and support
innovater21 Mar 11, 2022
680d070
added support for w3c and upgrade
innovater21 Mar 11, 2022
5004519
removed deprecated syntax
innovater21 Mar 11, 2022
2a41e1d
added comment for w3c support
innovater21 Mar 16, 2022
9f20467
w3c compliant
innovater21 Mar 16, 2022
249f818
lint
innovater21 Mar 16, 2022
1316fea
Update README.md
innovater21 Mar 16, 2022
8931708
typo fix
innovater21 Mar 16, 2022
63478c0
Update README.md
innovater21 Mar 16, 2022
e2cf186
Update README.md
innovater21 Mar 16, 2022
f1cb725
Update README.md
innovater21 Mar 16, 2022
3cf22be
Updated README for initiating a local connection
innovater21 Mar 17, 2022
ecb8978
Added local testing link for local testing
innovater21 Mar 17, 2022
2f1f069
Merge pull request #18 from browserstack/AASI-812-support-java-client…
deepwired Mar 17, 2022
f2baa82
created dedicated directories for java7 and java8
deepwired May 10, 2022
7eb080f
updating readme.md file with links for java7 and java8
deepwired May 17, 2022
6b1f7cf
adding tab navigation for both java/protocol versions
deepwired May 17, 2022
92daf59
typo, missed a . in back links
deepwired May 17, 2022
07080f9
linking to repo instead of readme
deepwired May 17, 2022
b746aca
small content updates
deepwired May 17, 2022
dd073c2
updated ios device/os combo
deepwired May 25, 2022
8932035
iPhone 12 + iOS 13
deepwired May 26, 2022
e37aeb3
Merge pull request #20 from browserstack/java_versions
deepwired May 26, 2022
e9ea53a
Update BrowserStackSample.java
8ll Jan 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added support for w3c and upgrade
  • Loading branch information
innovater21 committed Mar 11, 2022
commit 680d0701ae9ce69129fccacb875e358a82d7a544
187 changes: 106 additions & 81 deletions src/test/java/ios/BrowserStackSampleLocal.java
Original file line number Diff line number Diff line change
@@ -1,99 +1,124 @@
package ios;

import com.browserstack.local.Local;
import java.net.URL; import java.io.File; import java.util.*;
import io.appium.java_client.AppiumBy;
import java.io.File;
import java.net.URL;
import java.time.Duration;
import java.util.*;
import org.apache.commons.io.FileUtils;
import io.appium.java_client.ios.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.*;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.*;

public class BrowserStackSampleLocal {

private static Local localInstance;
public static String userName = "YOUR_USERNAME";
public static String accessKey = "YOUR_ACCESS_KEY";


public static void setupLocal() throws Exception {
localInstance = new Local();
Map<String, String> options = new HashMap<String, String>();
options.put("key", accessKey);
localInstance.start(options);
}

public static void tearDownLocal() throws Exception {
localInstance.stop();
}
private static Local localInstance;
public static String userName = "YOUR_USERNAME";
public static String accessKey = "YOUR_ACCESS_KEY";

public static void setupLocal() throws Exception {
localInstance = new Local();
Map<String, String> options = new HashMap<String, String>();
options.put("key", accessKey);
options.put("local", "true");
localInstance.start(options);
}

public static void tearDownLocal() throws Exception {
localInstance.stop();
}

public static void main(String[] args) throws Exception {
// Start the BrowserStack Local binary
setupLocal();

DesiredCapabilities capabilities = new DesiredCapabilities();

// Set your access credentials
capabilities.setCapability("browserstack.user", userName);
capabilities.setCapability("browserstack.key", accessKey);

// Set URL of the application under test
capabilities.setCapability("app", "<app-id>");

public static void main(String[] args) throws Exception {
// Start the BrowserStack Local binary
setupLocal();

DesiredCapabilities capabilities = new DesiredCapabilities();

// Set your access credentials
capabilities.setCapability("browserstack.user", userName);
capabilities.setCapability("browserstack.key", accessKey);

// Set URL of the application under test
capabilities.setCapability("app", "bs://<app-id>");

// Specify device and os_version for testing
capabilities.setCapability("device", "iPhone 11 Pro");
capabilities.setCapability("os_version", "13");

// Set the browserstack.local capability to true
capabilities.setCapability("browserstack.local", true);

// Set other BrowserStack capabilities
capabilities.setCapability("project", "First Java Project");
capabilities.setCapability("build", "browserstack-build-1");
capabilities.setCapability("name", "local_test");

// Initialise the remote Webdriver using BrowserStack remote URL
// and desired capabilities defined above
RemoteWebDriver driver = new RemoteWebDriver(
new URL("http://hub.browserstack.com/wd/hub"), capabilities);

// Test case for the BrowserStack sample iOS Local app.
// If you have uploaded your app, update the test case here.
WebElement testButton = (WebElement) new WebDriverWait(driver, 30).until(
ExpectedConditions.elementToBeClickable(By.xpath("//*[@content-desc='TestBrowserStackLocal']")));
testButton.click();

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
String result = d.findElement(By.xpath("//*[@content-desc='ResultBrowserStackLocal']")).getAttribute("value");
return result != null && result.length() > 0;
}
});
WebElement resultElement = (WebElement) driver.findElement(By.xpath("//*[@content-desc='ResultBrowserStackLocal']"));

String resultString = resultElement.getText().toLowerCase();
System.out.println(resultString);
if(resultString.contains("not working")) {
File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png"));
System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png");
throw new Error("Unexpected BrowserStackLocal test result");
// Specify device and os_version for testing
capabilities.setCapability("deviceName", "iPhone 11 Pro");
capabilities.setCapability("platformName", "ios");
capabilities.setCapability("platformVersion", "13");

// Set the browserstack.local capability to true
capabilities.setCapability("browserstack.local", true);

// Set other BrowserStack capabilities
capabilities.setCapability("project", "First Java Project");
capabilities.setCapability("build", "browserstack-build-1");
capabilities.setCapability("name", "local_test");

// Initialise the remote Webdriver using BrowserStack remote URL
// and desired capabilities defined above
RemoteWebDriver driver = new RemoteWebDriver(
new URL("http://hub.browserstack.com/wd/hub"),
capabilities
);

// Test case for the BrowserStack sample iOS Local app.
// If you have uploaded your app, update the test case here.
WebElement testButton = (WebElement) new WebDriverWait(
driver,
Duration.ofSeconds(30)
)
.until(
ExpectedConditions.elementToBeClickable(
AppiumBy.accessibilityId("TestBrowserStackLocal")
)
);
testButton.click();

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(
new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
String result = d
.findElement(AppiumBy.accessibilityId("ResultBrowserStackLocal"))
.getAttribute("value");
return result != null && result.length() > 0;
}
}
);
WebElement resultElement = (WebElement) driver.findElement(
AppiumBy.accessibilityId("ResultBrowserStackLocal")
);

String resultString = resultElement.getText().toLowerCase();
System.out.println(resultString);
if (resultString.contains("not working")) {
File scrFile = (File) ((TakesScreenshot) driver).getScreenshotAs(
OutputType.FILE
);
FileUtils.copyFile(
scrFile,
new File(System.getProperty("user.dir") + "/screenshot.png")
);
System.out.println(
"Screenshot stored at " +
System.getProperty("user.dir") +
"/screenshot.png"
);
throw new Error("Unexpected BrowserStackLocal test result");
}

String expectedString = "Up and running";
assert(resultString.contains(expectedString.toLowerCase()));
String expectedString = "Up and running";
assert (resultString.contains(expectedString.toLowerCase()));

// Invoke driver.quit() after the test is done to indicate that the test is completed.
driver.quit();

// Stop the BrowserStack Local binary
tearDownLocal();

}
// Invoke driver.quit() after the test is done to indicate that the test is completed.
driver.quit();

// Stop the BrowserStack Local binary
tearDownLocal();
}
}