-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidContactsTest.java
More file actions
160 lines (132 loc) · 6.18 KB
/
AndroidContactsTest.java
File metadata and controls
160 lines (132 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.testing.example;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
* This test class automate few scenario for android contacts app.
* Use TestNG to run this class or you can unit testing framework also.
*
*/
public class AndroidContactsTest {
private WebDriver driver;
@BeforeMethod
public void setUp() throws Exception {
// set up appium
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.3");
capabilities.setCapability(CapabilityType.PLATFORM, "Windows");
capabilities.setCapability("app-package", "com.android.contacts"); // This is package name of your app (you can get it from apk info app)
capabilities.setCapability("app-activity", "com.android.contacts.activities.PeopleActivity"); // This is Launcher activity of your app (you can get it from apk info app)
// Create RemoteWebDriver instance and connect to the Appium server.
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
// this test case should used when we are adding contact to app for first time.
@Test
public void addContact() throws InterruptedException{
WebElement el = driver.findElement(By.name("Create a new contact"));
el.click();
Thread.sleep(5000);
List<WebElement> textFieldsList = driver.findElements(By.tagName("textfield"));
textFieldsList.get(0).sendKeys("Some Name");
textFieldsList.get(2).sendKeys("Some@example.com");
driver.findElement(By.name("Done")).click();
driver.findElements(By.tagName("ImageView")).get(0).click();
}
//Use when the app has one or more contacts already
@Test
public void addContact2() throws InterruptedException{
WebElement el = driver.findElement(By.name("New"));
el.click();
List<WebElement> textFieldsList = driver.findElements(By.tagName("textfield"));
textFieldsList.get(0).sendKeys("John Paul");
textFieldsList.get(2).sendKeys("johnpaul@gmail.com");
driver.findElement(By.name("Done")).click();
driver.findElements(By.tagName("ImageView")).get(0).click();
}
@Test
public void testSearchContact()
{
WebElement el = driver.findElement(By.name("Search"));
el.click();
driver.findElement(By.name("Search query")).sendKeys("Some");
driver.findElement(By.name("Some Name"));
}
@Test
public void testClearTextInSearch()
{
WebElement el = driver.findElement(By.name("Search"));
el.click();
//enters text to search field
driver.findElement(By.name("Search query")).sendKeys("Ajit");
//clears the text from search field
driver.findElement(By.name("Clear query")).click();
driver.findElement(By.name("Some Name"));
}
@Test
public void testDeleteContact() throws IOException, InterruptedException{
WebElement el = driver.findElement(By.name("Search"));
el.click();
driver.findElement(By.name("Search query")).sendKeys("John");
driver.findElement(By.name("John Paul")).click();
// to send menu key
Process p = Runtime.getRuntime().exec("adb shell input keyevent 82");
p.waitFor();
driver.findElement(By.name("Delete")).click();
driver.findElement(By.name("OK")).click();
driver.findElements(By.name("John Paul"));
}
//to view contacts names by last name
@Test
public void testViewContactsNamesByLastName() throws IOException, InterruptedException
{
// to send menu key
Process p = Runtime.getRuntime().exec("adb shell input keyevent 82");
p.waitFor();
driver.findElement(By.name("Settings")).click();
driver.findElement(By.name("View contact names as")).click();
driver.findElement(By.name("Last name first")).click();
driver.findElements(By.tagName("ImageView")).get(0).click();
driver.findElement(By.name("Search")).click();
driver.findElement(By.name("Search query")).sendKeys("Some");
driver.findElement(By.name("Name, Some"));
Process p1 = Runtime.getRuntime().exec("adb shell input keyevent 82");
p1.waitFor();
driver.findElement(By.name("Settings")).click();
driver.findElement(By.name("View contact names as")).click();
driver.findElement(By.name("First name first")).click();
driver.findElement(By.name("Some Name"));
}
// to edit contact and add mobile number to it.
@Test
public void testEditContactAddMobileNumber() throws IOException, InterruptedException
{
driver.findElement(By.name("Some Name")).click();
Process p = Runtime.getRuntime().exec("adb shell input keyevent 82");
p.waitFor();
driver.findElement(By.name("Edit")).click();
driver.findElement(By.name("Add another field")).click();
driver.findElement(By.name("Phone")).click();
driver.findElement(By.name("Mobile")).click();
driver.findElements(By.tagName("CheckedTextView")).get(0).click();
driver.findElement(By.name("Phone")).sendKeys("1234567890");
driver.findElement(By.name("Done")).click();
driver.findElement(By.name("1 234-567-890"));
driver.findElements(By.tagName("ImageView")).get(0).click();
}
}