-
-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #556 from TikhomirovSergey/master
#552 FIX
- Loading branch information
Showing
12 changed files
with
347 additions
and
93 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
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
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
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
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
42 changes: 42 additions & 0 deletions
42
src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.appium.java_client.appium.element.generation; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import io.appium.java_client.AppiumDriver; | ||
import io.appium.java_client.service.local.AppiumServiceBuilder; | ||
import org.junit.After; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
|
||
import java.util.function.BiPredicate; | ||
import java.util.function.Supplier; | ||
|
||
public class BaseElementGenerationTest { | ||
protected AppiumDriver<?> driver; | ||
protected final BiPredicate<By, Class<? extends WebElement>> commonPredicate = (by, aClass) -> { | ||
WebElement element = driver.findElement(by); | ||
assertTrue(element.getClass().equals(aClass)); | ||
return true; | ||
}; | ||
|
||
@After | ||
public void tearDown() { | ||
if (driver != null) { | ||
driver.quit(); | ||
} | ||
driver = null; | ||
} | ||
|
||
protected boolean check(Supplier<DesiredCapabilities> serverCapabilitiesSupplier, | ||
Supplier<Capabilities> clientCapabilitiesSupplier, | ||
BiPredicate<By, Class<? extends WebElement>> filter, | ||
By by, Class<? extends WebElement> clazz) { | ||
AppiumServiceBuilder builder = new AppiumServiceBuilder() | ||
.withCapabilities(serverCapabilitiesSupplier.get()); | ||
driver = new AppiumDriver<>(builder, clientCapabilitiesSupplier.get()); | ||
return filter.test(by, clazz); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.appium.java_client.appium.element.generation.android; | ||
|
||
import static io.appium.java_client.MobileBy.AndroidUIAutomator; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.openqa.selenium.By.className; | ||
import static org.openqa.selenium.By.tagName; | ||
|
||
import io.appium.java_client.android.AndroidElement; | ||
import io.appium.java_client.appium.element.generation.BaseElementGenerationTest; | ||
import io.appium.java_client.remote.AndroidMobileCapabilityType; | ||
import io.appium.java_client.remote.MobileBrowserType; | ||
import io.appium.java_client.remote.MobileCapabilityType; | ||
import io.appium.java_client.remote.MobilePlatform; | ||
import org.junit.Test; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
import org.openqa.selenium.remote.RemoteWebElement; | ||
|
||
import java.io.File; | ||
import java.util.function.Supplier; | ||
|
||
public class AndroidElementGeneratingTest extends BaseElementGenerationTest { | ||
|
||
private final File app = new File(new File("src/test/java/io/appium/java_client"), | ||
"ApiDemos-debug.apk"); | ||
private final Supplier<DesiredCapabilities> serverCapabilitiesSupplier = () -> { | ||
DesiredCapabilities serverCapabilities = new DesiredCapabilities(); | ||
serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); | ||
serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); | ||
serverCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); | ||
return serverCapabilities; | ||
}; | ||
|
||
@Test public void whenAndroidNativeAppIsLaunched() { | ||
assertTrue(check(serverCapabilitiesSupplier, () -> { | ||
DesiredCapabilities clientCapabilities = new DesiredCapabilities(); | ||
clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); | ||
clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); | ||
return clientCapabilities; | ||
}, commonPredicate, AndroidUIAutomator("new UiSelector().clickable(true)"), | ||
AndroidElement.class)); | ||
} | ||
|
||
@Test public void whenAndroidHybridAppIsLaunched() { | ||
assertTrue(check(serverCapabilitiesSupplier, () -> { | ||
DesiredCapabilities clientCapabilities = new DesiredCapabilities(); | ||
clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); | ||
clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); | ||
return clientCapabilities; | ||
}, (by, aClass) -> { | ||
driver.context("WEBVIEW_io.appium.android.apis"); | ||
return commonPredicate.test(by, aClass); | ||
}, tagName("a"), RemoteWebElement.class)); | ||
} | ||
|
||
@Test public void whenAndroidBrowserIsLaunched() { | ||
assertTrue(check(() -> { | ||
DesiredCapabilities serverCapabilities = new DesiredCapabilities(); | ||
serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); | ||
serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); | ||
return serverCapabilities; | ||
}, () -> { | ||
DesiredCapabilities clientCapabilities = new DesiredCapabilities(); | ||
clientCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); | ||
return clientCapabilities; | ||
}, (by, aClass) -> { | ||
driver.get("https://www.google.com"); | ||
return commonPredicate.test(by, aClass); | ||
}, className("gsfi"), RemoteWebElement.class)); | ||
} | ||
} |
Oops, something went wrong.