66
77package io.flutter.integrationTest
88
9- import com.intellij.driver.sdk.ui.Finder
10- import com.intellij.driver.sdk.ui.components.ComponentData
11- import com.intellij.driver.sdk.ui.components.UiComponent
129import com.intellij.driver.sdk.ui.components.UiComponent.Companion.waitFound
1310import com.intellij.driver.sdk.ui.components.common.ideFrame
1411import com.intellij.driver.sdk.ui.components.common.toolwindows.projectView
15- import com.intellij.driver.sdk.ui.components.common.welcomeScreen
16- import com.intellij.driver.sdk.wait
1712import com.intellij.driver.sdk.waitForIndicators
1813import com.intellij.ide.starter.driver.engine.BackgroundRun
1914import com.intellij.ide.starter.driver.engine.runIdeWithDriver
2015import com.intellij.ide.starter.junit5.config.UseLatestDownloadedIdeBuild
16+ import io.flutter.integrationTest.utils.newProjectWelcomeScreen
2117import org.junit.jupiter.api.*
2218import org.junit.jupiter.api.extension.ExtendWith
2319import java.nio.file.Paths
2420import kotlin.time.Duration.Companion.minutes
25- import kotlin.time.Duration.Companion.seconds
2621
2722@Tag(" ui" )
2823@TestInstance(TestInstance .Lifecycle .PER_METHOD )
@@ -87,7 +82,7 @@ class MyProjectUITest {
8782 println (" Test project will be created as: $testProjectName " )
8883 run = Setup .setupTestContextIC(" MyProjectUITest" ).runIdeWithDriver()
8984
90- newProjectWelcomeScreen()
85+ newProjectWelcomeScreen(run, testProjectName )
9186 newProjectInProjectView()
9287 }
9388
@@ -98,7 +93,7 @@ class MyProjectUITest {
9893 println (" Test project will be created as: $testProjectName " )
9994 run = Setup .setupTestContextUE(" MyProjectUITest" ).runIdeWithDriver()
10095
101- newProjectWelcomeScreen()
96+ newProjectWelcomeScreen(run, testProjectName )
10297 run.driver.withContext {
10398 ideFrame {
10499 // Wait for the ideFrame to appear before attempting to interact with it.
@@ -115,58 +110,10 @@ class MyProjectUITest {
115110 println (" Test project will be created as: $testProjectName " )
116111 run = Setup .setupTestContextWS(" MyProjectUITest" ).runIdeWithDriver()
117112
118- newProjectWelcomeScreen()
113+ newProjectWelcomeScreen(run, testProjectName )
119114 newProjectInProjectView()
120115 }
121116
122-
123- /* *
124- * Automates the process of creating a new Flutter project from the welcome screen.
125- * <p>
126- * This function navigates the "New Project" dialog, selects the Flutter project type,
127- * and enters a unique project name. It relies on the {@code FLUTTER_SDK} environment
128- * variable to be set for the test to proceed.
129- */
130- fun newProjectWelcomeScreen () {
131- run.driver.withContext {
132- // Assert that the welcome screen is visible before interacting with it.
133- welcomeScreen {
134- assert (isVisible())
135- println (" Creating the new project from Welcome Screen" )
136- createNewProjectButton.click()
137-
138- // The test expects the `FlutterGeneratorPeer` to automatically populate the
139- // Flutter SDK path. This behavior relies on the FLUTTER_SDK environment
140- // variable being set.
141- //
142- // If the FLUTTER_SDK variable is not present, the UI will not find the SDK,
143- // and the 'Next' button will remain disabled, causing the test to fail.
144- // A common reason for this failure is an unconfigured test environment.
145-
146- newProjectDialog {
147- // Wait for the dialog to fully load
148- wait(1 .seconds)
149-
150- // Select project type - adjust based on your needs
151- chooseProjectType(" Flutter" )
152- wait(1 .seconds)
153-
154- // Expect setup to take care of setting the correct Flutter SDK
155- if (! nextButton.isEnabled()) {
156- fail { " The FLUTTER_SDK environment variable was not set." }
157- }
158- nextButton.click()
159- wait(1 .seconds)
160-
161- keyboard {
162- typeText(testProjectName)
163- }
164- createButton.click()
165- }
166- }
167- }
168- }
169-
170117 /* *
171118 * Verifies the successful creation of a new project by asserting the presence
172119 * and structure of files in the project view.
@@ -226,47 +173,3 @@ class MyProjectUITest {
226173 }
227174 }
228175}
229-
230- //
231- // TODO(jwren) move this into a utility for project creation tasks
232- //
233-
234- // A Kotlin extension function for the `Finder` class.
235- // This function adds a new method, `newProjectDialog`, that can be
236- // called on any `Finder` object.
237- fun Finder.newProjectDialog (action : NewProjectDialogUI .() -> Unit ) {
238- // Locates the "New Project" dialog.
239- // - `x(...)` creates an XPath-like query to find the UI component.
240- // - The query targets a `div` with a `title` of "New Project".
241- // - `NewProjectDialogUI::class.java` specifies that the found component
242- // should be treated as an instance of the `NewProjectDialogUI` class,
243- // allowing access to its properties and functions.
244- //
245- // The found dialog component is then passed to the `action` lambda,
246- // which contains the test steps to perform within the dialog.
247- x(" //div[@title='New Project']" , NewProjectDialogUI ::class .java).action()
248- }
249-
250- // A UI component representing the "New Project" dialog.
251- // This class provides a structured way to interact with the dialog's elements
252- // using the IntelliJ Driver SDK.
253- open class NewProjectDialogUI (data : ComponentData ) : UiComponent(data) {
254-
255- // Clicks on the specified project type from the list.
256- // The function waits until the text is found before performing the click action.
257- fun chooseProjectType (projectType : String ) {
258- projectTypeList.waitOneText(projectType).click()
259- }
260-
261- // Locates the list of project types within the dialog.
262- // The xQuery targets a component with the specific class "JBList".
263- private val projectTypeList = x(" //div[@class='JBList']" )
264-
265- // Locates the "Next" button in the dialog.
266- // The xQuery finds a button component with the visible text "Next".
267- val nextButton = x(" //div[@text='Next']" )
268-
269- // Locates the "Create" button in the dialog.
270- // The xQuery finds a button component with the visible text "Create".
271- val createButton = x(" //div[@text='Create']" )
272- }
0 commit comments