Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit b092ce1

Browse files
committed
Add appium tests.
1 parent 57a56d7 commit b092ce1

File tree

8 files changed

+96
-27
lines changed

8 files changed

+96
-27
lines changed

‎Contacts/ContactCell.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ - (void)setContactIcon:(UIImage *)contactIcon
4040

4141
- (void)setContact:(Contact *)contact
4242
{
43-
if (contact != _contact) {
44-
_contact = contact;
45-
46-
self.contactName = [NSString stringWithFormat:@"%@ %@", contact.firstName, contact.lastName];
47-
self.contactIcon = contact.icon;
48-
}
43+
_contact = contact;
44+
45+
self.contactName = [NSString stringWithFormat:@"%@ %@", contact.firstName, contact.lastName];
46+
self.contactIcon = contact.icon;
4947
}
5048

5149
@end

‎Contacts/ContactDetailsViewController.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ - (void)viewDidLoad
2424

2525
// Update screen
2626
self.contact = self.contact;
27+
28+
self.view.accessibilityIdentifier = @"com.vc.contactDetails";
29+
self.contactNameLabel.accessibilityIdentifier = @"com.label.contactDetails";
2730
}
2831

2932
- (void)setContact:(Contact *)contact

‎Contacts/ContactsListViewController.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ - (void)viewDidLoad
2525
[super viewDidLoad];
2626

2727
self.navigationItem.leftBarButtonItem = self.editButtonItem;
28+
29+
self.view.accessibilityIdentifier = @"com.vc.contactsList";
30+
}
31+
32+
- (void)viewWillAppear:(BOOL)animated
33+
{
34+
[super viewWillAppear:animated];
35+
36+
[self.tableView reloadData];
2837
}
2938

3039
#pragma mark - Accessors
@@ -69,6 +78,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
6978
{
7079
ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
7180
cell.contact = self.contacts[indexPath.row];
81+
cell.isAccessibilityElement = YES;
82+
cell.accessibilityIdentifier = @"com.cell.contactsList";
7283

7384
return cell;
7485
}

‎Contacts/EditContactDetailsViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ - (void)viewDidLoad
3434
self.firstNameTextField.text = self.contact.firstName;
3535
self.lastNameTextField.text = self.contact.lastName;
3636
}
37+
38+
self.view.accessibilityIdentifier = @"com.vc.contactsEdit";
39+
40+
self.firstNameTextField.accessibilityIdentifier = @"com.textfield.firstName";
41+
self.lastNameTextField.accessibilityIdentifier = @"com.textfield.lastName";
3742
}
3843

3944
- (void)viewWillDisappear:(BOOL)animated

‎appium/features/add_contact.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: Create a new contact in the contacts list
66

77
@s1 @add_action
88
Scenario: User can add a new contact in the contacts list
9-
Given I see the contact list screen
9+
Given I see the contacts list screen
1010
When I press on "Add" button
1111
Then The screen "Edit Contact Details" appears
1212
And I enter "Jon" in the "first name" textfield

‎appium/features/remove_contact.feature

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ Feature: Remove an existing contact from the contacts list
66

77
@s1 @remove_action
88
Scenario: User can remove an existing contact from the contacts list
9-
Given I see the contact list screen
9+
Given I see the contacts list screen
1010
Given I see at least one contact in the list
11-
When I press on "Add" button
12-
Then The screen "Edit Contact Details" appears
13-
And I enter "Jon" in the "first name" textfield
14-
And I enter "Snow" in the "last name" textfield
15-
When I press on "Done" button
16-
Then I see the "Jon Snow" contact in the contact list
11+
When I press on "Edit" button
12+
And I remove the first contact
13+
Then Contacts list is empty
1714

1815

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,86 @@
1-
Given(/^I see the contact list screen$/) do
2-
pending # Write code here that turns the phrase above into concrete actions
1+
############
2+
# Helpers
3+
############
4+
5+
def keyboard_visible?
6+
keyboard = execute_script "UIATarget.localTarget().frontMostApp().keyboard()"
7+
return keyboard != ""
8+
end
9+
10+
def keyboard_type_string string
11+
execute_script "UIATarget.localTarget().frontMostApp().keyboard().typeString(\"#{string}\")"
12+
end
13+
14+
############
15+
# Steps
16+
############
17+
18+
Given(/^I see the contacts list screen$/) do
19+
step "The screen \"Contacts List\" appears"
320
end
421

