public void testSelectCostumeAndPlay() { solo.clickOnText(getActivity().getString(R.string.broadcast_nothing_selected)); solo.clickOnText(costumeName); assertTrue(costumeName + " is not selected in Spinner", solo.searchText(costumeName)); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.sleep(7000); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.sleep(2000); Costume costume = ProjectManager.getInstance().getCurrentProject().getSpriteList().get(0).costume; assertEquals( "costume not set", costume.getImagePath(), costumeDataList.get(0).getAbsolutePath()); solo.goBack(); solo.goBack(); solo.waitForActivity(ScriptTabActivity.class.getSimpleName()); solo.clickOnText(costumeName); solo.clickOnText(costumeName2); assertTrue(costumeName2 + " is not selected in Spinner", solo.searchText(costumeName2)); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.sleep(2000); costume = ProjectManager.getInstance().getCurrentProject().getSpriteList().get(0).costume; assertEquals( "costume not set", costume.getImagePath(), costumeDataList.get(1).getAbsolutePath()); }
public void testRestartButtonActivityChain() throws NameNotFoundException, IOException { createAndSaveTestProject(testProject); solo.clickOnButton(getActivity().getString(R.string.my_projects)); solo.waitForActivity(MyProjectsActivity.class.getSimpleName()); solo.waitForFragmentById(R.id.fr_projects_list); assertTrue("Cannot click project.", UiTestUtils.clickOnTextInList(solo, testProject)); solo.waitForActivity(ProjectActivity.class.getSimpleName()); Activity currentActivity = solo.getCurrentActivity(); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.goBack(); solo.sleep(100); solo.clickOnButton(getActivity().getString(R.string.restart_current_project)); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.assertCurrentActivity("Program is not in stage activity", StageActivity.class); solo.sleep(500); solo.goBack(); solo.sleep(100); solo.clickOnButton(getActivity().getString(R.string.back)); solo.waitForActivity(ProjectActivity.class.getSimpleName()); assertEquals("Returned to wrong Activity", currentActivity, solo.getCurrentActivity()); }
public void testPauseOnBackButton() { double scale = 100.0; Project project = new Project(getActivity(), testProject); Sprite sprite = new Sprite("testSprite"); Script script = new StartScript(sprite); WaitBrick waitBrick = new WaitBrick(sprite, 5000); SetSizeToBrick scaleCostumeBrick = new SetSizeToBrick(sprite, scale); script.addBrick(waitBrick); script.addBrick(scaleCostumeBrick); sprite.addScript(script); project.addSprite(sprite); storageHandler.saveProject(project); ProjectManager.getInstance().setProject(project); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); // assertEquals("Unexpected sprite size", 100.0, sprite.getSize()); // solo.goBack(); // solo.sleep(6000); // solo.goBack(); // assertEquals("Unexpected sprite size", 100.0, sprite.getSize()); // solo.sleep(4000); // assertEquals("Unexpected sprite size", scale, sprite.getSize()); }
public void testAdapterUpdateInScriptActivity() { String costume1ImagePath = costumeDataList.get(0).getAbsolutePath(); String costume2ImagePath = costumeDataList.get(1).getAbsolutePath(); solo.clickOnText(getActivity().getString(R.string.broadcast_nothing_selected)); solo.clickOnText(costumeName); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); String costumePath = ProjectManager.getInstance() .getCurrentSprite() .getCostumeDataList() .get(0) .getAbsolutePath(); assertEquals( "Wrong image shown in stage --> Problem with Adapter update in Script", costume1ImagePath, costumePath); solo.goBack(); solo.sleep(500); solo.goBack(); for (int i = 0; i < 5; i++) { selectCostume(costumeName2, costumeName, costume2ImagePath); selectCostume(costumeName, costumeName2, costume1ImagePath); } }
public void testRestartButtonScriptPosition() { ArrayList<Integer> scriptPositionsStart = new ArrayList<Integer>(); ArrayList<Integer> scriptPositionsRestart = new ArrayList<Integer>(); scriptPositionsStart.clear(); scriptPositionsRestart.clear(); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.sleep(1000); ProjectManager projectManager = ProjectManager.getInstance(); Project projectStart = projectManager.getCurrentProject(); String projectNameStart = projectStart.getName(); // scriptPositions at start List<Sprite> spriteList = projectStart.getSpriteList(); for (int i = 0; i < spriteList.size(); i++) { Sprite sprite = spriteList.get(i); int size = sprite.getNumberOfScripts(); for (int j = 0; j < size; j++) { scriptPositionsRestart.add(sprite.getScript(j).getExecutingBrickIndex()); } } spriteList.clear(); solo.clickOnScreen(Values.SCREEN_WIDTH / 2, Values.SCREEN_HEIGHT / 2); solo.sleep(200); solo.goBack(); solo.sleep(100); solo.clickOnButton(getActivity().getString(R.string.restart_current_project)); solo.sleep(300); // scriptPositions in between Project projectRestart = ProjectManager.getInstance().getCurrentProject(); String projectNameRestart = projectRestart.getName(); assertEquals("Wrong project after restart", projectNameStart, projectNameRestart); spriteList = projectRestart.getSpriteList(); for (int i = 0; i < spriteList.size(); i++) { Sprite sprite = spriteList.get(i); int size = sprite.getNumberOfScripts(); for (int j = 0; j < size; j++) { scriptPositionsRestart.add(sprite.getScript(j).getExecutingBrickIndex()); } } for (int i = 0; i < scriptPositionsStart.size(); i++) { assertEquals( "Script is not at starting position!", scriptPositionsStart.get(i).intValue(), scriptPositionsRestart.get(i).intValue()); } }
public void testRestartProjectWithSound() { String projectName = UiTestUtils.PROJECTNAME1; // creating sprites for project: Sprite firstSprite = new Sprite("sprite1"); Script startScript = new StartScript(firstSprite); PlaySoundBrick playSoundBrick = new PlaySoundBrick(firstSprite); startScript.addBrick(playSoundBrick); firstSprite.addScript(startScript); ArrayList<Sprite> spriteList = new ArrayList<Sprite>(); spriteList.add(firstSprite); Project project = UiTestUtils.createProject(projectName, spriteList, getActivity()); File soundFile = UiTestUtils.saveFileToProject( projectName, "soundfile.mp3", at.tugraz.ist.catroid.uitest.R.raw.longsound, getInstrumentation().getContext(), UiTestUtils.FileTypes.SOUND); SoundInfo soundInfo = new SoundInfo(); soundInfo.setSoundFileName(soundFile.getName()); soundInfo.setTitle(soundFile.getName()); playSoundBrick.setSoundInfo(soundInfo); firstSprite.getSoundList().add(soundInfo); storageHandler.saveProject(project); MediaPlayer mediaPlayer = SoundManager.getInstance().getMediaPlayer(); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.sleep(1000); assertTrue("Sound not playing.", mediaPlayer.isPlaying()); int positionBeforeRestart = mediaPlayer.getCurrentPosition(); solo.goBack(); solo.sleep(500); assertFalse("Sound playing but should be paused.", mediaPlayer.isPlaying()); solo.clickOnButton(getActivity().getString(R.string.restart_current_project)); solo.sleep(300); @SuppressWarnings("unchecked") ArrayList<MediaPlayer> mediaPlayerArrayList = (ArrayList<MediaPlayer>) UiTestUtils.getPrivateField("mediaPlayers", SoundManager.getInstance()); int positionAfterRestart = mediaPlayerArrayList.get(0).getCurrentPosition(); assertTrue("Sound not playing after stage restart.", mediaPlayerArrayList.get(0).isPlaying()); assertTrue("Sound did not play from start!", positionBeforeRestart > positionAfterRestart); }
public void testBackButtonPressedTwice() throws NameNotFoundException, IOException { Project project = createTestProject(testProject); ProjectManager.getInstance().setProject(project); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.sleep(1000); solo.goBack(); solo.goBack(); solo.waitForActivity(MainMenuActivity.class.getSimpleName()); solo.assertCurrentActivity("Program is not in stage activity", MainMenuActivity.class); }
public void testAxesOnOff() throws NameNotFoundException, IOException { createAndSaveTestProject(testProject); solo.clickOnButton(getActivity().getString(R.string.my_projects)); solo.waitForActivity(MyProjectsActivity.class.getSimpleName()); solo.waitForFragmentById(R.id.fr_projects_list); assertTrue("Cannot click project.", UiTestUtils.clickOnTextInList(solo, testProject)); solo.waitForActivity(ProjectActivity.class.getSimpleName()); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.goBack(); solo.clickOnButton(getActivity().getString(R.string.stagemenu_axes_on)); solo.clickOnButton(getActivity().getString(R.string.resume_current_project)); solo.sleep(100); byte[] redPixel = {(byte) 255, 0, 0, (byte) 255}; byte[] stagePixel = StageActivity.stageListener.getPixels( Values.SCREEN_WIDTH / 2, Values.SCREEN_HEIGHT / 2, 1, 1); UiTestUtils.compareByteArrays(redPixel, stagePixel); stagePixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH / 2, 0, 1, 1); UiTestUtils.compareByteArrays(redPixel, stagePixel); stagePixel = StageActivity.stageListener.getPixels( Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT / 2, 1, 1); UiTestUtils.compareByteArrays(redPixel, stagePixel); stagePixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT / 2, 1, 1); UiTestUtils.compareByteArrays(redPixel, stagePixel); stagePixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH / 2, Values.SCREEN_HEIGHT, 1, 1); UiTestUtils.compareByteArrays(redPixel, stagePixel); solo.goBack(); solo.clickOnButton(getActivity().getString(R.string.stagemenu_axes_off)); solo.clickOnButton(getActivity().getString(R.string.resume_current_project)); solo.sleep(100); byte[] whitePixel = {(byte) 255, (byte) 255, (byte) 255, (byte) 255}; stagePixel = StageActivity.stageListener.getPixels( Values.SCREEN_WIDTH / 2, Values.SCREEN_HEIGHT / 2, 1, 1); UiTestUtils.compareByteArrays(whitePixel, stagePixel); stagePixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH / 2, 0, 1, 1); UiTestUtils.compareByteArrays(whitePixel, stagePixel); stagePixel = StageActivity.stageListener.getPixels( Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT / 2, 1, 1); UiTestUtils.compareByteArrays(whitePixel, stagePixel); stagePixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT / 2, 1, 1); UiTestUtils.compareByteArrays(whitePixel, stagePixel); stagePixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH / 2, Values.SCREEN_HEIGHT, 1, 1); UiTestUtils.compareByteArrays(whitePixel, stagePixel); }
public void selectCostume(String newCostume, String oldName, String costumeImagePath) { solo.clickOnText(oldName); solo.clickOnText(newCostume); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.sleep(5000); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.sleep(2000); String costumePath = ProjectManager.getInstance().getCurrentSprite().costume.getImagePath(); assertEquals( "Wrong image shown in stage --> Problem with Adapter update in Script", costumeImagePath, costumePath); solo.goBack(); solo.goBack(); }
public void testBackToPreviousActivity() throws NameNotFoundException, IOException { createAndSaveTestProject(testProject); solo.clickOnButton(getActivity().getString(R.string.my_projects)); solo.waitForActivity(MyProjectsActivity.class.getSimpleName()); solo.waitForFragmentById(R.id.fr_projects_list); assertTrue("Cannot click project.", UiTestUtils.clickOnTextInList(solo, testProject)); solo.waitForActivity(ProjectActivity.class.getSimpleName()); Activity previousActivity = getActivity(); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); solo.goBack(); solo.clickOnButton(getActivity().getString(R.string.back)); solo.waitForActivity(ProjectActivity.class.getSimpleName()); assertEquals("Not equal Activities", previousActivity, getActivity()); }
public void testMaximizeStretch() throws NameNotFoundException, IOException { Project project = createTestProject(testProject); project.virtualScreenWidth = 480; project.virtualScreenHeight = 700; project.setDeviceData(getActivity()); storageHandler.saveProject(project); solo.clickOnButton(getActivity().getString(R.string.my_projects)); solo.waitForActivity(MyProjectsActivity.class.getSimpleName()); solo.waitForFragmentById(R.id.fr_projects_list); assertTrue("Cannot click project.", UiTestUtils.clickOnTextInList(solo, testProject)); solo.waitForActivity(ProjectActivity.class.getSimpleName()); Utils.updateScreenWidthAndHeight(getActivity()); UiTestUtils.clickOnActionBar(solo, R.id.menu_start); solo.waitForActivity(StageActivity.class.getSimpleName()); assertTrue( "Stage not resizeable.", ((StageActivity) solo.getCurrentActivity()).getResizePossible()); byte[] whitePixel = {(byte) 255, (byte) 255, (byte) 255, (byte) 255}; byte[] screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels( Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); solo.goBack(); solo.clickOnButton(getActivity().getString(R.string.stagemenu_screen_size)); solo.clickOnButton(getActivity().getString(R.string.resume_current_project)); solo.sleep(100); byte[] blackPixel = {0, 0, 0, (byte) 255}; screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1); UiTestUtils.compareByteArrays(blackPixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels( Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1); UiTestUtils.compareByteArrays(blackPixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1); UiTestUtils.compareByteArrays(blackPixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1); UiTestUtils.compareByteArrays(blackPixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH, Values.SCREEN_HEIGHT, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); solo.goBack(); solo.clickOnButton(getActivity().getString(R.string.stagemenu_screen_size)); solo.clickOnButton(getActivity().getString(R.string.resume_current_project)); solo.sleep(100); screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels( Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1); UiTestUtils.compareByteArrays(whitePixel, screenPixel); }