Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.vokal.petcheck.test;
import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.content.IntentFilter;
import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.vokal.petcheck.*;
import com.vokal.petcheck.walk.User;
public class CustomerSearchTests extends ActivityInstrumentationTestCase2<CustomerSearchActivity> {
private CustomerSearchActivity mActivity;
private Instrumentation mInst;
public CustomerSearchTests() {
super("com.vokal.petcheck", CustomerSearchActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
mActivity = getActivity();
mInst = getInstrumentation();
User user = User.getInstance();
user.setFirst("Carlos");
user.setLast("Bozer");
user.setUserId(36);
user.setLicenseeId(4);
user.setForgotPassword(false);
user.setUsername("cboozer@gmail.com");
}
public void testScroll() throws Exception {
Thread.sleep(5000);
mInst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
TouchUtils.drag(this, 50, 50, 500, 10, 3);
mInst.waitForIdleSync();
Thread.sleep(3000);
TouchUtils.drag(this, 50, 50, 300, 500, 3);
mInst.waitForIdleSync();
Thread.sleep(3000);
}
}
package com.vokal.petcheck.test;
import android.app.Activity;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Button;
import android.widget.EditText;
import com.vokal.petcheck.*;
/**
* This is a simple framework for a test of an Application. See
* {@link android.test.ApplicationTestCase ApplicationTestCase} for more information on
* how to write and extend Application tests.
* <p/>
* To run this test, you can type:
* adb shell am instrument -w \
* -e class com.vokal.petcheck.LoginActivityTest \
* com.vokal.petcheck.tests/android.test.InstrumentationTestRunner
*/
public class LoginTests extends ActivityInstrumentationTestCase2<LoginActivity> {
private static final String TAG = "LoginActivityTest";
private LoginActivity mActivity;
private Button mForgotButton;
private Button mLoginButton;
private EditText mUsername;
private EditText mPassword;
private Instrumentation mInst;
public LoginTests() {
super("com.vokal.petcheck", LoginActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mInst = getInstrumentation();
mForgotButton = (Button) mActivity.findViewById(com.vokal.petcheck.R.id.login_forgot);
mLoginButton = (Button) mActivity.findViewById(com.vokal.petcheck.R.id.login_submit);
mUsername = (EditText) mActivity.findViewById(com.vokal.petcheck.R.id.login_username);
mPassword = (EditText) mActivity.findViewById(com.vokal.petcheck.R.id.login_password);
}
public void testFailedLogin() throws Exception {
TouchUtils.clickView(this, mUsername);
mInst.sendStringSync("Notcboozer@gmail.com\n");
TouchUtils.clickView(this, mPassword);
mInst.sendStringSync("cboozer");
sendKeys(KeyEvent.KEYCODE_BACK);
TouchUtils.clickView(this, mLoginButton);
Instrumentation.ActivityMonitor monitor = mInst.addMonitor(WelcomeActivity.class.getCanonicalName(), null, false);
Activity shouldBeNull = monitor.waitForActivityWithTimeout(2000);
mInst.removeMonitor(monitor);
assertTrue(shouldBeNull == null);
sendKeys(KeyEvent.KEYCODE_BACK);
}
public void testLogin() throws Exception {
Instrumentation.ActivityMonitor monitor = mInst.addMonitor(WelcomeActivity.class.getCanonicalName(), null, false);
TouchUtils.clickView(this, mUsername);
mInst.sendStringSync("cboozer@gmail.com\n");
TouchUtils.clickView(this, mPassword);
mInst.sendStringSync("cboozer");
mInst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
TouchUtils.clickView(this, mLoginButton);
Activity welcomeActivity = mInst.waitForMonitorWithTimeout(monitor, 4000);
mInst.removeMonitor(monitor);
assertNotNull("WelcomeActivity is null", welcomeActivity);
assertTrue("Login Unsuccessful", welcomeActivity instanceof WelcomeActivity);
welcomeActivity.finish();
}
public void testForgotPassword() throws Exception {
Instrumentation.ActivityMonitor monitor = mInst.addMonitor(SecurityQuestionActivity.class.getCanonicalName(), null, false);
TouchUtils.clickView(this, mForgotButton);
mInst.sendStringSync("cboozer@gmail.com");
sendKeys(KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_ENTER);
Activity securityQuestion = mInst.waitForMonitorWithTimeout(monitor, 4000);
assertTrue(securityQuestion instanceof SecurityQuestionActivity);
Thread.sleep(2000);
securityQuestion.finish();
}
}
package com.vokal.petcheck.test;
import android.test.suitebuilder.TestSuiteBuilder;
import junit.framework.Test;
import junit.framework.TestSuite;
public class PetcheckTestSuite extends TestSuite {
public static Test suite() {
return new TestSuiteBuilder(PetcheckTestSuite.class)
.includeAllPackagesUnderHere()
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.