-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
3 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
44 changes: 44 additions & 0 deletions
44
src/test/java/com/github/aceton41k/mobile/AppiumTests.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,44 @@ | ||
package com.github.aceton41k.mobile; | ||
|
||
import com.github.aceton41k.mobile.page.LoginPage; | ||
import io.appium.java_client.AppiumBy; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
|
||
public class AppiumTests extends BaseTestAndroid { | ||
|
||
@Test | ||
public void androidTest() { | ||
|
||
LoginPage loginPage = new LoginPage(driver); | ||
assertTrue(loginPage.isPageLoaded()); | ||
loginPage.login(); | ||
|
||
|
||
wait.until(webDriver -> | ||
webDriver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"Posts\")"))); | ||
|
||
WebElement recyclerView = driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().resourceId(\"com.github.aceton41k.simpleapp:id/recycler_view\")")); | ||
|
||
List<WebElement> linearLayouts = recyclerView.findElements(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.widget.LinearLayout\")")); | ||
assertEquals(linearLayouts.size(), 6); | ||
|
||
WebElement menu = driver.findElement(AppiumBy.accessibilityId("Open navigation drawer")); | ||
menu.click(); | ||
wait.until( | ||
ExpectedConditions.visibilityOf( | ||
driver.findElement( | ||
AppiumBy.androidUIAutomator("new UiSelector().text(\"Android Studio\")")))); | ||
driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"Android Studio\")")); | ||
|
||
|
||
driver.quit(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/com/github/aceton41k/mobile/BaseTestAndroid.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,30 @@ | ||
package com.github.aceton41k.mobile; | ||
|
||
import io.appium.java_client.android.AndroidDriver; | ||
import io.appium.java_client.android.options.UiAutomator2Options; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
import org.testng.annotations.BeforeClass; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.time.Duration; | ||
|
||
public class BaseTestAndroid extends BaseTestMobile { | ||
|
||
@BeforeClass | ||
public void setUp() throws URISyntaxException, MalformedURLException { | ||
UiAutomator2Options options = new UiAutomator2Options(); | ||
options | ||
.setAppPackage("com.github.aceton41k.simpleapp") | ||
.setAppActivity(".activity.LoginActivity") | ||
.setPlatformVersion("12") | ||
.setDeviceName("emulator-5554") | ||
.setPlatformName("Android") | ||
.noReset(); | ||
|
||
driver = new AndroidDriver(new URI("http://192.168.0.200:4723").toURL(), options); | ||
driver.activateApp("com.github.aceton41k.simpleapp"); | ||
wait = new WebDriverWait(driver, Duration.ofSeconds(10)); // 10 секунд ожидания | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/java/com/github/aceton41k/mobile/BaseTestMobile.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,19 @@ | ||
package com.github.aceton41k.mobile; | ||
|
||
import io.appium.java_client.android.AndroidDriver; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
import org.testng.annotations.BeforeClass; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URISyntaxException; | ||
|
||
public class BaseTestMobile { | ||
|
||
AndroidDriver driver; | ||
WebDriverWait wait; | ||
|
||
@BeforeClass | ||
public void setUp() throws URISyntaxException, MalformedURLException { | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/java/com/github/aceton41k/mobile/page/BasePage.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,16 @@ | ||
package com.github.aceton41k.mobile.page; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
import java.time.Duration; | ||
|
||
public class BasePage { | ||
WebDriver driver; | ||
WebDriverWait wait; | ||
|
||
public BasePage(WebDriver driver) { | ||
this.driver = driver; | ||
wait = new WebDriverWait(driver, Duration.ofSeconds(10)); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/github/aceton41k/mobile/page/LoginPage.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,51 @@ | ||
package com.github.aceton41k.mobile.page; | ||
|
||
import org.openqa.selenium.TimeoutException; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.PageFactory; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
|
||
public class LoginPage extends BasePage { | ||
@FindBy(xpath = "//android.widget.EditText[@resource-id=\"email_input\"]") | ||
WebElement email; | ||
|
||
@FindBy(xpath = "//android.widget.EditText[@resource-id=\"password_input\"]") | ||
WebElement password; | ||
|
||
@FindBy(xpath = "//android.view.View[@resource-id=\"login_button\"]") | ||
WebElement loginButton; | ||
|
||
public LoginPage(final WebDriver driver) { | ||
super(driver); | ||
PageFactory.initElements(driver, this); | ||
} | ||
|
||
|
||
public void login() { | ||
email.sendKeys("a@a.a"); | ||
password.sendKeys("123456"); | ||
loginButton.click(); | ||
} | ||
|
||
public boolean isPageLoaded() { | ||
try { | ||
wait.until( | ||
ExpectedConditions.visibilityOf( | ||
email)); | ||
|
||
wait.until( | ||
ExpectedConditions.visibilityOf( | ||
password)); | ||
|
||
wait.until( | ||
ExpectedConditions.visibilityOf( | ||
loginButton)); | ||
} catch (TimeoutException _) { | ||
|
||
} | ||
return true; | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ava/com/github/aceton41k/ui/BaseTest.java → ...va/com/github/aceton41k/web/BaseTest.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,4 +1,4 @@ | ||
package com.github.aceton41k.ui; | ||
package com.github.aceton41k.web; | ||
|
||
import org.testng.annotations.BeforeClass; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...java/com/github/aceton41k/ui/UITests.java → ...ava/com/github/aceton41k/web/UITests.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