1+ package org.utbot.dialogs
2+
3+ import com.intellij.remoterobot.RemoteRobot
4+ import com.intellij.remoterobot.data.RemoteComponent
5+ import com.intellij.remoterobot.fixtures.*
6+ import com.intellij.remoterobot.search.locators.byXpath
7+ import com.intellij.remoterobot.stepsProcessing.step
8+ import com.intellij.remoterobot.utils.Keyboard
9+ import com.intellij.remoterobot.utils.waitFor
10+ import org.utbot.data.IdeaBuildSystem
11+ import org.utbot.data.JDKVersion
12+ import java.awt.event.KeyEvent
13+ import java.time.Duration
14+ import java.time.Duration.ofSeconds
15+
16+ @FixtureName(" NewProjectDialog" )
17+ @DefaultXpath(" type" , " //*[contains(@title.key, 'title.new.project')]" )
18+ class NewProjectDialogFixture (remoteRobot : RemoteRobot , remoteComponent : RemoteComponent )
19+ : DialogFixture (remoteRobot, remoteComponent) {
20+ val keyboard: Keyboard = Keyboard (remoteRobot)
21+
22+ val wizardsList
23+ get() = jList(
24+ byXpath(" //div[@class='JBList']" ))
25+
26+ val nameInput
27+ get() = textField(
28+ byXpath(" //div[@class='JBTextField']" ))
29+
30+ val locationInput
31+ get() = textField(
32+ byXpath(" //div[@class='ExtendableTextField']" ))
33+
34+ val addSampleCodeCheckbox
35+ get() = checkBox(
36+ byXpath(" //div[@text.key='label.project.wizard.new.project.add.sample.code']" ))
37+
38+ val jdkComboBox
39+ get() = comboBox(
40+ byXpath(" //div[@class='JdkComboBox']" ),
41+ Duration .ofSeconds(10 ))
42+
43+ val jdkList
44+ get() = heavyWeightWindow().itemsList
45+
46+ val createButton
47+ get() = button(
48+ byXpath(" //div[@text.key='button.create']" ))
49+
50+ val cancelButton
51+ get() = button(
52+ byXpath(" //div[@text.key='button.cancel']" ))
53+
54+ fun selectWizard (wizardName : String ) {
55+ if (title != wizardName) {
56+ wizardsList.findText(wizardName).click()
57+ }
58+ }
59+
60+ fun selectJDK (jdkVersion : String ) {
61+ step(" Select JDK: $jdkVersion " ) {
62+ jdkComboBox.click()
63+ try {
64+ waitFor(ofSeconds(10 )) {
65+ findAll<ComponentFixture >(byXpath(" //*[@text.key='progress.title.detecting.sdks']" )).isNotEmpty()
66+ }
67+ } catch (ignore: Throwable ) {}
68+ waitFor(ofSeconds(20 )) {
69+ findAll<ComponentFixture >(byXpath(" //*[@text.key='progress.title.detecting.sdks']" )).isEmpty()
70+ }
71+ val jdkMatching = jdkList.collectItems().first { it.contains(jdkVersion) }
72+ jdkList.clickItem(jdkMatching)
73+ }
74+ }
75+
76+ fun fillDialog (projectName : String ,
77+ location : String = "",
78+ language : String = "Java ",
79+ buildSystem : IdeaBuildSystem = IdeaBuildSystem .INTELLIJ ,
80+ jdkVersion : JDKVersion ,
81+ addSampleCode : Boolean = true) {
82+ step(" Fill New Project dialog" ) {
83+ nameInput.doubleClick()
84+ keyboard.hotKey(KeyEvent .VK_CONTROL , KeyEvent .VK_A )
85+ keyboard.enterText(projectName)
86+ if (location != " " ) {
87+ if (locationInput.hasText(location).not ()) {
88+ locationInput.doubleClick()
89+ keyboard.hotKey(KeyEvent .VK_CONTROL , KeyEvent .VK_A )
90+ keyboard.enterText(location.replace(" \\ " , " \\\\ " ))
91+ }
92+ }
93+ this .findText(language).click()
94+ this .findText(buildSystem.system).click()
95+ addSampleCodeCheckbox.setValue(addSampleCode)
96+ if (! jdkComboBox.selectedText().contains(jdkVersion.namePart)) {
97+ selectJDK(jdkVersion.namePart)
98+ }
99+ }
100+ }
101+ }
0 commit comments