Search in sources :

Example 16 with EditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.

the class BuildTypesTest method addNewBuildType.

/**
   * Verifies addition of new build types
   * <p>This is run to qualify releases. Please involve the test team in substantial changes.
   * <p>TR ID: C14581580
   * <pre>
   *   Test Steps:
   *   1. Open the project structure dialog
   *   2. Select a module
   *   3. Click the Build Types tab
   *   4. Create new Build Type and name it newBuildType
   *   5. Set properties debuggable and version Name Suffix to valid values
   *   Verification:
   *   1. Open the build.gradle file for that module and verify
   *   entries for build types to contain new build type added.
   *   2. Verify the properties in the file match the values
   *   set in the project structure flavor dialog
   * </pre>
   */
@RunIn(TestGroup.QA)
@Test
public void addNewBuildType() throws Exception {
    IdeFrameFixture ideFrame = guiTest.importSimpleApplication();
    ProjectStructureDialogFixture projectStructureDialog = ideFrame.openFromMenu(ProjectStructureDialogFixture::find, "File", "Project Structure...");
    BuildTypesTabFixture buildTypesTab = projectStructureDialog.selectConfigurable("app").selectBuildTypesTab();
    buildTypesTab.setName("newBuildType").setDebuggable("true").setVersionNameSuffix("suffix");
    projectStructureDialog.clickOk();
    ideFrame.waitForGradleProjectSyncToFinish();
    EditorFixture editor = ideFrame.getEditor().open("/app/build.gradle");
    String gradleFileContents = editor.getCurrentFileContents();
    assertThat(gradleFileContents).containsMatch("newBuildType \\{\\n[\\s]*debuggable true\\n[\\s]*versionNameSuffix 'suffix'\\n[\\s]*\\}");
}
Also used : ProjectStructureDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.projectstructure.ProjectStructureDialogFixture) EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) BuildTypesTabFixture(com.android.tools.idea.tests.gui.framework.fixture.projectstructure.BuildTypesTabFixture) Test(org.junit.Test) RunIn(com.android.tools.idea.tests.gui.framework.RunIn)

Example 17 with EditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.

the class NlEditorTest method testCopyAndPaste.

@Test
public void testCopyAndPaste() throws Exception {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    EditorFixture editor = ideFrame.getEditor().open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.DESIGN);
    NlEditorFixture layout = editor.getLayoutEditor(true).dragComponentToSurface("Widgets", "Button").dragComponentToSurface("Widgets", "CheckBox").waitForRenderToFinish();
    // Find and click the first text view
    NlComponentFixture textView = layout.findView("CheckBox", 0);
    textView.click();
    // It should be selected now
    layout.requireSelection(Collections.singletonList(textView));
    // 4 = root layout + 3 widgets
    assertEquals(4, layout.getAllComponents().size());
    ideFrame.invokeMenuPath("Edit", "Cut");
    layout.requireSelection(Collections.emptyList());
    assertEquals(3, layout.getAllComponents().size());
    layout.findView("Button", 0).click();
    ideFrame.invokeMenuPath("Edit", "Paste");
    layout.findView("CheckBox", 0).click();
    ideFrame.invokeMenuPath("Edit", "Copy");
    ideFrame.invokeMenuPath("Edit", "Paste");
    assertEquals(5, layout.getAllComponents().size());
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) NlComponentFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture) Test(org.junit.Test)

Example 18 with EditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.

the class NlPreviewTest method testRenderingDynamicResources.

