@@ -26,7 +26,10 @@ function makeHistory(steps: Partial<RecordedStep>[]): SessionHistory {
2626 sessionId : 'test-123' ,
2727 type : 'browser' ,
2828 startedAt : '2026-01-01T00:00:00.000Z' ,
29- capabilities : { } ,
29+ capabilities : {
30+ browserName : 'chrome' ,
31+ 'goog:chromeOptions' : { args : [ '--window-size=1920,1080' , '--headless=new' ] } ,
32+ } ,
3033 steps : [ START_BROWSER_STEP , ...extraSteps ] ,
3134 } ;
3235}
@@ -39,18 +42,61 @@ describe('generateCode - header', () => {
3942 expect ( code ) . toContain ( 'browserName' ) ;
4043 } ) ;
4144
42- it ( 'generates start_browser as const browser = await remote()' , ( ) => {
43- const code = generateCode ( makeHistory ( [ ] ) ) ;
45+ it ( 'generates start_browser using history.capabilities, not reconstructed from params' , ( ) => {
46+ const history : SessionHistory = {
47+ sessionId : 'caps-123' ,
48+ type : 'browser' ,
49+ startedAt : '2026-01-01T00:00:00.000Z' ,
50+ capabilities : {
51+ browserName : 'chrome' ,
52+ acceptInsecureCerts : true ,
53+ 'goog:chromeOptions' : { args : [ '--headless=new' , '--custom-flag' ] } ,
54+ } ,
55+ steps : [ {
56+ index : 1 ,
57+ tool : 'start_browser' ,
58+ params : { browser : 'chrome' , headless : true } ,
59+ status : 'ok' ,
60+ durationMs : 100 ,
61+ timestamp : '2026-01-01T00:00:00.000Z' ,
62+ } ] ,
63+ } ;
64+ const code = generateCode ( history ) ;
4465 expect ( code ) . toContain ( 'const browser = await remote(' ) ;
4566 expect ( code ) . toContain ( '"browserName": "chrome"' ) ;
67+ expect ( code ) . toContain ( '--custom-flag' ) ; // only present in history.capabilities
68+ } ) ;
69+
70+ it ( 'generates attach_browser using history.capabilities' , ( ) => {
71+ const history : SessionHistory = {
72+ sessionId : 'attach-123' ,
73+ type : 'browser' ,
74+ startedAt : '2026-01-01T00:00:00.000Z' ,
75+ capabilities : {
76+ browserName : 'chrome' ,
77+ 'goog:chromeOptions' : { debuggerAddress : 'localhost:9222' , args : [ '--user-data-dir=/tmp/chrome-debug' ] } ,
78+ } ,
79+ steps : [ {
80+ index : 1 ,
81+ tool : 'attach_browser' ,
82+ params : { port : 9222 , host : 'localhost' , userDataDir : '/tmp/chrome-debug' } ,
83+ status : 'ok' ,
84+ durationMs : 100 ,
85+ timestamp : '2026-01-01T00:00:00.000Z' ,
86+ } ] ,
87+ } ;
88+ const code = generateCode ( history ) ;
89+ expect ( code ) . toContain ( 'const browser = await remote(' ) ;
90+ expect ( code ) . toContain ( '"debuggerAddress": "localhost:9222"' ) ;
91+ expect ( code ) . toContain ( '--user-data-dir=/tmp/chrome-debug' ) ;
4692 } ) ;
4793
4894 it ( 'appends browser.url() when navigationUrl is set on start_browser' , ( ) => {
4995 const history : SessionHistory = {
5096 sessionId : 'nav-123' ,
5197 type : 'browser' ,
5298 startedAt : '2026-01-01T00:00:00.000Z' ,
53- capabilities : { } ,
99+ capabilities : { browserName : 'chrome' } ,
54100 steps : [ {
55101 index : 1 ,
56102 tool : 'start_browser' ,
@@ -64,26 +110,30 @@ describe('generateCode - header', () => {
64110 expect ( code ) . toContain ( "await browser.url('https://github.com/login');" ) ;
65111 } ) ;
66112
67- it ( 'generates start_app_session with appium caps and server config' , ( ) => {
113+ it ( 'generates start_app_session using history.appiumConfig for connection config' , ( ) => {
68114 const history : SessionHistory = {
69115 sessionId : 'app-123' ,
70- type : 'ios ' ,
116+ type : 'android ' ,
71117 startedAt : '2026-01-01T00:00:00.000Z' ,
72- capabilities : { } ,
118+ capabilities : {
119+ platformName : 'Android' ,
120+ 'appium:deviceName' : 'emulator-5554' ,
121+ 'appium:app' : '/app/MyApp.apk' ,
122+ } ,
123+ appiumConfig : { hostname : '127.0.0.1' , port : 4723 , path : '/' } ,
73124 steps : [ {
74125 index : 1 ,
75126 tool : 'start_app_session' ,
76- params : { platform : 'iOS ' , deviceName : 'iPhone 14' , platformVersion : '17.0' , appPath : '/app/MyApp.app' } ,
127+ params : { platform : 'Android ' , deviceName : 'emulator-5554' } , // no appiumHost in params
77128 status : 'ok' ,
78- durationMs : 0 ,
129+ durationMs : 100 ,
79130 timestamp : '2026-01-01T00:00:00.000Z' ,
80131 } ] ,
81132 } ;
82133 const code = generateCode ( history ) ;
83- expect ( code ) . toContain ( 'const browser = await remote(' ) ;
84- expect ( code ) . toContain ( '"platformName": "iOS"' ) ;
85- expect ( code ) . toContain ( '"appium:deviceName": "iPhone 14"' ) ;
86- expect ( code ) . toContain ( '"appium:app": "/app/MyApp.app"' ) ;
134+ expect ( code ) . toContain ( '"hostname": "127.0.0.1"' ) ; // from history.appiumConfig, not params fallback
135+ expect ( code ) . toContain ( '"port": 4723' ) ;
136+ expect ( code ) . toContain ( '"platformName": "Android"' ) ;
87137 } ) ;
88138} ) ;
89139
0 commit comments