21
21
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
22
*/
23
23
24
- import { By , until , WebElement , Key , error , WebDriver } from "selenium-webdriver" ;
24
+ import { until , WebElement , Key , error , WebDriver } from "selenium-webdriver" ;
25
25
import { explicitWait , IDBConnection } from "./misc.js" ;
26
+ import * as locator from "../lib/locators.js" ;
26
27
27
28
export const execFullBlockSql = "Execute the selection or everything in the current block and create a new block" ;
28
29
export const execFullBlockJs = "Execute everything in the current block and create a new block" ;
@@ -43,11 +44,11 @@ export class DBNotebooks {
43
44
* @returns Promise resolving when the select is made
44
45
*/
45
46
public static selectDBType = async ( driver : WebDriver , value : string ) : Promise < void > => {
46
- await driver . findElement ( By . id ( " databaseType" ) ) . click ( ) ;
47
- const dropDownList = await driver . findElement ( By . css ( ".dropdownList" ) ) ;
48
- const els = await dropDownList . findElements ( By . css ( " div" ) ) ;
47
+ await driver . findElement ( locator . databaseConnectionConfiguration . databaseType . exists ) . click ( ) ;
48
+ const dropDownList = await driver . findElement ( locator . databaseConnectionConfiguration . databaseType . list ) ;
49
+ const els = await dropDownList . findElements ( locator . htmlTag . div ) ;
49
50
if ( els . length > 0 ) {
50
- await dropDownList . findElement ( By . id ( value ) ) . click ( ) ;
51
+ await dropDownList . findElement ( locator . searchById ( value ) ) . click ( ) ;
51
52
}
52
53
} ;
53
54
@@ -58,9 +59,9 @@ export class DBNotebooks {
58
59
* @returns Promise resolving when the select is made
59
60
*/
60
61
public static setProtocol = async ( driver : WebDriver , value : string ) : Promise < void > => {
61
- await driver . findElement ( By . id ( "scheme" ) ) . click ( ) ;
62
- const dropDownList = await driver . findElement ( By . css ( ".dropdownList" ) ) ;
63
- await dropDownList . findElement ( By . id ( value ) ) . click ( ) ;
62
+ await driver . findElement ( locator . databaseConnectionConfiguration . mysql . basic . protocol . exists ) . click ( ) ;
63
+ const dropDownList = await driver . findElement ( locator . databaseConnectionConfiguration . mysql . basic . protocol . list ) ;
64
+ await dropDownList . findElement ( locator . searchById ( value ) ) . click ( ) ;
64
65
} ;
65
66
66
67
/**
@@ -70,9 +71,9 @@ export class DBNotebooks {
70
71
* @returns Promise resolving when the select is made
71
72
*/
72
73
public static setSSLMode = async ( driver : WebDriver , value : string ) : Promise < void > => {
73
- await driver . findElement ( By . id ( "sslMode" ) ) . click ( ) ;
74
- const dropDownList = await driver . findElement ( By . css ( ".dropdownList" ) ) ;
75
- await dropDownList . findElement ( By . id ( value ) ) . click ( ) ;
74
+ await driver . findElement ( locator . databaseConnectionConfiguration . mysql . ssl . mode ) . click ( ) ;
75
+ const dropDownList = await driver . findElement ( locator . databaseConnectionConfiguration . mysql . ssl . modeList . exists ) ;
76
+ await dropDownList . findElement ( locator . searchById ( value ) ) . click ( ) ;
76
77
} ;
77
78
78
79
/**
@@ -83,16 +84,16 @@ export class DBNotebooks {
83
84
* @returns Promise resolving with the connection created
84
85
*/
85
86
public static createDBconnection = async ( driver : WebDriver , dbConfig : IDBConnection ) : Promise < WebElement | undefined > => {
86
- const ctx = await driver . wait ( until . elementLocated ( By . css ( ".connectionBrowser" ) ) ,
87
+ const ctx = await driver . wait ( until . elementLocated ( locator . dbConnections . browser ) ,
87
88
explicitWait , "DB Connection Overview page was not loaded" ) ;
88
89
89
90
await driver . wait ( async ( ) => {
90
- const isDialogVisible = ( await driver . findElements ( By . css ( ".valueEditDialog" ) ) ) . length > 0 ;
91
+ const isDialogVisible = ( await driver . findElements ( locator . databaseConnectionConfiguration . exists ) ) . length > 0 ;
91
92
if ( isDialogVisible ) {
92
93
return true ;
93
94
} else {
94
95
try {
95
- await ctx . findElement ( By . id ( "-1" ) ) . click ( ) ;
96
+ await ctx . findElement ( locator . dbConnections . newConnection ) . click ( ) ;
96
97
} catch ( e ) {
97
98
if ( ! ( e instanceof error . ElementClickInterceptedError ) ) {
98
99
throw e ;
@@ -103,56 +104,56 @@ export class DBNotebooks {
103
104
}
104
105
} , explicitWait , "Connection dialog was not displayed" ) ;
105
106
106
- const newConDialog = await driver . findElement ( By . css ( ".valueEditDialog" ) ) ;
107
+ const newConDialog = await driver . findElement ( locator . databaseConnectionConfiguration . exists ) ;
107
108
108
109
await driver . wait ( async ( ) => {
109
- await newConDialog . findElement ( By . id ( " caption" ) ) . clear ( ) ;
110
+ await newConDialog . findElement ( locator . databaseConnectionConfiguration . caption ) . clear ( ) ;
110
111
111
112
return ! ( await driver . executeScript ( "return document.querySelector('#caption').value" ) ) ;
112
113
} , 3000 , "caption was not cleared in time" ) ;
113
- await newConDialog . findElement ( By . id ( " caption" ) ) . sendKeys ( dbConfig . caption ) ;
114
- await newConDialog . findElement ( By . id ( " description" ) ) . clear ( ) ;
114
+ await newConDialog . findElement ( locator . databaseConnectionConfiguration . caption ) . sendKeys ( dbConfig . caption ) ;
115
+ await newConDialog . findElement ( locator . databaseConnectionConfiguration . description ) . clear ( ) ;
115
116
await newConDialog
116
- . findElement ( By . id ( " description" ) )
117
+ . findElement ( locator . databaseConnectionConfiguration . description )
117
118
. sendKeys ( dbConfig . description ) ;
118
- await newConDialog . findElement ( By . id ( "hostName" ) ) . clear ( ) ;
119
- await newConDialog . findElement ( By . id ( "hostName" ) ) . sendKeys ( String ( dbConfig . hostname ) ) ;
119
+ await newConDialog . findElement ( locator . databaseConnectionConfiguration . mysql . basic . hostname ) . clear ( ) ;
120
+ await newConDialog . findElement ( locator . databaseConnectionConfiguration . mysql . basic . hostname ) . sendKeys ( String ( dbConfig . hostname ) ) ;
120
121
await DBNotebooks . setProtocol ( driver , dbConfig . protocol ) ;
121
- await driver . findElement ( By . css ( "# port input" ) ) . clear ( ) ;
122
- await driver . findElement ( By . css ( "# port input" ) ) . sendKeys ( String ( dbConfig . port ) ) ;
123
- await newConDialog . findElement ( By . id ( "userName" ) ) . sendKeys ( String ( dbConfig . username ) ) ;
122
+ await driver . findElement ( locator . databaseConnectionConfiguration . mysql . basic . port ) . clear ( ) ;
123
+ await driver . findElement ( locator . databaseConnectionConfiguration . mysql . basic . port ) . sendKeys ( String ( dbConfig . port ) ) ;
124
+ await newConDialog . findElement ( locator . databaseConnectionConfiguration . mysql . basic . username ) . sendKeys ( String ( dbConfig . username ) ) ;
124
125
await newConDialog
125
- . findElement ( By . id ( "defaultSchema" ) )
126
+ . findElement ( locator . databaseConnectionConfiguration . mysql . basic . schema )
126
127
. sendKeys ( String ( dbConfig . schema ) ) ;
127
128
128
129
if ( dbConfig . dbType ) {
129
130
await DBNotebooks . selectDBType ( driver , dbConfig . dbType ) ;
130
131
}
131
132
132
133
if ( dbConfig . sslMode ) {
133
- await newConDialog . findElement ( By . id ( "page1" ) ) . click ( ) ;
134
- await newConDialog . findElement ( By . id ( "sslMode" ) ) . click ( ) ;
135
- const dropDownList = await driver . findElement ( By . css ( ".noArrow.dropdownList" ) ) ;
136
- await dropDownList . findElement ( By . id ( dbConfig . sslMode ) ) . click ( ) ;
137
- expect ( await newConDialog . findElement ( By . css ( "#sslMode label" ) ) . getText ( ) )
134
+ await newConDialog . findElement ( locator . databaseConnectionConfiguration . sslTab ) . click ( ) ;
135
+ await newConDialog . findElement ( locator . databaseConnectionConfiguration . mysql . ssl . mode ) . click ( ) ;
136
+ const dropDownList = await driver . findElement ( locator . databaseConnectionConfiguration . mysql . ssl . modeList . exists ) ;
137
+ await dropDownList . findElement ( locator . searchById ( dbConfig . sslMode ) ) . click ( ) ;
138
+ expect ( await newConDialog . findElement ( locator . databaseConnectionConfiguration . mysql . ssl . modeLabel ) . getText ( ) )
138
139
. toBe ( dbConfig . sslMode ) ;
139
140
140
141
const certsPath = process . env . SSLCERTSPATH as string ;
141
- const paths = await newConDialog . findElements ( By . css ( ".tabview.top input.msg" ) ) ;
142
+ const paths = await newConDialog . findElements ( locator . databaseConnectionConfiguration . mysql . ssl . inputs ) ;
142
143
await paths [ 0 ] . sendKeys ( `${ certsPath } /ca-cert.pem` ) ;
143
144
await paths [ 1 ] . sendKeys ( `${ certsPath } /client-cert.pem` ) ;
144
145
await paths [ 2 ] . sendKeys ( `${ certsPath } /client-key.pem` ) ;
145
146
}
146
147
147
- const okBtn = await driver . findElement ( By . id ( "ok" ) ) ;
148
+ const okBtn = await driver . findElement ( locator . databaseConnectionConfiguration . ok ) ;
148
149
await driver . executeScript ( "arguments[0].scrollIntoView(true)" , okBtn ) ;
149
150
await okBtn . click ( ) ;
150
- expect ( ( await driver . findElements ( By . css ( ".valueEditDialog" ) ) ) . length ) . toBe ( 0 ) ;
151
+ expect ( ( await driver . findElements ( locator . databaseConnectionConfiguration . exists ) ) . length ) . toBe ( 0 ) ;
151
152
152
153
return driver . wait ( async ( ) => {
153
- const connections = await driver . findElements ( By . css ( "#tilesHost .connectionTile" ) ) ;
154
+ const connections = await driver . findElements ( locator . dbConnections . connections . item ) ;
154
155
for ( const connection of connections ) {
155
- const el = await connection . findElement ( By . css ( ".textHost .tileCaption" ) ) ;
156
+ const el = await connection . findElement ( locator . dbConnections . connections . caption ) ;
156
157
if ( ( await el . getAttribute ( "innerHTML" ) ) . includes ( dbConfig . caption ) ) {
157
158
return connection ;
158
159
}
@@ -170,9 +171,9 @@ export class DBNotebooks {
170
171
public static getConnection = async ( driver : WebDriver , name : string ) : Promise < WebElement | undefined > => {
171
172
172
173
return driver . wait ( async ( ) => {
173
- const connections = await driver . findElements ( By . css ( "#tilesHost .connectionTile" ) ) ;
174
+ const connections = await driver . findElements ( locator . dbConnections . connections . item ) ;
174
175
for ( const connection of connections ) {
175
- const el = await connection . findElement ( By . css ( ".textHost .tileCaption" ) ) ;
176
+ const el = await connection . findElement ( locator . dbConnections . connections . caption ) ;
176
177
if ( ( await el . getAttribute ( "innerHTML" ) ) . includes ( name ) ) {
177
178
return connection ;
178
179
}
@@ -182,35 +183,36 @@ export class DBNotebooks {
182
183
} ;
183
184
184
185
public static clickConnectionItem = async ( driver : WebDriver , conn : WebElement , item : string ) : Promise < void > => {
185
- const moreActions = await conn . findElement ( By . id ( "tileMoreActionsAction" ) ) ;
186
+ const moreActions = await conn . findElement ( locator . dbConnections . connections . actions . moreActions ) ;
186
187
const moreActionsRect = await moreActions . getRect ( ) ;
187
188
await driver . actions ( ) . move ( {
188
189
x : parseInt ( `${ moreActionsRect . x } ` , 10 ) ,
189
190
y : parseInt ( `${ moreActionsRect . y } ` , 10 ) ,
190
191
} ) . perform ( ) ;
191
192
switch ( item ) {
192
193
case "notebook" : {
193
- await conn . findElement ( By . id ( "tileNewNotebookAction" ) ) . click ( ) ;
194
+ await conn . findElement ( locator . dbConnections . connections . actions . newNotebook ) . click ( ) ;
194
195
break ;
195
196
}
196
197
case "script" : {
197
- await conn . findElement ( By . id ( "tileNewScriptAction" ) ) . click ( ) ;
198
+ await conn . findElement ( locator . dbConnections . connections . actions . newScript ) . click ( ) ;
198
199
break ;
199
200
}
200
201
case "edit" : {
201
202
await moreActions . click ( ) ;
202
- await driver . wait ( until . elementLocated ( By . id ( "edit" ) ) , explicitWait , "Edit button not found" ) . click ( ) ;
203
+ await driver . wait ( until . elementLocated ( locator . dbConnections . connections . actions . edit ) ,
204
+ explicitWait , "Edit button not found" ) . click ( ) ;
203
205
break ;
204
206
}
205
207
case "duplicate" : {
206
208
await moreActions . click ( ) ;
207
- await driver . wait ( until . elementLocated ( By . id ( " duplicate" ) ) ,
209
+ await driver . wait ( until . elementLocated ( locator . dbConnections . connections . actions . duplicate ) ,
208
210
explicitWait , "Duplicate button not found" ) . click ( ) ;
209
211
break ;
210
212
}
211
213
case "remove" : {
212
214
await moreActions . click ( ) ;
213
- await driver . wait ( until . elementLocated ( By . id ( " remove" ) ) ,
215
+ await driver . wait ( until . elementLocated ( locator . dbConnections . connections . actions . remove ) ,
214
216
explicitWait , "Remove button not found" ) . click ( ) ;
215
217
break ;
216
218
}
@@ -227,7 +229,7 @@ export class DBNotebooks {
227
229
*/
228
230
public static getAutoCompleteMenuItems = async ( driver : WebDriver , ) : Promise < string [ ] > => {
229
231
const els = [ ] ;
230
- let items = await driver . wait ( until . elementsLocated ( By . css ( ".monaco-list .monaco-highlighted-label" ) ) ,
232
+ let items = await driver . wait ( until . elementsLocated ( locator . notebook . codeEditor . autoCompleteItems ) ,
231
233
explicitWait , "Auto complete items were not displayed" ) ;
232
234
233
235
for ( const item of items ) {
@@ -236,15 +238,14 @@ export class DBNotebooks {
236
238
237
239
await driver . actions ( ) . sendKeys ( Key . ARROW_UP ) . perform ( ) ;
238
240
239
- items = await driver . wait ( until . elementsLocated ( By . css ( ".monaco-list .monaco-highlighted-label" ) ) ,
241
+ items = await driver . wait ( until . elementsLocated ( locator . notebook . codeEditor . autoCompleteItems ) ,
240
242
explicitWait , "Auto complete items were not displayed" ) ;
241
243
242
244
for ( const item of items ) {
243
245
els . push ( await item . getText ( ) ) ;
244
246
}
245
247
246
248
return [ ...new Set ( els ) ] ;
247
-
248
249
} ;
249
250
250
251
/**
@@ -253,9 +254,9 @@ export class DBNotebooks {
253
254
* @returns A promise resolving with the line number
254
255
*/
255
256
public static getMouseCursorLine = async ( driver : WebDriver ) : Promise < number | undefined > => {
256
- const lines = await driver . findElements ( By . css ( ".view-overlays > div" ) ) ;
257
+ const lines = await driver . findElements ( locator . notebook . codeEditor . editor . cursorLine ) ;
257
258
for ( let i = 0 ; i <= lines . length - 1 ; i ++ ) {
258
- const curLine = await lines [ i ] . findElements ( By . className ( "current-line" ) ) ;
259
+ const curLine = await lines [ i ] . findElements ( locator . notebook . codeEditor . editor . currentLine ) ;
259
260
if ( curLine . length > 0 ) {
260
261
return i ;
261
262
}
@@ -277,7 +278,7 @@ export class DBNotebooks {
277
278
let line ;
278
279
await driver . wait ( async ( ) => {
279
280
try {
280
- const lines = await driver . findElements ( By . css ( ".view-lines.monaco-mouse-cursor-text > div" ) ) ;
281
+ const lines = await driver . findElements ( locator . notebook . codeEditor . editor . editorPrompt ) ;
281
282
for ( let i = 0 ; i <= lines . length - 1 ; i ++ ) {
282
283
const lineContent = await lines [ i ] . getAttribute ( "innerHTML" ) ;
283
284
if ( lineContent . match ( regex ) ) {
@@ -308,11 +309,9 @@ export class DBNotebooks {
308
309
*/
309
310
public static setMouseCursorAt = async ( driver : WebDriver , word : string ) : Promise < void > => {
310
311
const mouseCursorIs = await DBNotebooks . getMouseCursorLine ( driver ) ;
311
- console . log ( `mouseCursorIs: ${ mouseCursorIs } ` ) ;
312
312
const mouseCursorShouldBe = await DBNotebooks . getLineFromWord ( driver , word ) ;
313
- console . log ( `mouseCursorShouldBe: ${ mouseCursorShouldBe } ` ) ;
314
313
const taps = mouseCursorShouldBe - mouseCursorIs ! ;
315
- const textArea = await driver . findElement ( By . css ( "textarea" ) ) ;
314
+ const textArea = await driver . findElement ( locator . notebook . codeEditor . textArea ) ;
316
315
if ( taps > 0 ) {
317
316
for ( let i = 0 ; i < taps ; i ++ ) {
318
317
await textArea . sendKeys ( Key . ARROW_DOWN ) ;
0 commit comments