@@ -3,122 +3,122 @@ import { command } from 'webdriver';
3
3
import path from 'path' ;
4
4
5
5
export async function registerCommands ( ) {
6
- const utils = await import (
7
- path . join (
8
- require . resolve ( 'webdriverio' ) . replace ( 'cjs/index.js' , '' ) ,
9
- 'utils' ,
10
- 'getElementObject.js' ,
11
- )
12
- ) ;
6
+ const utils = await import (
7
+ path . join (
8
+ require . resolve ( 'webdriverio' ) . replace ( 'cjs/index.js' , '' ) ,
9
+ 'utils' ,
10
+ 'getElementObject.js' ,
11
+ )
12
+ ) ;
13
13
14
- function handler ( multi : boolean = false ) {
15
- return async function ( value : string ) {
16
- let findElement ;
14
+ function handler ( multi : boolean = false ) {
15
+ return async function ( value : string ) {
16
+ let findElement ;
17
17
18
- let args = [ 'key' , value ] ;
19
- let suffix = multi ? 'elements' : 'element' ;
20
- if ( this [ 'elementId' ] ) {
21
- args = [ this [ 'elementId' ] , 'key' , value ] ;
22
- findElement = command (
23
- 'POST' ,
24
- `/session/:sessionId/element/:elementId/${ suffix } ` ,
25
- {
26
- command : 'flutterFinderByKey' ,
27
- description : 'a new WebDriver command' ,
28
- ref : 'https://vendor.com/commands/#myNewCommand' ,
29
- variables : [
30
- {
31
- name : 'elementId' ,
32
- type : 'string' ,
33
- description : 'a valid parameter' ,
34
- required : true ,
35
- } ,
36
- ] ,
37
- parameters : [
38
- {
39
- name : 'using' ,
40
- type : 'string' ,
41
- description : 'a valid parameter' ,
42
- required : true ,
43
- } ,
44
- {
45
- name : 'value' ,
46
- type : 'string' ,
47
- description : 'a valid parameter' ,
48
- required : true ,
49
- } ,
50
- ] ,
51
- returns : {
52
- type : 'object' ,
53
- name : 'element' ,
54
- description :
55
- "A JSON representation of an element object, e.g. `{ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT_1' }`." ,
56
- } ,
57
- } ,
58
- ) ;
59
- } else {
60
- findElement = command ( 'POST' , `/session/:sessionId/${ suffix } ` , {
61
- command : 'flutterFinderByKey' ,
62
- description : 'a new WebDriver command' ,
63
- ref : 'https://vendor.com/commands/#myNewCommand' ,
64
- variables : [ ] ,
65
- parameters : [
66
- {
67
- name : 'using' ,
68
- type : 'string' ,
69
- description : 'a valid parameter' ,
70
- required : true ,
71
- } ,
72
- {
73
- name : 'value' ,
74
- type : 'string' ,
75
- description : 'a valid parameter' ,
76
- required : true ,
77
- } ,
78
- {
79
- name : 'context' ,
80
- type : 'string' ,
81
- description : 'a valid parameter' ,
82
- required : false ,
83
- } ,
84
- ] ,
85
- returns : {
86
- type : 'object' ,
87
- name : 'element' ,
88
- description :
89
- "A JSON representation of an element object, e.g. `{ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT_1' }`." ,
90
- } ,
91
- } ) ;
92
- }
18
+ let args = [ 'key' , value ] ;
19
+ let suffix = multi ? 'elements' : 'element' ;
20
+ if ( this [ 'elementId' ] ) {
21
+ args = [ this [ 'elementId' ] , 'key' , value ] ;
22
+ findElement = command (
23
+ 'POST' ,
24
+ `/session/:sessionId/element/:elementId/${ suffix } ` ,
25
+ {
26
+ command : 'flutterFinderByKey' ,
27
+ description : 'a new WebDriver command' ,
28
+ ref : 'https://vendor.com/commands/#myNewCommand' ,
29
+ variables : [
30
+ {
31
+ name : 'elementId' ,
32
+ type : 'string' ,
33
+ description : 'a valid parameter' ,
34
+ required : true ,
35
+ } ,
36
+ ] ,
37
+ parameters : [
38
+ {
39
+ name : 'using' ,
40
+ type : 'string' ,
41
+ description : 'a valid parameter' ,
42
+ required : true ,
43
+ } ,
44
+ {
45
+ name : 'value' ,
46
+ type : 'string' ,
47
+ description : 'a valid parameter' ,
48
+ required : true ,
49
+ } ,
50
+ ] ,
51
+ returns : {
52
+ type : 'object' ,
53
+ name : 'element' ,
54
+ description :
55
+ "A JSON representation of an element object, e.g. `{ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT_1' }`." ,
56
+ } ,
57
+ } ,
58
+ ) ;
59
+ } else {
60
+ findElement = command ( 'POST' , `/session/:sessionId/${ suffix } ` , {
61
+ command : 'flutterFinderByKey' ,
62
+ description : 'a new WebDriver command' ,
63
+ ref : 'https://vendor.com/commands/#myNewCommand' ,
64
+ variables : [ ] ,
65
+ parameters : [
66
+ {
67
+ name : 'using' ,
68
+ type : 'string' ,
69
+ description : 'a valid parameter' ,
70
+ required : true ,
71
+ } ,
72
+ {
73
+ name : 'value' ,
74
+ type : 'string' ,
75
+ description : 'a valid parameter' ,
76
+ required : true ,
77
+ } ,
78
+ {
79
+ name : 'context' ,
80
+ type : 'string' ,
81
+ description : 'a valid parameter' ,
82
+ required : false ,
83
+ } ,
84
+ ] ,
85
+ returns : {
86
+ type : 'object' ,
87
+ name : 'element' ,
88
+ description :
89
+ "A JSON representation of an element object, e.g. `{ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT_1' }`." ,
90
+ } ,
91
+ } ) ;
92
+ }
93
93
94
- const response = await findElement . call ( browser , ...args ) ;
95
- console . log ( utils . getElement ) ;
96
- try {
97
- if ( multi ) {
98
- return response . map ( ( element : any ) =>
99
- utils . getElement . call ( this , null , element ) ,
100
- ) ;
101
- } else {
102
- return utils . getElement . call ( this , null , response ) ;
103
- }
104
- } catch ( e ) {
105
- console . log ( e ) ;
106
- }
107
- } ;
108
- }
109
- browser . addCommand ( 'flutterFinderByKey$' , handler ( ) ) ;
110
- browser . addCommand ( 'flutterFinderByKey$' , handler ( ) , true ) ;
94
+ const response = await findElement . call ( browser , ...args ) ;
95
+ console . log ( utils . getElement ) ;
96
+ try {
97
+ if ( multi ) {
98
+ return response . map ( ( element : any ) =>
99
+ utils . getElement . call ( this , null , element ) ,
100
+ ) ;
101
+ } else {
102
+ return utils . getElement . call ( this , null , response ) ;
103
+ }
104
+ } catch ( e ) {
105
+ console . log ( e ) ;
106
+ }
107
+ } ;
108
+ }
109
+ browser . addCommand ( 'flutterFinderByKey$' , handler ( ) ) ;
110
+ browser . addCommand ( 'flutterFinderByKey$' , handler ( ) , true ) ;
111
111
112
- browser . addCommand ( 'flutterFinderByKey$$' , handler ( true ) ) ;
113
- browser . addCommand ( 'flutterFinderByKey$$' , handler ( true ) , true ) ;
112
+ browser . addCommand ( 'flutterFinderByKey$$' , handler ( true ) ) ;
113
+ browser . addCommand ( 'flutterFinderByKey$$' , handler ( true ) , true ) ;
114
114
115
- /**
116
- *
117
- * 1. Element visible
118
- * 2. Element not visible
119
- * 3. element enable/disabled
120
- * 4. Element count
121
- * 6.
122
- *
123
- */
115
+ /**
116
+ *
117
+ * 1. Element visible
118
+ * 2. Element not visible
119
+ * 3. element enable/disabled
120
+ * 4. Element count
121
+ * 6.
122
+ *
123
+ */
124
124
}
0 commit comments