-
-
Save houssemzaier/105f9a9bb2290499236058bb9e4c386f to your computer and use it in GitHub Desktop.
Class example for testing a Login screen using Screen Object Pattern & JUnit4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package qa.com.espressospoonstructure.tests; | |
import org.junit.Test; | |
import qa.com.espressospoonstructure.screenObjects.LoginScreen; | |
import static android.support.test.espresso.assertion.ViewAssertions.matches; | |
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | |
public class TestLoginScreen extends BaseTestCase<MainActivity> { | |
/* Create the variable that will contain the instance of our Screen Object class*/ | |
private LoginScreen mLoginScreen; | |
/* Create our instance of Login Screen and any other screen object we might require. | |
* Normally, you'll have to go thorugh several screens before running a test.*/ | |
public TestLoginScreen(){ | |
super(MainActivity.class); | |
mLoginScreen = new LoginScreen(); | |
} | |
/* This example doesn't hold one, but it's normal to have a @Before method that navigates to the screen | |
* before executing it. Being able to use that annotation is one of the advantages of using JUnit4*/ | |
/* All tests have the @Test annotation. | |
* Notice that the method name describes exactly the expected behavior for the specified action. | |
* Also notice that the assertion is performed here and it does not rely on the Screen Object class. | |
* */ | |
@Test | |
public void shouldDisplayErrorWhenSubmittingInvalidPassword(){ | |
mLoginScreen.doLogin("ValidUsername", "InvalidPassword"); | |
LoginScreen.LOGIN_VALIDATION_INVALID_PASSWORD.check(matches(isDisplayed())); | |
} | |
/* Notice that we reuse method 'doLogin'. | |
* Difference lies on the test data we use and the assertion implemented. | |
* */ | |
@Test | |
public void shouldDisplayErrorWhenSubmittingInvalidUsernameFormat(){ | |
mLoginScreen.doLogin("InvalidUsername", "ValidPasswordFormat"); | |
mLoginScreen.LOGIN_VALIDATION_USERNAME_INVALID_FORMAT.check(matches(isDisplayed())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment