|
package com.uia.example.my; |
|
|
|
import com.android.uiautomator.core.UiDevice; |
|
import com.android.uiautomator.core.UiObject; |
|
import com.android.uiautomator.core.UiObjectNotFoundException; |
|
import com.android.uiautomator.core.UiScrollable; |
|
import com.android.uiautomator.core.UiSelector; |
|
import com.android.uiautomator.testrunner.UiAutomatorTestCase; |
|
|
|
public class AddPage extends UiAutomatorTestCase { |
|
|
|
private final UiDevice device; |
|
|
|
// locators |
|
UiScrollable contactView = new UiScrollable(new UiSelector() |
|
.className("android.widget.ScrollView")); |
|
UiSelector nameLocator = new UiSelector().className("android.widget.EditText"); |
|
UiSelector photoLocator = new UiSelector().className("android.view.View"); |
|
UiSelector phoneLocator = new UiSelector().className("android.widget.EditText"); |
|
UiSelector emailLocator = new UiSelector().className("android.widget.EditText"); |
|
UiSelector addressLocator = new UiSelector().className("android.widget.EditText"); |
|
|
|
public AddPage(UiDevice device) throws UiObjectNotFoundException { |
|
this.device = device; |
|
|
|
// ensure we're in the right page |
|
UiObject photo = contactView.getChildByDescription(photoLocator, "contact photo"); |
|
if(!photo.exists()) { |
|
fail(); |
|
} |
|
} |
|
|
|
public HomePage create(String name, String phone, String email, String address) throws UiObjectNotFoundException { |
|
typeName(name); |
|
typePhone(phone); |
|
typeEmail(email); |
|
typeAddress(address); |
|
|
|
return new HomePage(device); |
|
} |
|
|
|
private AddPage typeName(String name) throws UiObjectNotFoundException { |
|
UiObject nameField = contactView.getChildByText(nameLocator, "Name"); |
|
nameField.setText(name); |
|
|
|
return this; |
|
} |
|
|
|
private AddPage typePhone(String phone) throws UiObjectNotFoundException { |
|
UiObject phoneField = contactView.getChildByText(phoneLocator, "Phone"); |
|
phoneField.setText(phone); |
|
|
|
return this; |
|
} |
|
|
|
private AddPage typeEmail(String email) throws UiObjectNotFoundException { |
|
UiObject emailField = contactView.getChildByText(emailLocator, "Email"); |
|
emailField.setText(email); |
|
|
|
return this; |
|
} |
|
|
|
private AddPage typeAddress(String address) throws UiObjectNotFoundException { |
|
UiObject addressField = contactView.getChildByText(addressLocator, "Address"); |
|
addressField.setText(address); |
|
|
|
return this; |
|
} |
|
} |