Skip to content

Commit 612fd51

Browse files
committed
My first java + appium commit
0 parents  commit 612fd51

File tree

10 files changed

+221
-0
lines changed

10 files changed

+221
-0
lines changed

.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>qa-univa-appium</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<dependencies>
11+
<dependency>
12+
<groupId>io.appium</groupId>
13+
<artifactId>java-client</artifactId>
14+
<version>9.3.0</version>
15+
</dependency>
16+
<dependency>
17+
<groupId>org.seleniumhq.selenium</groupId>
18+
<artifactId>selenium-java</artifactId>
19+
<version>4.23.0</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>junit</groupId>
23+
<artifactId>junit</artifactId>
24+
<version>4.13.2</version>
25+
<scope>test</scope>
26+
</dependency>
27+
</dependencies>
28+
<properties>
29+
<maven.compiler.source>22</maven.compiler.source>
30+
<maven.compiler.target>22</maven.compiler.target>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
</properties>
33+
34+
</project>
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package e2e.pages;
2+
3+
import io.appium.java_client.AppiumDriver;
4+
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
5+
import org.openqa.selenium.WebElement;
6+
import org.openqa.selenium.support.PageFactory;
7+
import org.openqa.selenium.support.ui.WebDriverWait;
8+
9+
import java.time.Duration;
10+
11+
public class BaseActions {
12+
13+
protected AppiumDriver driver;
14+
15+
public BaseActions (AppiumDriver driver) {
16+
this.driver = driver;
17+
PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(30)), this);
18+
}
19+
20+
public boolean isElementDisplayed(WebElement element) {
21+
return element.isDisplayed();
22+
}
23+
24+
25+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package e2e.pages;
2+
3+
import io.appium.java_client.AppiumBy;
4+
import io.appium.java_client.AppiumDriver;
5+
import io.appium.java_client.pagefactory.AndroidFindBy;
6+
import org.openqa.selenium.WebElement;
7+
8+
public class CatalogScreen extends BaseActions {
9+
@AndroidFindBy(xpath = "//android.widget.TextView[contains(@text, 'PRODUCTS')]")
10+
private WebElement catalogHeader;
11+
12+
13+
public CatalogScreen (AppiumDriver driver){
14+
super(driver);
15+
}
16+
17+
public WebElement getCatalogHeader () {
18+
return this.catalogHeader;
19+
}
20+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package e2e.pages;
2+
3+
import io.appium.java_client.AppiumBy;
4+
import io.appium.java_client.AppiumDriver;
5+
import io.appium.java_client.pagefactory.AndroidFindBy;
6+
import org.openqa.selenium.WebElement;
7+
8+
public class LoginScreen extends BaseActions {
9+
@AndroidFindBy(accessibility = "test-Username")
10+
private WebElement userInput;
11+
12+
@AndroidFindBy(xpath = "//*[@*='test-Password']")
13+
protected WebElement passwordInput;
14+
15+
@AndroidFindBy(xpath = "//*[@text='LOGIN']")
16+
protected WebElement loginButton;
17+
18+
public LoginScreen (AppiumDriver driver) {
19+
super(driver);
20+
}
21+
22+
public void enterUserLogin(String username, String password) {
23+
userInput.sendKeys(username);
24+
passwordInput.sendKeys(password);
25+
loginButton.click();
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package e2e.tests.login;
2+
3+
import e2e.pages.CatalogScreen;
4+
import e2e.pages.LoginScreen;
5+
import e2e.utils.BaseConfig;
6+
import org.junit.Test;
7+
8+
public class LoginTests extends BaseConfig {
9+
10+
@Test
11+
public void userLogin (){
12+
LoginScreen loginScreen = new LoginScreen(driver);
13+
loginScreen.enterUserLogin("standard_user", "secret_sauce");
14+
15+
CatalogScreen catalogScreen = new CatalogScreen(driver);
16+
assert catalogScreen.isElementDisplayed(catalogScreen.getCatalogHeader());
17+
}
18+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package e2e.utils;
2+
3+
import io.appium.java_client.AppiumDriver;
4+
import io.appium.java_client.android.options.UiAutomator2Options;
5+
import org.junit.After;
6+
import org.junit.Before;
7+
8+
import java.net.MalformedURLException;
9+
import java.net.URL;
10+
11+
public class BaseConfig {
12+
13+
protected AppiumDriver driver;
14+
15+
@Before
16+
public void setUp() throws MalformedURLException {
17+
UiAutomator2Options androidOptions = new UiAutomator2Options();
18+
URL url = new URL("http://127.0.0.1:4723/wd/hub");
19+
20+
androidOptions.setAutomationName("UIAutomator2");
21+
androidOptions.setPlatformName("Android");
22+
androidOptions.setPlatformVersion("14");
23+
androidOptions.setDeviceName("Pixel 5");
24+
androidOptions.setAppActivity("com.swaglabsmobileapp.MainActivity");
25+
androidOptions.setAppPackage("com.swaglabsmobileapp");
26+
androidOptions.setApp("/Users/eduardo.contreras/Downloads/Android.SauceLabs.Mobile.Sample.app.2.7.1.apk");
27+
28+
driver = new AppiumDriver(url, androidOptions);
29+
}
30+
31+
@After
32+
public void tearDown(){
33+
driver.quit();
34+
}
35+
}

0 commit comments

Comments
 (0)