Skip to content

Commit

Permalink
#38
Browse files Browse the repository at this point in the history
  • Loading branch information
Kushal committed Sep 6, 2018
1 parent fddb821 commit 8601a19
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import org.hamcrest.Matcher;
import android.support.test.espresso.matcher.ViewMatchers;
import static android.support.test.espresso.Espresso.onView;


/*
- This class defines all the application elements used
*/
public class ObjectStore {

public final static Matcher<View> tv_USERNAME = withId(R.id.edt_username);
public final static Matcher<View> tv_PASSWORD = withId(R.id.edt_password);
public final static Matcher<View> et_USERNAME = withId(R.id.edt_username);
public final static Matcher<View> et_PASSWORD = withId(R.id.edt_password);
public final static Matcher<View> btn_LOGIN = withId(R.id.btn_login);

public final static Matcher<View> left_DRAWER = withId(R.id.drawer_layout);

public final static Matcher<View> tv_USER_LOGGED = withId(R.id.nav_username);


}
52 changes: 26 additions & 26 deletions app/src/androidTest/java/com/mytaxi/android_demo/LoginTestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ public void setUpBeforeTest(){
public void performLoginTestWithValidCredentials(){

//checking if Username input field is present & enabled before entering text
onView(ObjectStore.tv_USERNAME).check(matches(isDisplayed()));
onView(ObjectStore.tv_USERNAME).check(matches(isEnabled()));
onView(ObjectStore.tv_USERNAME).perform(click()) ;
onView(ObjectStore.tv_USERNAME).perform(typeText(Constants.USER_NAME)); // enter in username
onView(ObjectStore.et_USERNAME).check(matches(isDisplayed()));
onView(ObjectStore.et_USERNAME).check(matches(isEnabled()));
onView(ObjectStore.et_USERNAME).perform(click()) ;
onView(ObjectStore.et_USERNAME).perform(typeText(Constants.USER_NAME)); // enter in username

//checking if password input field is present & enabled before entering text
onView(ObjectStore.tv_PASSWORD).check(matches(isDisplayed()));
onView(ObjectStore.tv_PASSWORD).check(matches(isEnabled()));
onView(ObjectStore.tv_PASSWORD).perform(click()) ;
onView(ObjectStore.tv_PASSWORD).perform(typeText(Constants.USER_PASSWORD), closeSoftKeyboard()); //enter in password field and close the keyboard
onView(ObjectStore.et_PASSWORD).check(matches(isDisplayed()));
onView(ObjectStore.et_PASSWORD).check(matches(isEnabled()));
onView(ObjectStore.et_PASSWORD).perform(click()) ;
onView(ObjectStore.et_PASSWORD).perform(typeText(Constants.USER_PASSWORD), closeSoftKeyboard()); //enter in password field and close the keyboard


// to check if LOGIN button is displayed and can be clicked
Expand All @@ -111,9 +111,9 @@ public void performLoginTestWithValidCredentials(){
@Test
public void performLoginTestWithBlankValues(){

onView(ObjectStore.tv_USERNAME).check(matches(isDisplayed())); //checking if username input field is present
onView(ObjectStore.et_USERNAME).check(matches(isDisplayed())); //checking if username input field is present

onView(ObjectStore.tv_PASSWORD).check(matches(isDisplayed())); //checking if password input field is present
onView(ObjectStore.et_PASSWORD).check(matches(isDisplayed())); //checking if password input field is present

onView(ObjectStore.btn_LOGIN).check(matches(isDisplayed())).check(matches(isClickable())); // to check if LOGIN button is displayed and can be clicked
onView(ObjectStore.btn_LOGIN).perform(click()) ; // click LOGIN button to submit [Although LOGIN button should be disabled unless Username & Password fields have value]
Expand All @@ -135,17 +135,17 @@ public void performLoginTestWithBlankValues(){
@Test
public void performLoginTestWithInValidUsername(){
//checking if Username input field is present & enabled before entering text
onView(ObjectStore.tv_USERNAME).check(matches(isDisplayed()));
onView(ObjectStore.tv_USERNAME).check(matches(isEnabled()));
onView(ObjectStore.tv_USERNAME).perform(click()) ;
onView(ObjectStore.tv_USERNAME).perform(typeText(Constants.SOME_INVALID_TEXT)); // enter in username field
onView(ObjectStore.et_USERNAME).check(matches(isDisplayed()));
onView(ObjectStore.et_USERNAME).check(matches(isEnabled()));
onView(ObjectStore.et_USERNAME).perform(click()) ;
onView(ObjectStore.et_USERNAME).perform(typeText(Constants.SOME_INVALID_TEXT)); // enter in username field


//checking if password input field is present & enabled before entering text
onView(ObjectStore.tv_PASSWORD).check(matches(isDisplayed()));
onView(ObjectStore.tv_PASSWORD).check(matches(isEnabled()));
onView(ObjectStore.tv_PASSWORD).perform(click()) ;
onView(ObjectStore.tv_PASSWORD).perform(typeText(Constants.USER_PASSWORD), closeSoftKeyboard()); // enter in password field & close keyboard
onView(ObjectStore.et_PASSWORD).check(matches(isDisplayed()));
onView(ObjectStore.et_PASSWORD).check(matches(isEnabled()));
onView(ObjectStore.et_PASSWORD).perform(click()) ;
onView(ObjectStore.et_PASSWORD).perform(typeText(Constants.USER_PASSWORD), closeSoftKeyboard()); // enter in password field & close keyboard

onView(ObjectStore.btn_LOGIN).check(matches(isDisplayed())).check(matches(isClickable())); // to check if LOGIN button is displayed and can be clicked
onView(ObjectStore.btn_LOGIN).perform(click()) ; // click LOGIN button to submit
Expand All @@ -167,17 +167,17 @@ public void performLoginTestWithInValidUsername(){
@Test
public void performLoginTestWithInValidPassword(){
//checking if Username input field is present & enabled before entering text
onView(ObjectStore.tv_USERNAME).check(matches(isDisplayed()));
onView(ObjectStore.tv_USERNAME).check(matches(isEnabled()));
onView(ObjectStore.tv_USERNAME).perform(click()) ;
onView(ObjectStore.tv_USERNAME).perform(typeText(Constants.USER_NAME )); // enter in username field
onView(ObjectStore.et_USERNAME).check(matches(isDisplayed()));
onView(ObjectStore.et_USERNAME).check(matches(isEnabled()));
onView(ObjectStore.et_USERNAME).perform(click()) ;
onView(ObjectStore.et_USERNAME).perform(typeText(Constants.USER_NAME )); // enter in username field


//checking if password input field is present & enabled before entering text
onView(ObjectStore.tv_PASSWORD).check(matches(isDisplayed()));
onView(ObjectStore.tv_PASSWORD).check(matches(isEnabled()));
onView(ObjectStore.tv_PASSWORD).perform(click()) ;
onView(ObjectStore.tv_PASSWORD).perform(typeText(Constants.SOME_INVALID_TEXT), closeSoftKeyboard()); // enter in password field & close keyboard
onView(ObjectStore.et_PASSWORD).check(matches(isDisplayed()));
onView(ObjectStore.et_PASSWORD).check(matches(isEnabled()));
onView(ObjectStore.et_PASSWORD).perform(click()) ;
onView(ObjectStore.et_PASSWORD).perform(typeText(Constants.SOME_INVALID_TEXT), closeSoftKeyboard()); // enter in password field & close keyboard


// to check if LOGIN button is displayed and can be clicked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.mytaxi.android_demo.ObjectStore;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
Expand Down Expand Up @@ -79,26 +81,26 @@ public void setUpBeforeTest() {
@Test
public void performLoginAndCallSearchedDriverTest(){
//checking if Username input field is present & enabled before entering text
onView(withId(R.id.edt_username)).check(matches(isDisplayed()));
onView(withId(R.id.edt_username)).check(matches(isEnabled()));
onView(withId(R.id.edt_username)).perform(click()) ;
onView(withId(R.id.edt_username)).perform(typeText(Constants.USER_NAME)); //enter in username field
onView(ObjectStore.et_USERNAME).check(matches(isDisplayed()));
onView(ObjectStore.et_USERNAME).check(matches(isEnabled()));
onView(ObjectStore.et_USERNAME).perform(click()) ;
onView(ObjectStore.et_USERNAME).perform(typeText(Constants.USER_NAME)); //enter in username field

//checking if password input field is present & enabled before entering text
onView(withId(R.id.edt_password)).check(matches(isDisplayed()));
onView(withId(R.id.edt_password)).check(matches(isEnabled()));
onView(withId(R.id.edt_password)).perform(click()) ;
onView(withId(R.id.edt_password)).perform(typeText(Constants.USER_PASSWORD), closeSoftKeyboard()); //enter in password field and close the keyboard
onView(ObjectStore.et_PASSWORD).check(matches(isDisplayed()));
onView(ObjectStore.et_PASSWORD).check(matches(isEnabled()));
onView(ObjectStore.et_PASSWORD).perform(click()) ;
onView(ObjectStore.et_PASSWORD).perform(typeText(Constants.USER_PASSWORD), closeSoftKeyboard()); //enter in password field and close the keyboard


// to check if LOGIN button is displayed and can be clicked
onView(withId(R.id.btn_login)).check(matches(isDisplayed())).check(matches(isClickable()));
onView(withId(R.id.btn_login)).perform(click()) ; // click LOGIN to submit
onView(ObjectStore.btn_LOGIN).check(matches(isDisplayed())).check(matches(isClickable()));
onView(ObjectStore.btn_LOGIN).perform(click()) ; // click LOGIN to submit

//Waiting for MainActivity to open up
IdlingRegistry.getInstance().register(mainActivityIdlingResource);

onView(withId(R.id.drawer_layout))
onView(ObjectStore.left_DRAWER)
.check(matches(isClosed(Gravity.LEFT))) // To check Left Drawer based on that it is currently closed.
.perform(DrawerActions.open()); // open drawer

Expand Down

0 comments on commit 8601a19

Please sign in to comment.