1616// under the License.
1717
1818import {
19+ EmitterContext ,
1920 codeExport as exporter ,
2021 ExportFlexCommandShape ,
2122 PrebuildEmitter ,
2223 ProcessedCommandEmitter ,
2324 ScriptShape ,
2425} from 'side-code-export'
26+ // eslint-disable-next-line node/no-unpublished-import
2527import { CommandShape } from '@seleniumhq/side-model'
2628import location from './location'
2729import selection from './selection'
@@ -134,8 +136,9 @@ function register(command: string, emitter: PrebuildEmitter) {
134136 exporter . register . emitter ( { command, emitter, emitters } )
135137}
136138
137- function emit ( command : CommandShape ) {
139+ function emit ( command : CommandShape , context : EmitterContext ) {
138140 return exporter . emit . command ( command , emitters [ command . command ] , {
141+ context,
139142 variableLookup,
140143 emitNewWindowHandling,
141144 } )
@@ -182,7 +185,10 @@ function emitWaitForWindow() {
182185 } )
183186}
184187
185- async function emitNewWindowHandling ( command : CommandShape , emittedCommand : ExportFlexCommandShape ) {
188+ async function emitNewWindowHandling (
189+ command : CommandShape ,
190+ emittedCommand : ExportFlexCommandShape
191+ ) {
186192 return Promise . resolve (
187193 `vars["windowHandles"] = await driver.getAllWindowHandles()\n${ await emittedCommand } \nvars["${
188194 command . windowHandleName
@@ -309,7 +315,10 @@ function emitControlFlowIf(script: ScriptShape) {
309315 } )
310316}
311317
312- function emitControlFlowForEach ( collectionVarName : string , iteratorVarName : string ) {
318+ function emitControlFlowForEach (
319+ collectionVarName : string ,
320+ iteratorVarName : string
321+ ) {
313322 return Promise . resolve ( {
314323 commands : [
315324 {
@@ -519,12 +528,11 @@ async function emitMouseUp(locator: string) {
519528 return Promise . resolve ( { commands } )
520529}
521530
522- function emitOpen ( target : string ) {
531+ function emitOpen ( target : string , _value : unknown , context : EmitterContext ) {
523532 const url = / ^ ( f i l e | h t t p | h t t p s ) : \/ \/ / . test ( target )
524- ? `"${ target } "`
525- : // @ts -expect-error globals yuck
526- `"${ global . baseUrl } ${ target } "`
527- return Promise . resolve ( `await driver.get(${ url } )` )
533+ ? target
534+ : `${ context . project . url } ${ target } `
535+ return Promise . resolve ( `await driver.get("${ url } ")` )
528536}
529537
530538async function emitPause ( time : string ) {
@@ -837,7 +845,10 @@ async function emitVerifyNotEditable(locator: string) {
837845 return Promise . resolve ( { commands } )
838846}
839847
840- async function emitVerifyNotSelectedValue ( locator : string , expectedValue : string ) {
848+ async function emitVerifyNotSelectedValue (
849+ locator : string ,
850+ expectedValue : string
851+ ) {
841852 const commands = [
842853 { level : 0 , statement : `{` } ,
843854 {
@@ -848,7 +859,7 @@ async function emitVerifyNotSelectedValue(locator: string, expectedValue: string
848859 } ,
849860 {
850861 level : 1 ,
851- statement : `assert.equal(value, "${ exporter . emit . text ( expectedValue ) } ")`
862+ statement : `assert.equal(value, "${ exporter . emit . text ( expectedValue ) } ")` ,
852863 } ,
853864 { level : 0 , statement : `}` } ,
854865 ]
@@ -864,7 +875,10 @@ async function emitVerifyNotText(locator: string, text: string) {
864875 locator
865876 ) } ).getText()`,
866877 } ,
867- { level : 1 , statement : `assert.notEqual(text, "${ exporter . emit . text ( text ) } ")` } ,
878+ {
879+ level : 1 ,
880+ statement : `assert.notEqual(text, "${ exporter . emit . text ( text ) } ")` ,
881+ } ,
868882 { level : 0 , statement : `}` } ,
869883 ]
870884 return Promise . resolve ( { commands } )
0 commit comments