Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions Appium/Activities/Activity1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package Activity;

import static org.testng.Assert.assertEquals;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import javax.xml.crypto.URIReferenceException;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;

public class Activity1Test {

//Declare Appium driver
AppiumDriver driver ;

//Setup function
@BeforeClass
public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException {
// Desired Capabilities
UiAutomator2Options options = new UiAutomator2Options();
options.setPlatformName("android");
options.setAutomationName("UiAutomator2");
options.setAppPackage("com.google.android.calculator");
options.setAppActivity("com.android.calculator2.Calculator");
// options.setApp("path/to/.apk");
options.noReset();


//Server URL
URL serverURL = new URI("http://localhost:4723").toURL();

//Initialize the driver
driver = new AndroidDriver(serverURL, options);
}
//Test Function
@Test
public void multiplicationTest() {
//Find digit 5 and tap it
driver.findElement(AppiumBy.id("digit_5")).click();
//Find plus symbol and tap it
driver.findElement(AppiumBy.accessibilityId("multiply")).click();
//Find digit 2 and tap it
driver.findElement(AppiumBy.id("digit_2")).click();
//Find equals symbol and tap it
driver.findElement(AppiumBy.accessibilityId("equals")).click();

//Assertions
String result = driver.findElement(AppiumBy.id("result_final")).getText();
assertEquals(result,"10");
}


//Tear down function
@AfterClass
public void tearDown() {
// Close the app

driver.quit();
}

}
76 changes: 76 additions & 0 deletions Appium/Activities/Activity2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package Activity;


import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import javax.xml.crypto.URIReferenceException;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;

public class Activity2 {
//Declare Appium driver
AppiumDriver driver ;

//Setup function
@BeforeClass
public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException {
// Desired Capabilities
UiAutomator2Options options = new UiAutomator2Options();
options.setPlatformName("android");
options.setAutomationName("UiAutomator2");
options.setAppPackage("com.android.chrome");
options.setAppActivity("com.google.android.apps.chrome.Main");
// options.setApp("path/to/.apk");
options.noReset();


//Server URL

URL serverURL = new URI("http://localhost:4723").toURL();

//Initialize the driver
driver = new AndroidDriver(serverURL, options);

// Open the browser with the URL- https://training-support.net
driver.get("https://training-support.net");


}
//Test Function
@Test
public void displayPageHeading() {

// Locate heading on page and print it
String pageTitle = driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text='Training Support']")).getText();
System.out.println("Heading: " + pageTitle);

// Find and click the About Us link
driver.findElement(AppiumBy.accessibilityId("About Us")).click();

// Find heading of new page and print to console
String aboutPageHeading = driver.findElement(AppiumBy.xpath(
"//android.widget.TextView[@text='About Us']"
)).getText();
System.out.println(aboutPageHeading);


}

//Tear down function
@AfterClass
public void tearDown() {
// Close the app

driver.quit();
}
}
119 changes: 119 additions & 0 deletions Appium/Activities/Activity3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package Activity;

import static org.testng.Assert.assertEquals;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import javax.xml.crypto.URIReferenceException;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;

