-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#149 refactor API for switching context in mobile app
* instead of `setContext("WEBVIEW_com.saucelabs.mydemoapp.rn")`, * we will have `switchTo().context("WEBVIEW_com.saucelabs.mydemoapp.rn")`
- Loading branch information
Showing
3 changed files
with
19 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 13 additions & 6 deletions
19
modules/appium/src/main/java/com/codeborne/selenide/appium/SelenideAppiumTargetLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
package com.codeborne.selenide.appium; | ||
|
||
import com.codeborne.selenide.WebDriverRunner; | ||
import com.codeborne.selenide.Driver; | ||
import com.codeborne.selenide.logevents.SelenideLogger; | ||
import org.openqa.selenium.ContextAware; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.util.Set; | ||
|
||
@ParametersAreNonnullByDefault | ||
public class SelenideAppiumTargetLocator { | ||
private final Driver driver; | ||
|
||
public void setContext(String contextName) { | ||
SelenideAppiumTargetLocator(Driver driver) { | ||
this.driver = driver; | ||
} | ||
|
||
public void context(String contextName) { | ||
SelenideLogger.run("set context", contextName, () -> { | ||
(WebdriverUnwrapper.cast(WebDriverRunner.getWebDriver(), ContextAware.class)) | ||
WebdriverUnwrapper.cast(driver, ContextAware.class) | ||
.map(contextAware -> contextAware.context(contextName)) | ||
.orElseThrow(() -> new UnsupportedOperationException("Context not found" + contextName)); | ||
}); | ||
} | ||
|
||
public Set<String> getContextHandles() { | ||
return (WebdriverUnwrapper.cast(WebDriverRunner.getWebDriver(), ContextAware.class)) | ||
return WebdriverUnwrapper.cast(driver, ContextAware.class) | ||
.map(ContextAware::getContextHandles) | ||
.orElseThrow(() -> new UnsupportedOperationException("Cannot get contexts from mobile driver")); | ||
} | ||
|
||
public String getCurrentContext() { | ||
return (WebdriverUnwrapper.cast(WebDriverRunner.getWebDriver(), ContextAware.class)) | ||
return WebdriverUnwrapper.cast(driver, ContextAware.class) | ||
.map(ContextAware::getContext) | ||
.orElseThrow(() -> new UnsupportedOperationException("Cannot get contexts from mobile driver")); | ||
.orElseThrow(() -> new UnsupportedOperationException("Cannot get current context from mobile driver")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters