Skip to content

Commit 8393266

Browse files
authored
Create a wizard fixture with the appropriate pages to handle new project creation (#50)
1 parent 66e40c8 commit 8393266

File tree

31 files changed

+1064
-336
lines changed

31 files changed

+1064
-336
lines changed

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/UITestRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.FlatWelcomeFrame;
1616

1717
import java.io.File;
18+
import java.io.FileOutputStream;
1819
import java.io.IOException;
1920
import java.io.InputStream;
2021
import java.io.OutputStream;
21-
import java.io.FileOutputStream;
2222
import java.net.InetSocketAddress;
2323
import java.net.Socket;
2424
import java.net.SocketAddress;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.commonUiTestLibrary.exceptions;
12+
13+
/**
14+
* IntelliJ UI test library runtime exception
15+
*
16+
17+
*/
18+
public class UITestException extends RuntimeException {
19+
public UITestException(String errorMsg) {
20+
super(errorMsg);
21+
}
22+
}

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/dialogs/FlatWelcomeFrame.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.intellij.remoterobot.fixtures.JButtonFixture;
2020
import com.intellij.remoterobot.fixtures.JListFixture;
2121
import com.intellij.remoterobot.fixtures.JPopupMenuFixture;
22+
import com.intellij.remoterobot.utils.UtilsKt;
2223
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
2324
import com.redhat.devtools.intellij.commonUiTestLibrary.UITestRunner;
2425
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.errors.IdeFatalErrorsDialog;
@@ -33,8 +34,6 @@
3334
import java.util.List;
3435

3536
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
36-
import static com.intellij.remoterobot.utils.UtilsKt.hasAnyComponent;
37-
import static com.redhat.devtools.intellij.commonUiTestLibrary.UITestRunner.getIdeaVersion;
3837

3938
/**
4039
* Welcome to IntelliJ IDEA dialog fixture
@@ -48,20 +47,29 @@ public class FlatWelcomeFrame extends CommonContainerFixture {
4847

4948
public FlatWelcomeFrame(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
5049
super(remoteRobot, remoteComponent);
51-
this.intelliJVersion = getIdeaVersion();
50+
this.intelliJVersion = UITestRunner.getIdeaVersion();
5251
}
5352

5453
/**
5554
* Click on the 'New Project' link
5655
*/
5756
public void createNewProject() {
57+
clickOnLink("New Project");
58+
}
59+
60+
/**
61+
* Click on the link according to given label
62+
*
63+
* @param label label of the link to click on
64+
*/
65+
public void clickOnLink(String label) {
5866
// Code for IntelliJ Idea 2020.3 or newer
5967
if (intelliJVersion.toInt() >= 20203) {
60-
welcomeFrameLink("New Project").click();
68+
welcomeFrameLink(label).click();
6169
}
6270
// Code for IntelliJ Idea 2020.2 or earlier
6371
else {
64-
actionLink("New Project").click();
72+
actionLink(label).click();
6573
}
6674
}
6775

@@ -112,7 +120,7 @@ public void clearExceptions() {
112120

113121
// Works for IntelliJ Idea 2020.3+
114122
private JButtonFixture welcomeFrameLink(String text) {
115-
if (hasAnyComponent(this, byXpath("//div[@class='NewRecentProjectPanel']"))) {
123+
if (UtilsKt.hasAnyComponent(this, byXpath("//div[@class='NewRecentProjectPanel']"))) {
116124
return button(byXpath("//div[@class='JBOptionButton' and @text='" + text + "']"), Duration.ofSeconds(2));
117125
}
118126
return button(byXpath("//div[@class='NonOpaquePanel'][./div[@text='" + text + "']]"), Duration.ofSeconds(2));

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/dialogs/errors/IdeFatalErrorsDialog.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
1616
import com.intellij.remoterobot.fixtures.DefaultXpath;
1717
import com.intellij.remoterobot.fixtures.FixtureName;
18+
import com.redhat.devtools.intellij.commonUiTestLibrary.utils.labels.ButtonLabels;
1819
import org.jetbrains.annotations.NotNull;
1920

20-
import static com.redhat.devtools.intellij.commonUiTestLibrary.utils.labels.ButtonLabels.clearAllLabel;
21-
2221
/**
2322
* IDE Fatal Errors dialog fixture
2423
*
@@ -35,6 +34,6 @@ public IdeFatalErrorsDialog(@NotNull RemoteRobot remoteRobot, @NotNull RemoteCom
3534
* Click on the 'Clear all' button
3635
*/
3736
public void clearAll() {
38-
button(clearAllLabel).click();
37+
button(ButtonLabels.clearAllLabel).click();
3938
}
4039
}

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/dialogs/information/ProjectStructureDialog.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
1616
import com.intellij.remoterobot.fixtures.DefaultXpath;
1717
import com.intellij.remoterobot.fixtures.FixtureName;
18+
import com.redhat.devtools.intellij.commonUiTestLibrary.utils.labels.ButtonLabels;
1819
import org.jetbrains.annotations.NotNull;
1920

20-
import static com.redhat.devtools.intellij.commonUiTestLibrary.utils.labels.ButtonLabels.cancelLabel;
21-
2221
/**
2322
* Project Structure dialog fixture
2423
*
@@ -35,6 +34,6 @@ public ProjectStructureDialog(@NotNull RemoteRobot remoteRobot, @NotNull RemoteC
3534
* Cancel the 'Project Structure'
3635
*/
3736
public void cancel() {
38-
button(cancelLabel).click();
37+
button(ButtonLabels.cancelLabel).click();
3938
}
4039
}

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/dialogs/information/TipDialog.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
import com.intellij.remoterobot.fixtures.DefaultXpath;
1717
import com.intellij.remoterobot.fixtures.FixtureName;
1818
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
19+
import com.redhat.devtools.intellij.commonUiTestLibrary.utils.labels.ButtonLabels;
1920
import org.jetbrains.annotations.NotNull;
2021

2122
import java.time.Duration;
2223

23-
import static com.redhat.devtools.intellij.commonUiTestLibrary.utils.labels.ButtonLabels.closeLabel;
24-
2524
/**
2625
* Tip of the Day dialog fixture
2726
*
@@ -42,7 +41,7 @@ public TipDialog(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remo
4241
public static void closeTipDialogIfItAppears(RemoteRobot remoteRobot) {
4342
try {
4443
TipDialog tipDialog = remoteRobot.find(TipDialog.class, Duration.ofSeconds(20));
45-
tipDialog.button(closeLabel).click();
44+
tipDialog.button(ButtonLabels.closeLabel).click();
4645
} catch (WaitForConditionTimeoutException e) {
4746
e.printStackTrace();
4847
}

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/dialogs/navigation/SearchEverywherePopup.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212

1313
import com.intellij.remoterobot.RemoteRobot;
1414
import com.intellij.remoterobot.data.RemoteComponent;
15-
import com.intellij.remoterobot.fixtures.*;
15+
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
16+
import com.intellij.remoterobot.fixtures.DefaultXpath;
17+
import com.intellij.remoterobot.fixtures.FixtureName;
18+
import com.intellij.remoterobot.fixtures.JListFixture;
19+
import com.intellij.remoterobot.fixtures.JTextFieldFixture;
1620
import com.intellij.remoterobot.fixtures.dataExtractor.RemoteText;
1721
import com.intellij.remoterobot.utils.Keyboard;
1822
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
23+
import com.redhat.devtools.intellij.commonUiTestLibrary.exceptions.UITestException;
24+
import com.redhat.devtools.intellij.commonUiTestLibrary.utils.textTranformation.TextUtils;
1925
import org.jetbrains.annotations.NotNull;
2026

2127
import java.awt.event.KeyEvent;
@@ -24,7 +30,6 @@
2430

2531
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
2632
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;
27-
import static com.redhat.devtools.intellij.commonUiTestLibrary.utils.textTranformation.TextUtils.listOfRemoteTextToString;
2833

2934
/**
3035
* Search everywhere popup fixture
@@ -50,7 +55,7 @@ public void activateTab(String tabName) {
5055
try {
5156
button(byXpath("//div[@text='" + tabName + "']"), Duration.ofSeconds(2)).click();
5257
} catch (WaitForConditionTimeoutException e) {
53-
throw new RuntimeException("The '" + tabName + "' tab cannot be found.");
58+
throw new UITestException("The '" + tabName + "' tab cannot be found.");
5459
}
5560
}
5661

@@ -68,7 +73,7 @@ public void invokeCmd(String cmdToEnter) {
6873
}
6974

7075
private boolean didSearchFinish(String cmdToInvoke) {
71-
String searchResultsString = listOfRemoteTextToString(getSearchResults());
76+
String searchResultsString = TextUtils.listOfRemoteTextToString(getSearchResults());
7277
return searchResultsString.toLowerCase().contains(cmdToInvoke.toLowerCase());
7378
}
7479

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.project;
12+
13+
import com.intellij.remoterobot.RemoteRobot;
14+
import com.intellij.remoterobot.data.RemoteComponent;
15+
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
16+
import com.intellij.remoterobot.fixtures.DefaultXpath;
17+
import com.intellij.remoterobot.fixtures.FixtureName;
18+
import com.intellij.remoterobot.fixtures.JButtonFixture;
19+
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
20+
import com.redhat.devtools.intellij.commonUiTestLibrary.exceptions.UITestException;
21+
import com.redhat.devtools.intellij.commonUiTestLibrary.utils.labels.ButtonLabels;
22+
import org.jetbrains.annotations.NotNull;
23+
24+
/**
25+
* New Project dialog wizard fixture
26+
*
27+
28+
*/
29+
@DefaultXpath(by = "MyDialog type", xpath = "//div[@accessiblename='New Project' and @class='MyDialog']")
30+
@FixtureName(name = "New Project Dialog")
31+
public class NewProjectDialogWizard extends CommonContainerFixture {
32+
public NewProjectDialogWizard(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
33+
super(remoteRobot, remoteComponent);
34+
}
35+
36+
/**
37+
* Move to the previous page of the 'New Project' dialog by clicking on the 'Previous' button
38+
*/
39+
public void previous() {
40+
clickOnButton(ButtonLabels.previousLabel);
41+
}
42+
43+
/**
44+
* Move to the next page of the 'New Project' dialog by clicking on the 'Next' button
45+
*/
46+
public void next() {
47+
clickOnButton(ButtonLabels.nextLabel);
48+
}
49+
50+
/**
51+
* Finish the 'New Project' dialog by clicking on the 'Finish' button
52+
*/
53+
public void finish() {
54+
clickOnButton(ButtonLabels.finishLabel);
55+
}
56+
57+
/**
58+
* Close the 'New Project' dialog by clicking on the 'Cancel' button
59+
*/
60+
public void cancel() {
61+
button(ButtonLabels.cancelLabel).click();
62+
}
63+
64+
private void clickOnButton(String label) {
65+
JButtonFixture button;
66+
try {
67+
button = button(label);
68+
} catch (WaitForConditionTimeoutException e) {
69+
throw new UITestException("The '" + label + "' button has not been found.");
70+
}
71+
72+
if (button.isEnabled()) {
73+
button.click();
74+
} else {
75+
throw new UITestException("The '" + label + "' button is not enabled.");
76+
}
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.project.pages;
12+
13+
import com.intellij.remoterobot.RemoteRobot;
14+
import com.intellij.remoterobot.data.RemoteComponent;
15+
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
16+
import com.intellij.remoterobot.fixtures.DefaultXpath;
17+
import com.intellij.remoterobot.fixtures.FixtureName;
18+
import com.intellij.remoterobot.fixtures.JTextFieldFixture;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
/**
22+
* New Project dialog abstract terminal page fixture
23+
*
24+
25+
*/
26+
@DefaultXpath(by = "MyDialog type", xpath = "//div[@class='DialogRootPane']")
27+
@FixtureName(name = "New Project Dialog")
28+
public abstract class AbstractNewProjectFinalPage extends CommonContainerFixture {
29+
public AbstractNewProjectFinalPage(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
30+
super(remoteRobot, remoteComponent);
31+
}
32+
33+
/**
34+
* Get the project name for new project in the 'New Project' dialog
35+
*
36+
* @return currently set new project name
37+
*/
38+
public String getProjectName() {
39+
return textFields(JTextFieldFixture.Companion.byType()).get(0).getText();
40+
}
41+
42+
/**
43+
* Set the project name for new project in the 'New Project' dialog
44+
*
45+
* @param projectName name of the new project
46+
*/
47+
public void setProjectName(String projectName) {
48+
textFields(JTextFieldFixture.Companion.byType()).get(0).setText(projectName);
49+
}
50+
51+
/**
52+
* Get the project location for new project in the 'New Project' dialog
53+
*
54+
* @return currently set new project location
55+
*/
56+
public String getProjectLocation() {
57+
return textFields(JTextFieldFixture.Companion.byType()).get(1).getText();
58+
}
59+
60+
/**
61+
* Set the project location for new project in the 'New Project' dialog
62+
*
63+
* @param projectLocation project location of the new project
64+
*/
65+
public void setProjectLocation(String projectLocation) {
66+
textFields(JTextFieldFixture.Companion.byType()).get(1).setText(projectLocation);
67+
}
68+
69+
/**
70+
* Enumeration defining values of the 'Project format' combo box
71+
*/
72+
public enum ProjectFormatType {
73+
IDEA_DIRECTORY_BASED(".idea"),
74+
IPR_FILE_BASED(".ipr");
75+
76+
private String textRepresentation;
77+
78+
ProjectFormatType(String textRepresentation) {
79+
this.textRepresentation = textRepresentation;
80+
}
81+
82+
@Override
83+
public String toString() {
84+
return this.textRepresentation;
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)