Radical Art Template – Adjustable Page Turn Tests

Here is some sample test code from the Radical Art Template

Free PDF Guide here…

It uses Android Studio to run the code and perform page turns.

package radical.art.template;

import android.test.ActivityInstrumentationTestCase2;

/**
* A class to perform page turns on your emulator or phone of the Radical Art Template.
*/

public class PageTurnTests extends
ActivityInstrumentationTestCase2<MainActivity> {

private MainActivity mainActivity;

public PageTurnTests() {
super(MainActivity.class);
}

protected void setUp() throws Exception {
super.setUp();
mainActivity = getActivity();
}

/**
* You can adjust the number of turns the application will perform as well as the speed that it performs them.
*/
public void testRightTurn() {

// set the number of page turns to perform
final int TURNS = 100;

// set the speed at which the pages turn to test if it will work
final int SPEED = 50;

//check the position of the current image position
int before = mainActivity.common.currentImagePosition;
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
mainActivity.RightArrowClick(null);
}
});

// the actual position should have changed
int actual = mainActivity.common.currentImagePosition;
assertTrue(actual != before);

//perform the same page turns in a loop
for (int i = 0; i < TURNS; i++) {
try {
Thread.sleep(SPEED);
} catch (InterruptedException e) {
e.printStackTrace();
}

before = mainActivity.common.currentImagePosition;
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
mainActivity.RightArrowClick(null);
}
});
actual = mainActivity.common.currentImagePosition;
assertTrue(actual != before);
}
}

/**
* You can adjust the number of turns the application will perform as well as the speed that it performs them.
*/
public void testLeftPageTurns() {

// set the number of page turns to perform
final int TURNS = 100;

// set the speed at which the pages turn to test if it will work
final int SPEED = 100;

//check the position of the current image position
int before = mainActivity.common.currentImagePosition;
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
mainActivity.LeftArrowClick(null);
}
});

// the actual position should have changed
int actual = mainActivity.common.currentImagePosition;
assertTrue(actual != before);

//perform the same page turns in a loop
for (int i = 0; i < TURNS; i++) {
try {
Thread.sleep(SPEED);
} catch (InterruptedException e) {
e.printStackTrace();
}

before = mainActivity.common.currentImagePosition;
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
mainActivity.LeftArrowClick(null);
}
});
actual = mainActivity.common.currentImagePosition;
assertTrue(actual != before);
}
}
}
Radical Art Template – Adjustable Page Turn Tests

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 2 other subscribers