522
When(/^I press on "([^"]*)" button$/) do |arg1|
6-
pending# Write code here that turns the phrase above into concrete actions
23+
wait{button(arg1).click}
724
end
825

9-
Then(/^The screen "([^"]*)" appears$/) do |arg1|
10-
pending # Write code here that turns the phrase above into concrete actions
26+
Then(/^The screen "([^"]*)" appears$/) do |screen|
27+
case screen
28+
when "Edit Contact Details"
29+
wait { find("com.vc.contactsEdit") }
30+
when "Contacts List"
31+
wait { find("com.vc.contactsList") }
32+
when "Contact Details"
33+
wait { find("com.vc.contactDetails") }
34+
end
1135
end
1236

13-
Then(/^I enter "([^"]*)" in the "([^"]*)" textfield$/) do |arg1, arg2|
14-
pending # Write code here that turns the phrase above into concrete actions
37+
Then(/^I enter "([^"]*)" in the "([^"]*)" textfield$/) do |arg1, text_field_name|
38+
39+
text_field_id = nil
40+
case text_field_name
41+
when "first name"
42+
text_field_id = "com.textfield.firstName"
43+
when "last name"
44+
text_field_id = "com.textfield.lastName"
45+
end
46+
47+
text_field = nil
48+
wait { text_field = textfield(text_field_id) }
49+
set_immediate_value(text_field, "")
50+
text_field.click
51+
wait_true { keyboard_visible?() }
52+
keyboard_type_string(arg1)
1553
end
1654

1755
Then(/^I see the "([^"]*)" contact in the contact list$/) do |arg1|
18-
pending # Write code here that turns the phrase above into concrete actions
56+
cell = nil
57+
wait { cell = find_ele_by_attr("UIATableCell", "label", arg1) }
58+
expect(cell.name()).to eq("com.cell.contactsList")
1959
end
2060

2161
Given(/^I see at least one contact in the list$/) do
22-
pending # Write code here that turns the phrase above into concrete actions
62+
step "I press on \"Add\" button"
63+
step "I enter \"Jon\" in the \"first name\" textfield"
64+
step "I enter \"Snow\" in the \"last name\" textfield"
65+
step "I press on \"Done\" button"
66+
expect(tags("UIATableCell").length()).to eq(1)
2367
end
2468

2569
When(/^I press on first contact$/) do
26-
pending# Write code here that turns the phrase above into concrete actions
70+
wait{tags("UIATableCell")[0].click}
2771
end
2872

2973
Then(/^I see the "([^"]*)" contact in the contact details$/) do |arg1|
30-
pending # Write code here that turns the phrase above into concrete actions
74+
label = nil
75+
wait { label = find_ele_by_attr("UIAStaticText", "label", arg1) }
76+
expect(label.name()).to eq("com.label.contactDetails")
77+
end
78+
79+
When(/^I remove the first contact$/) do
80+
wait { find_eles_by_attr("UIAButton", "hint", "Double tap to delete item")[0].click }
81+
wait { button("Delete").click }
82+
end
83+
84+
Then(/^Contacts list is empty$/) do
85+
expect(tags("UIATableCell").length()).to eq(0)
3186
end

‎appium/features/update_contact.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
@update_contact
22
Feature: Update an existing contact in the contacts list
3-
In order to keep all my contact up-to-date
3+
In order to keep all my contacts up-to-date
44
As I user
55
I want to update an existing contact in my contacts list
66

77
@s1 @update_action
88
Scenario: User can update an existing contact in the contacts list
9-
Given I see the contact list screen
9+
Given I see the contacts list screen
1010
Given I see at least one contact in the list
1111
When I press on first contact
1212
Then The screen "Contact Details" appears

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /