-
Notifications
You must be signed in to change notification settings - Fork 58
use options class instead deprecated DesiredCapabilities #24
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
Changes from all commits
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,21 +2,21 @@ | |
|
||
import io.appium.java_client.AppiumBy; | ||
import io.appium.java_client.android.AndroidDriver; | ||
import io.appium.java_client.android.options.UiAutomator2Options; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
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; | ||
|
||
public class BrowserStackSample { | ||
|
||
public static void main(String[] args) | ||
throws MalformedURLException, InterruptedException { | ||
DesiredCapabilities caps = new DesiredCapabilities(); | ||
throws MalformedURLException, InterruptedException { | ||
UiAutomator2Options options = new UiAutomator2Options(); | ||
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); | ||
|
||
// Set your access credentials | ||
|
@@ -27,57 +27,50 @@ public static void main(String[] args) | |
browserstackOptions.put("appiumVersion", "1.22.0"); | ||
browserstackOptions.put("projectName", "First Java Project"); | ||
browserstackOptions.put("buildName", "browserstack-build-1"); | ||
browserstackOptions.put("sessionName", "first_test"); | ||
browserstackOptions.put("sessionName", "BStack first_test"); | ||
|
||
// Passing browserstack capabilities inside bstack:options | ||
caps.setCapability("bstack:options", browserstackOptions); | ||
options.setCapability("bstack:options", browserstackOptions); | ||
|
||
// Set URL of the application under test | ||
caps.setCapability("app", "bs://<app-id>"); | ||
options.setCapability("app", "bs://<app-id>"); | ||
|
||
// Specify deviceName and platformName for testing | ||
caps.setCapability("deviceName", "Google Pixel 3"); | ||
caps.setCapability("platformName", "android"); | ||
caps.setCapability("platformVersion", "9.0"); | ||
options.setCapability("deviceName", "Google Pixel 3"); | ||
options.setCapability("platformName", "android"); | ||
options.setCapability("platformVersion", "9.0"); | ||
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. This is non-w3c compliant and it must go inside bStackOptions ? 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. Also app cap is not complaint. 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. For Appium these caps are general capabilities and not specific to Browserstack, please ref here |
||
|
||
// Initialise the remote Webdriver using BrowserStack remote URL | ||
// and desired capabilities defined above | ||
AndroidDriver driver = new AndroidDriver( | ||
new URL("http://hub.browserstack.com/wd/hub"), | ||
caps | ||
); | ||
new URL("http://hub.browserstack.com/wd/hub"), | ||
options); | ||
|
||
// Test case for the BrowserStack sample Android app. | ||
// If you have uploaded your app, update the test case here. | ||
WebElement searchElement = (WebElement) new WebDriverWait( | ||
driver, | ||
Duration.ofSeconds(30) | ||
) | ||
.until( | ||
ExpectedConditions.elementToBeClickable( | ||
AppiumBy.accessibilityId("Search Wikipedia") | ||
) | ||
); | ||
driver, | ||
Duration.ofSeconds(30)) | ||
.until( | ||
ExpectedConditions.elementToBeClickable( | ||
AppiumBy.accessibilityId("Search Wikipedia"))); | ||
searchElement.click(); | ||
|
||
WebElement insertTextElement = (WebElement) new WebDriverWait( | ||
driver, | ||
Duration.ofSeconds(30) | ||
) | ||
.until( | ||
ExpectedConditions.elementToBeClickable( | ||
AppiumBy.id("org.wikipedia.alpha:id/search_src_text") | ||
) | ||
); | ||
driver, | ||
Duration.ofSeconds(30)) | ||
.until( | ||
ExpectedConditions.elementToBeClickable( | ||
AppiumBy.id("org.wikipedia.alpha:id/search_src_text"))); | ||
insertTextElement.sendKeys("BrowserStack"); | ||
Thread.sleep(5000); | ||
|
||
List<WebElement> allProductsName = driver.findElements( | ||
AppiumBy.className("android.widget.TextView") | ||
); | ||
AppiumBy.className("android.widget.TextView")); | ||
assert (allProductsName.size() > 0); | ||
|
||
// Invoke driver.quit() after the test is done to indicate that the test is completed. | ||
// Invoke driver.quit() after the test is done to indicate that the test is | ||
// completed. | ||
driver.quit(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,11 @@ | |
import com.browserstack.local.Local; | ||
import io.appium.java_client.AppiumBy; | ||
import io.appium.java_client.android.AndroidDriver; | ||
import io.appium.java_client.android.options.UiAutomator2Options; | ||
import java.net.URL; | ||
import java.time.Duration; | ||
import java.util.*; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.remote.*; | ||
import org.openqa.selenium.support.ui.*; | ||
|
||
public class BrowserStackSampleLocal { | ||
|
@@ -18,7 +18,7 @@ public class BrowserStackSampleLocal { | |
|
||
public static void setupLocal() throws Exception { | ||
localInstance = new Local(); | ||
Map<String, String> options = new HashMap<String, String>(); | ||
HashMap<String, String> options = new HashMap<String, String>(); | ||
options.put("key", accessKey); | ||
options.put("local", "true"); | ||
localInstance.start(options); | ||
|
@@ -32,7 +32,7 @@ public static void main(String[] args) throws Exception { | |
// Start the BrowserStack Local binary | ||
setupLocal(); | ||
|
||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
UiAutomator2Options options = new UiAutomator2Options(); | ||
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>(); | ||
|
||
// Set your access credentials | ||
|
@@ -43,53 +43,46 @@ public static void main(String[] args) throws Exception { | |
browserstackOptions.put("appiumVersion", "1.22.0"); | ||
browserstackOptions.put("projectName", "First Java Project"); | ||
browserstackOptions.put("buildName", "browserstack-build-1"); | ||
browserstackOptions.put("sessionName", "local_test"); | ||
browserstackOptions.put("sessionName", "BStack local_test"); | ||
|
||
// Set the browserstack.local capability to true | ||
browserstackOptions.put("local", "true"); | ||
|
||
// Passing browserstack capabilities inside bstack:options | ||
capabilities.setCapability("bstack:options", browserstackOptions); | ||
options.setCapability("bstack:options", browserstackOptions); | ||
|
||
// Set URL of the application under test | ||
capabilities.setCapability("app", "bs://<app-id>"); | ||
options.setCapability("app", "bs://<app-id>"); | ||
|
||
// Specify device and os_version for testing | ||
capabilities.setCapability("deviceName", "Google Pixel 3"); | ||
capabilities.setCapability("platformName", "android"); | ||
capabilities.setCapability("platformVersion", "9.0"); | ||
options.setCapability("deviceName", "Google Pixel 3"); | ||
options.setCapability("platformName", "android"); | ||
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. Above comment applies here too. |
||
options.setCapability("platformVersion", "9.0"); | ||
|
||
// Initialise the remote Webdriver using BrowserStack remote URL | ||
// and desired capabilities defined above | ||
AndroidDriver driver = new AndroidDriver( | ||
new URL("http://hub.browserstack.com/wd/hub"), | ||
capabilities | ||
); | ||
new URL("http://hub.browserstack.com/wd/hub"), | ||
options); | ||
|
||
// Test case for the BrowserStack sample Android Local app. | ||
// If you have uploaded your app, update the test case here. | ||
WebElement searchElement = new WebDriverWait(driver, Duration.ofSeconds(30)) | ||
.until( | ||
ExpectedConditions.elementToBeClickable( | ||
AppiumBy.id("com.example.android.basicnetworking:id/test_action") | ||
) | ||
); | ||
.until( | ||
ExpectedConditions.elementToBeClickable( | ||
AppiumBy.id("com.example.android.basicnetworking:id/test_action"))); | ||
searchElement.click(); | ||
|
||
WebElement insertTextElement = (WebElement) new WebDriverWait( | ||
driver, | ||
Duration.ofSeconds(30) | ||
) | ||
.until( | ||
ExpectedConditions.elementToBeClickable( | ||
AppiumBy.className("android.widget.TextView") | ||
) | ||
); | ||
driver, | ||
Duration.ofSeconds(30)) | ||
.until( | ||
ExpectedConditions.elementToBeClickable( | ||
AppiumBy.className("android.widget.TextView"))); | ||
|
||
WebElement testElement = null; | ||
List<WebElement> allTextViewElements = driver.findElements( | ||
AppiumBy.className("android.widget.TextView") | ||
); | ||
AppiumBy.className("android.widget.TextView")); | ||
Thread.sleep(10); | ||
for (WebElement textElement : allTextViewElements) { | ||
if (textElement.getText().contains("The active connection is")) { | ||
|
@@ -105,7 +98,8 @@ public static void main(String[] args) throws Exception { | |
assert (matchedString.contains("The active connection is wifi")); | ||
assert (matchedString.contains("Up and running")); | ||
|
||
// Invoke driver.quit() after the test is done to indicate that the test is completed. | ||
// Invoke driver.quit() after the test is done to indicate that the test is | ||
// completed. | ||
driver.quit(); | ||
|
||
// Stop the BrowserStack Local binary | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Mutuable Caps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been discussed with product team and @francisf and we decided to use Options.
Mutuable caps are not needed here, for android and ios separate folders are present because a single script cannot be used for both ios and android automation.