@Test
public void testRenderingDynamicResources() throws Exception {
    // Opens a layout which contains dynamic resources (defined only in build.gradle)
    // and checks that the values have been resolved correctly (both that there are no
    // unresolved reference errors in the XML file, and that the rendered layout strings
    // matches the expected overlay semantics); also edits these in the Gradle file and
    // checks that the layout rendering is updated after a Gradle sync.
    guiTest.importProjectAndWaitForProjectSyncToFinish("LayoutTest");
    AndroidModuleModel androidModel = guiTest.ideFrame().getAndroidModel("app");
    String modelVersion = androidModel.getAndroidProject().getModelVersion();
    Revision version = Revision.parseRevision(modelVersion);
    assumeTrue("This test tests behavior that starts working in 0.14.+", version.getMajor() != 0 || version.getMinor() >= 14);
    EditorFixture editor = guiTest.ideFrame().getEditor();
    String layoutFilePath = "app/src/main/res/layout/dynamic_layout.xml";
    editor.open(layoutFilePath, EditorFixture.Tab.EDITOR);
    NlPreviewFixture preview = editor.getLayoutPreview(true);
    preview.waitForRenderToFinish();
    assertFalse(preview.hasRenderErrors());
    NlComponentFixture string1 = preview.findView("TextView", 0);
    string1.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string1");
    string1.requireViewClass("android.support.v7.widget.AppCompatTextView");
    string1.requireActualText("String 1 defined only by defaultConfig");
    NlComponentFixture string2 = preview.findView("TextView", 1);
    string2.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string2");
    string2.requireActualText("String 1 defined only by defaultConfig");
    NlComponentFixture string3 = preview.findView("TextView", 2);
    string3.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string3");
    string3.requireActualText("String 3 defined by build type debug");
    NlComponentFixture string4 = preview.findView("TextView", 3);
    string4.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string4");
    string4.requireActualText("String 4 defined by flavor free");
    NlComponentFixture string5 = preview.findView("TextView", 4);
    string5.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string5");
    string5.requireActualText("String 5 defined by build type debug");
    // Ensure that all the references are properly resolved
    FileFixture file = guiTest.ideFrame().findExistingFileByRelativePath(layoutFilePath);
    file.waitForCodeAnalysisHighlightCount(ERROR, 0);
    editor.open("app/build.gradle", EditorFixture.Tab.EDITOR).moveBetween("String 1 defined only by ", "defaultConfig").enterText("edited ").awaitNotification("Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly.").performAction("Sync Now").waitForGradleProjectSyncToFinish();
    editor.open(layoutFilePath, EditorFixture.Tab.EDITOR);
    preview.waitForRenderToFinish();
    string1 = preview.findView("TextView", 0);
    string1.requireActualText("String 1 defined only by edited defaultConfig");
    file.waitForCodeAnalysisHighlightCount(ERROR, 0);
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) Revision(com.android.repository.Revision) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) FileFixture(com.android.tools.idea.tests.gui.framework.fixture.FileFixture) Test(org.junit.Test)

Example 19 with EditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.

the class NlPreviewTest method testConfigurationMatching.

@Test
public void testConfigurationMatching() throws Exception {
    guiTest.importProjectAndWaitForProjectSyncToFinish("LayoutTest");
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    EditorFixture editor = ideFrame.getEditor();
    editor.open("app/src/main/res/layout/layout2.xml", EditorFixture.Tab.EDITOR);
    NlPreviewFixture preview = editor.getLayoutPreview(true);
    NlConfigurationToolbarFixture toolbar = preview.getConfigToolbar();
    toolbar.chooseDevice("Nexus 5");
    preview.waitForRenderToFinish();
    toolbar.requireDevice("Nexus 5");
    assertThat(editor.getCurrentFile().getParent().getName()).isEqualTo("layout");
    toolbar.requireOrientation("Portrait");
    toolbar.chooseDevice("Nexus 7");
    preview.waitForRenderToFinish();
    toolbar.requireDevice("Nexus 7 2013");
    assertThat(editor.getCurrentFile().getParent().getName()).isEqualTo("layout-sw600dp");
    toolbar.chooseDevice("Nexus 10");
    preview.waitForRenderToFinish();
    toolbar.requireDevice("Nexus 10");
    assertThat(editor.getCurrentFile().getParent().getName()).isEqualTo("layout-sw600dp");
    // Default orientation for Nexus 10
    toolbar.requireOrientation("Landscape");
    editor.open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.EDITOR);
    preview.waitForRenderToFinish();
    // Since we switched to it most recently
    toolbar.requireDevice("Nexus 10");
    toolbar.requireOrientation("Portrait");
    toolbar.chooseDevice("Nexus 7");
    preview.waitForRenderToFinish();
    toolbar.chooseDevice("Nexus 4");
    preview.waitForRenderToFinish();
    editor.open("app/src/main/res/layout-sw600dp/layout2.xml", EditorFixture.Tab.EDITOR);
    preview.waitForRenderToFinish();
    assertThat(editor.getCurrentFile().getParent().getName()).isEqualTo("layout-sw600dp");
    // because it's the most recently configured sw600-dp compatible device
    toolbar.requireDevice("Nexus 7 2013");
    editor.open("app/src/main/res/layout/layout2.xml", EditorFixture.Tab.EDITOR);
    preview.waitForRenderToFinish();
    // because it's the most recently configured small screen compatible device
    toolbar.requireDevice("Nexus 4");
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) Test(org.junit.Test)