public class Activity3 {
//Declare Appium driver
AppiumDriver driver ;

//Setup function
@BeforeClass
public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException {
// Desired Capabilities
UiAutomator2Options options = new UiAutomator2Options();
options.setPlatformName("android");
options.setAutomationName("UiAutomator2");
options.setAppPackage("com.google.android.calculator");
options.setAppActivity("com.android.calculator2.Calculator");
// options.setApp("path/to/.apk");
options.noReset();


//Server URL
URL serverURL = new URI("http://localhost:4723").toURL();

//Initialize the driver
driver = new AndroidDriver(serverURL, options);
}

//Test Function
@Test (priority=1)
public void additionTest() {
//Find digit 5 and tap it
driver.findElement(AppiumBy.id("digit_5")).click();
//Find plus symbol and tap it
driver.findElement(AppiumBy.accessibilityId("plus")).click();
//Find digit 9 and tap it
driver.findElement(AppiumBy.id("digit_9")).click();
//Find equals symbol and tap it
driver.findElement(AppiumBy.accessibilityId("equals")).click();
//Assertions
String result = driver.findElement(AppiumBy.id("result_final")).getText();
assertEquals(result,"14");
}
//Test Function
@Test(priority=2)
public void subtractionTest() {
//Find digit 10 and tap it
driver.findElement(AppiumBy.id("digit_1")).click();
driver.findElement(AppiumBy.id("digit_0")).click();
//Find plus symbol and tap it
driver.findElement(AppiumBy.accessibilityId("minus")).click();
//Find digit 5 and tap it
driver.findElement(AppiumBy.id("digit_5")).click();
//Find equals symbol and tap it
driver.findElement(AppiumBy.accessibilityId("equals")).click();
//Assertions
String result = driver.findElement(AppiumBy.id("result_final")).getText();
assertEquals(result,"5");
}
//Test Function
@Test(priority=3)
public void multiplicationTest() {
//Find digit 5 and tap it
driver.findElement(AppiumBy.id("digit_5")).click();
//Find plus symbol and tap it
driver.findElement(AppiumBy.accessibilityId("multiply")).click();
//Find digit 100 and tap it
driver.findElement(AppiumBy.id("digit_1")).click();
driver.findElement(AppiumBy.id("digit_0")).click();
driver.findElement(AppiumBy.id("digit_0")).click();
//Find equals symbol and tap it
driver.findElement(AppiumBy.accessibilityId("equals")).click();
//Assertions
String result = driver.findElement(AppiumBy.id("result_final")).getText();
assertEquals(result,"500");
}
//Test Function
@Test(priority=4)
public void divisionTest() {
//Find digit 50 and tap it
driver.findElement(AppiumBy.id("digit_5")).click();
driver.findElement(AppiumBy.id("digit_0")).click();
//Find plus symbol and tap it
driver.findElement(AppiumBy.accessibilityId("divide")).click();
//Find digit 2 and tap it
driver.findElement(AppiumBy.id("digit_2")).click();
//Find equals symbol and tap it
driver.findElement(AppiumBy.accessibilityId("equals")).click();
//Assertions
String result = driver.findElement(AppiumBy.id("result_final")).getText();
assertEquals(result,"25");
}


//Tear down function
@AfterClass
public void tearDown() {
// Close the app

driver.quit();
}

}
86 changes: 86 additions & 0 deletions Appium/Activities/Activity4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package Activity;

import static org.testng.Assert.assertEquals;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.Duration;

import javax.xml.crypto.URIReferenceException;

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;

public class Activity4 {
//Declare Appium driver
AppiumDriver driver ;
WebDriverWait wait;

//Setup function
@BeforeClass
public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException {
// Desired Capabilities
UiAutomator2Options options = new UiAutomator2Options();
options.setPlatformName("android");
options.setAutomationName("UiAutomator2");
options.setAppPackage("com.google.android.contacts");
options.setAppActivity("com.google.android.apps.contacts.quickcontact.QuickContactActivity");
// options.setApp("path/to/.apk");
options.noReset();

//Server URL
URL serverURL = new URI("http://localhost:4723").toURL();

//Initialize the driver
driver = new AndroidDriver(serverURL, options);
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
//Test Function
@Test
public void addNewContact() {
//Find and click the button to add a new contact.
driver.findElement(AppiumBy.accessibilityId("Phone")).click();
driver.findElement(AppiumBy.accessibilityId("Create new contact")).click();


// Wait for elements to load
wait.until(ExpectedConditions.elementToBeClickable(
AppiumBy.xpath("//android.widget.EditText[@text='First name']")
));

driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text='First name']")).sendKeys("Aaditya");
driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text='Last name']")).sendKeys("Varma");
driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text='Phone']")).sendKeys("999148292");
driver.findElement(AppiumBy.id("com.google.android.contacts:id/toolbar_button")).click();


//Assertions

wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("large_title")));

// Assertion
String contactName = driver.findElement(AppiumBy.id("large_title")).getText();
Assert.assertEquals(contactName, "Aaditya Varma");
}


//Tear down function
@AfterClass
public void tearDown() {
// Close the app

driver.quit();
}

}
Loading