Example 20 with EditorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.EditorFixture in project android by JetBrains.

the class ThemePreviewTest method testToolbarState.

@RunIn(TestGroup.UNRELIABLE)
@Test
public void testToolbarState() throws Exception {
    guiTest.importSimpleApplication();
    Project project = guiTest.ideFrame().getProject();
    EditorFixture editor = guiTest.ideFrame().getEditor();
    editor.open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.EDITOR);
    int savedApiLevel = editor.getLayoutPreview(true).getConfigToolbar().getApiLevel();
    editor.open("app/src/main/res/values-v19/styles.xml", EditorFixture.Tab.EDITOR);
    editor.moveBetween("PreviewTheme", "");
    guiTest.robot().waitForIdle();
    assertTrue(ToolWindowManager.getInstance(project).getToolWindow("Theme Preview").isAvailable());
    // There is also a v20 styles.xml so in order to preview v19, it has to be selected in the toolbar
    editor.getThemePreview(true).getPreviewComponent().requireApi(19);
    editor.open("app/src/main/res/values/styles.xml", EditorFixture.Tab.EDITOR);
    editor.moveBetween("PreviewTheme", "");
    guiTest.robot().waitForIdle();
    editor.getThemePreview(true).getPreviewComponent().requireApi(18);
    editor.open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.EDITOR);
    // The API level shouldn't be modified by the theme preview. Regression test for http://b.android.com/201313
    assertThat(editor.getLayoutPreview(true).getConfigToolbar().getApiLevel()).isEqualTo(savedApiLevel);
}
Also used : Project(com.intellij.openapi.project.Project) EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) Test(org.junit.Test) RunIn(com.android.tools.idea.tests.gui.framework.RunIn)

Aggregations

EditorFixture (com.android.tools.idea.tests.gui.framework.fixture.EditorFixture)41 Test (org.junit.Test)37 IdeFrameFixture (com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture)9 Ignore (org.junit.Ignore)7 GradleBuildModelFixture (com.android.tools.idea.tests.gui.framework.fixture.gradle.GradleBuildModelFixture)6 NlComponentFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture)6 NlEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture)6 ArtifactDependencySpec (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)4 MergedManifestFixture (com.android.tools.idea.tests.gui.framework.fixture.MergedManifestFixture)4 RunIn (com.android.tools.idea.tests.gui.framework.RunIn)3 RenameRefactoringDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.RenameRefactoringDialogFixture)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 DialogFixture (org.fest.swing.fixture.DialogFixture)3 JButtonFixture (org.fest.swing.fixture.JButtonFixture)3 JTreeFixture (org.fest.swing.fixture.JTreeFixture)3 ExpectedModuleDependency (com.android.tools.idea.gradle.dsl.model.dependencies.ExpectedModuleDependency)2 ChooseResourceDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture)2 ConflictsDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.RenameRefactoringDialogFixture.ConflictsDialogFixture)2 ThemeEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.theme.ThemeEditorFixture)2 Project (com.intellij.openapi.project.Project)2