Best Selenoid code snippet using session.BrowserName
selenium_grid_scaler_test.go
Source:selenium_grid_scaler_test.go
...6func Test_getCountFromSeleniumResponse(t *testing.T) {7 type args struct {8 b []byte9 browserName string10 sessionBrowserName string11 browserVersion string12 }13 tests := []struct {14 name string15 args args16 want int6417 wantErr bool18 }{19 {20 name: "nil response body should throw error",21 args: args{22 b: []byte(nil),23 browserName: "",24 },25 // want: 0,26 wantErr: true,27 },28 {29 name: "empty response body should throw error",30 args: args{31 b: []byte(""),32 browserName: "",33 },34 // want: resource.NewQuantity(0, resource.DecimalSI),35 wantErr: true,36 },37 {38 name: "no active sessions should return count as 0",39 args: args{40 b: []byte(`{41 "data": {42 "grid":{43 "maxSession": 0,44 "nodeCount": 045 },46 "sessionsInfo": {47 "sessionQueueRequests": [],48 "sessions": []49 }50 }51 }`),52 browserName: "",53 },54 want: 0,55 wantErr: false,56 },57 {58 name: "active sessions with no matching browsername should return count as 0",59 args: args{60 b: []byte(`{61 "data": {62 "grid":{63 "maxSession": 1,64 "nodeCount": 165 },66 "sessionsInfo": {67 "sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],68 "sessions": [69 {70 "id": "0f9c5a941aa4d755a54b84be1f6535b1",71 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0.4472.114\",\n \"chrome\": {\n \"chromedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"goog:chromeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",72 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983c"73 }74 ]75 }76 }77 }`),78 browserName: "",79 sessionBrowserName: "",80 browserVersion: "latest",81 },82 want: 0,83 wantErr: false,84 },85 {86 name: "active sessions with matching browsername should return count as 2",87 args: args{88 b: []byte(`{89 "data": {90 "grid":{91 "maxSession": 1,92 "nodeCount": 193 },94 "sessionsInfo": {95 "sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],96 "sessions": []97 }98 }99 }`),100 browserName: "chrome",101 sessionBrowserName: "chrome",102 browserVersion: "latest",103 },104 want: 2,105 wantErr: false,106 },107 {108 name: "2 active sessions with matching browsername on 2 nodes and maxSession=4 should return count as 3 (rounded up from 2.5)",109 args: args{110 b: []byte(`{111 "data": {112 "grid":{113 "maxSession": 4,114 "nodeCount": 2115 },116 "sessionsInfo": {117 "sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],118 "sessions": [119 {120 "id": "0f9c5a941aa4d755a54b84be1f6535b1",121 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0.4472.114\",\n \"chrome\": {\n \"chromedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"goog:chromeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",122 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983c"123 },124 {125 "id": "0f9c5a941aa4d755a54b84be1f6535b2",126 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0.4472.114\",\n \"chrome\": {\n \"chromedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"goog:chromeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",127 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983d"128 }129 ]130 }131 }132 }`),133 browserName: "chrome",134 sessionBrowserName: "chrome",135 browserVersion: "latest",136 },137 want: 3,138 wantErr: false,139 },140 {141 name: "2 active sessions with matching browsername on 1 node and maxSession=3 should return count as 2 (rounded up from 1.33)",142 args: args{143 b: []byte(`{144 "data": {145 "grid":{146 "maxSession": 3,147 "nodeCount": 1148 },149 "sessionsInfo": {150 "sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\"\n}"],151 "sessions": [152 {153 "id": "0f9c5a941aa4d755a54b84be1f6535b1",154 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0.4472.114\",\n \"chrome\": {\n \"chromedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"goog:chromeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",155 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983c"156 },157 {158 "id": "0f9c5a941aa4d755a54b84be1f6535b2",159 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0.4472.114\",\n \"chrome\": {\n \"chromedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"goog:chromeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",160 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983d"161 }162 ]163 }164 }165 }`),166 browserName: "chrome",167 sessionBrowserName: "chrome",168 browserVersion: "latest",169 },170 want: 2,171 wantErr: false,172 },173 {174 name: "2 active sessions with matching browsername on 2 nodes should return count as 5",175 args: args{176 b: []byte(`{177 "data": {178 "sessionsInfo": {179 "grid":{180 "maxSession": 2,181 "nodeCount": 2182 },183 "sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],184 "sessions": [185 {186 "id": "0f9c5a941aa4d755a54b84be1f6535b1",187 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0.4472.114\",\n \"chrome\": {\n \"chromedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"goog:chromeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",188 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983c"189 },190 {191 "id": "0f9c5a941aa4d755a54b84be1f6535b2",192 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0.4472.114\",\n \"chrome\": {\n \"chromedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"goog:chromeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",193 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983d"194 }195 ]196 }197 }198 }`),199 browserName: "chrome",200 sessionBrowserName: "chrome",201 browserVersion: "latest",202 },203 want: 5,204 wantErr: false,205 },206 {207 name: "1 active session with matching browsername and version should return count as 2",208 args: args{209 b: []byte(`{210 "data": {211 "grid":{212 "maxSession": 1,213 "nodeCount": 1214 },215 "sessionsInfo": {216 "sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\"\n}"],217 "sessions": [218 {219 "id": "0f9c5a941aa4d755a54b84be1f6535b1",220 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0.4472.114\",\n \"chrome\": {\n \"chromedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"goog:chromeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",221 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983c"222 }223 ]224 }225 }226 }`),227 browserName: "chrome",228 sessionBrowserName: "chrome",229 browserVersion: "91.0",230 },231 want: 2,232 wantErr: false,233 },234 {235 name: "1 active msedge session with matching browsername/sessionBroswerName should return count as 3",236 args: args{237 b: []byte(`{238 "data": {239 "grid":{240 "maxSession": 1,241 "nodeCount": 1242 },243 "sessionsInfo": {244 "sessionQueueRequests": ["{\n \"browserName\": \"MicrosoftEdge\"\n}","{\n \"browserName\": \"MicrosoftEdge\"\n}"],245 "sessions": [246 {247 "id": "0f9c5a941aa4d755a54b84be1f6535b1",248 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"msedge\",\n \"browserVersion\": \"91.0.4472.114\",\n \"msedge\": {\n \"msedgedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"ms:edgeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",249 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983c"250 }251 ]252 }253 }254 }`),255 browserName: "MicrosoftEdge",256 sessionBrowserName: "msedge",257 browserVersion: "latest",258 },259 want: 3,260 wantErr: false,261 },262 {263 name: "1 active msedge session while asking for 2 chrome sessions should return a count of 2",264 args: args{265 b: []byte(`{266 "data": {267 "grid":{268 "maxSession": 1,269 "nodeCount": 1270 },271 "sessionsInfo": {272 "sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],273 "sessions": [274 {275 "id": "0f9c5a941aa4d755a54b84be1f6535b1",276 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"msedge\",\n \"browserVersion\": \"91.0.4472.114\",\n \"msedge\": {\n \"msedgedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"ms:edgeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",277 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983c"278 }279 ]280 }281 }282 }`),283 browserName: "chrome",284 sessionBrowserName: "chrome",285 browserVersion: "latest",286 },287 want: 2,288 wantErr: false,289 },290 {291 name: "1 active msedge session with maxSessions=3 while asking for 3 chrome sessions should return a count of 1",292 args: args{293 b: []byte(`{294 "data": {295 "grid":{296 "maxSession": 3,297 "nodeCount": 1298 },299 "sessionsInfo": {300 "sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],301 "sessions": [302 {303 "id": "0f9c5a941aa4d755a54b84be1f6535b1",304 "capabilities": "{\n \"acceptInsecureCerts\": false,\n \"browserName\": \"msedge\",\n \"browserVersion\": \"91.0.4472.114\",\n \"msedge\": {\n \"msedgedriverVersion\": \"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs\\u002fbranch-heads\\u002f4472@{#1462})\",\n \"userDataDir\": \"\\u002ftmp\\u002f.com.google.Chrome.DMqx9m\"\n },\n \"ms:edgeOptions\": {\n \"debuggerAddress\": \"localhost:35839\"\n },\n \"networkConnectionEnabled\": false,\n \"pageLoadStrategy\": \"normal\",\n \"platformName\": \"linux\",\n \"proxy\": {\n },\n \"se:cdp\": \"http:\\u002f\\u002flocalhost:35839\",\n \"se:cdpVersion\": \"91.0.4472.114\",\n \"se:vncEnabled\": true,\n \"se:vncLocalAddress\": \"ws:\\u002f\\u002flocalhost:7900\\u002fwebsockify\",\n \"setWindowRect\": true,\n \"strictFileInteractability\": false,\n \"timeouts\": {\n \"implicit\": 0,\n \"pageLoad\": 300000,\n \"script\": 30000\n },\n \"unhandledPromptBehavior\": \"dismiss and notify\",\n \"webauthn:extension:largeBlob\": true,\n \"webauthn:virtualAuthenticators\": true\n}",305 "nodeId": "d44dcbc5-0b2c-4d5e-abf4-6f6aa5e0983c"306 }307 ]308 }309 }310 }`),311 browserName: "chrome",312 sessionBrowserName: "chrome",313 browserVersion: "latest",314 },315 want: 1,316 wantErr: false,317 },318 }319 for _, tt := range tests {320 t.Run(tt.name, func(t *testing.T) {321 got, err := getCountFromSeleniumResponse(tt.args.b, tt.args.browserName, tt.args.browserVersion, tt.args.sessionBrowserName)322 if (err != nil) != tt.wantErr {323 t.Errorf("getCountFromSeleniumResponse() error = %v, wantErr %v", err, tt.wantErr)324 return325 }326 if !reflect.DeepEqual(got, tt.want) {327 t.Errorf("getCountFromSeleniumResponse() = %v, want %v", got, tt.want)328 }329 })330 }331}332func Test_parseSeleniumGridScalerMetadata(t *testing.T) {333 type args struct {334 config *ScalerConfig335 }336 tests := []struct {337 name string338 args args339 want *seleniumGridScalerMetadata340 wantErr bool341 }{342 {343 name: "invalid url string should throw error",344 args: args{345 config: &ScalerConfig{346 TriggerMetadata: map[string]string{},347 },348 },349 wantErr: true,350 },351 {352 name: "invalid browsername string should throw error",353 args: args{354 config: &ScalerConfig{355 TriggerMetadata: map[string]string{356 "url": "",357 },358 },359 },360 wantErr: true,361 },362 {363 name: "valid url and browsername should return metadata",364 args: args{365 config: &ScalerConfig{366 TriggerMetadata: map[string]string{367 "url": "http://selenium-hub:4444/graphql",368 "browserName": "chrome",369 },370 },371 },372 wantErr: false,373 want: &seleniumGridScalerMetadata{374 url: "http://selenium-hub:4444/graphql",375 browserName: "chrome",376 sessionBrowserName: "chrome",377 targetValue: 1,378 browserVersion: "latest",379 },380 },381 {382 name: "valid url, browsername, and sessionbrowsername should return metadata",383 args: args{384 config: &ScalerConfig{385 TriggerMetadata: map[string]string{386 "url": "http://selenium-hub:4444/graphql",387 "browserName": "MicrosoftEdge",388 "sessionBrowserName": "msedge",389 },390 },391 },392 wantErr: false,393 want: &seleniumGridScalerMetadata{394 url: "http://selenium-hub:4444/graphql",395 browserName: "MicrosoftEdge",396 sessionBrowserName: "msedge",397 targetValue: 1,398 browserVersion: "latest",399 },400 },401 {402 name: "valid url and browsername should return metadata",403 args: args{404 config: &ScalerConfig{405 TriggerMetadata: map[string]string{406 "url": "http://selenium-hub:4444/graphql",407 "browserName": "chrome",408 "browserVersion": "91.0",409 "unsafeSsl": "false",410 },411 },412 },413 wantErr: false,414 want: &seleniumGridScalerMetadata{415 url: "http://selenium-hub:4444/graphql",416 browserName: "chrome",417 sessionBrowserName: "chrome",418 targetValue: 1,419 browserVersion: "91.0",420 unsafeSsl: false,421 },422 },423 {424 name: "valid url, browsername and unsafeSsl should return metadata",425 args: args{426 config: &ScalerConfig{427 TriggerMetadata: map[string]string{428 "url": "http://selenium-hub:4444/graphql",429 "browserName": "chrome",430 "browserVersion": "91.0",431 "unsafeSsl": "true",432 },433 },434 },435 wantErr: false,436 want: &seleniumGridScalerMetadata{437 url: "http://selenium-hub:4444/graphql",438 browserName: "chrome",439 sessionBrowserName: "chrome",440 targetValue: 1,441 browserVersion: "91.0",442 unsafeSsl: true,443 },444 },445 }446 for _, tt := range tests {447 t.Run(tt.name, func(t *testing.T) {448 got, err := parseSeleniumGridScalerMetadata(tt.args.config)449 if (err != nil) != tt.wantErr {450 t.Errorf("parseSeleniumGridScalerMetadata() error = %v, wantErr %v", err, tt.wantErr)451 return452 }453 if !reflect.DeepEqual(got, tt.want) {...
config.go
Source:config.go
...138 }139 }140 sessions.Each(func(id string, session *session.Session) {141 state.Used++142 browserName := session.Caps.BrowserName()143 version := session.Caps.Version144 _, ok := state.Browsers[browserName]145 if !ok {146 state.Browsers[browserName] = make(Version)147 }148 _, ok = state.Browsers[browserName][version]149 if !ok {150 state.Browsers[browserName][version] = make(Quota)151 }152 v, ok := state.Browsers[browserName][version][session.Quota]153 if !ok {154 v = &Sessions{0, []Session{}}155 state.Browsers[browserName][version][session.Quota] = v156 }...
BrowserName
Using AI Code Generation
1import (2func main() {3 driver := agouti.ChromeDriver()4 if err := driver.Start(); err != nil {5 panic(err)6 }7 page, err := driver.NewPage()8 if err != nil {9 panic(err)10 }11 panic(err)12 }13 fmt.Println(page.Session().BrowserName())14 if err := driver.Stop(); err != nil {15 panic(err)16 }17}18import (19func main() {20 driver := agouti.ChromeDriver()21 if err := driver.Start(); err != nil {22 panic(err)23 }24 page, err := driver.NewPage()25 if err != nil {26 panic(err)27 }28 panic(err)29 }30 fmt.Println(page.Session().BrowserVersion())31 if err := driver.Stop(); err != nil {32 panic(err)33 }34}35import (36func main() {37 driver := agouti.ChromeDriver()38 if err := driver.Start(); err != nil {39 panic(err)40 }41 page, err := driver.NewPage()42 if err != nil {43 panic(err)44 }45 panic(err)46 }47 fmt.Println(page.Session().PlatformName())48 if err := driver.Stop(); err != nil {49 panic(err)50 }51}
BrowserName
Using AI Code Generation
1import (2func main() {3 agoutiDriver := agouti.ChromeDriver()4 agoutiDriver.Start()5 defer agoutiDriver.Stop()6 page, _ := agoutiDriver.NewPage()7 page.Session().BrowserName()8 fmt.Println(page.Session().BrowserName())9}10import (11func main() {12 agoutiDriver := agouti.ChromeDriver()13 agoutiDriver.Start()14 defer agoutiDriver.Stop()15 page, _ := agoutiDriver.NewPage()16 fmt.Println(page.PageSource())17}18import (19func main() {20 agoutiDriver := agouti.ChromeDriver()21 agoutiDriver.Start()22 defer agoutiDriver.Stop()23 page, _ := agoutiDriver.NewPage()24 fmt.Println(page.Session().PageSource())25}26import (27func main() {28 agoutiDriver := agouti.ChromeDriver()29 agoutiDriver.Start()30 defer agoutiDriver.Stop()31 page, _ := agoutiDriver.NewPage()32 fmt.Println(page.Title())33}34import (35func main() {36 agoutiDriver := agouti.ChromeDriver()37 agoutiDriver.Start()38 defer agoutiDriver.Stop()
BrowserName
Using AI Code Generation
1import (2func main() {3 driver := agouti.ChromeDriver()4 if err := driver.Start(); err != nil {5 panic(err)6 }7 defer driver.Stop()8 page, err := driver.NewPage()9 if err != nil {10 panic(err)11 }12 panic(err)13 }14 browserName, err := page.Session().BrowserName()15 if err != nil {16 panic(err)17 }18 fmt.Println("Browser Name: ", browserName)19 if err := page.DestroySession(); err != nil {20 panic(err)21 }22}
BrowserName
Using AI Code Generation
1import (2func main() {3 driver := agouti.ChromeDriver()4 if err := driver.Start(); err != nil {5 panic(err)6 }7 page, err := driver.NewPage()8 if err != nil {9 panic(err)10 }11 panic(err)12 }13 session := page.Session()14 browserName, err := session.BrowserName()15 if err != nil {16 panic(err)17 }18 fmt.Println("Browser Name: ", browserName)19 if err := driver.Stop(); err != nil {20 panic(err)21 }22}23import (24func main() {25 driver := agouti.ChromeDriver()26 if err := driver.Start(); err != nil {27 panic(err)28 }29 page, err := driver.NewPage()30 if err != nil {31 panic(err)32 }33 panic(err)34 }35 browserName, err := page.BrowserName()36 if err != nil {37 panic(err)38 }39 fmt.Println("Browser Name: ", browserName)40 if err := driver.Stop(); err != nil {41 panic(err)42 }43}44import (45func main() {46 driver := agouti.ChromeDriver()47 if err := driver.Start(); err != nil {48 panic(err)49 }50 browserName, err := driver.BrowserName()51 if err != nil {52 panic(err)53 }54 fmt.Println("Browser Name: ", browserName)55 if err := driver.Stop(); err != nil {56 panic(err)57 }58}59import (60func main() {61 driver := agouti.ChromeDriver()
BrowserName
Using AI Code Generation
1import (2func main() {3 driver := agouti.ChromeDriver()4 session, err := driver.NewSession()5 if err != nil {6 fmt.Println(err)7 }8 browserName, err := session.BrowserName()9 if err != nil {10 fmt.Println(err)11 }12 fmt.Println(browserName)13}14import (15func main() {16 driver := agouti.ChromeDriver()17 session, err := driver.NewSession()18 if err != nil {19 fmt.Println(err)20 }21 browserName, err := session.BrowserName()22 if err != nil {23 fmt.Println(err)24 }25 fmt.Println(browserName)26}27import (28func main() {29 driver := agouti.ChromeDriver()30 session, err := driver.NewSession()31 if err != nil {32 fmt.Println(err)33 }34 browserName, err := session.BrowserName()35 if err != nil {36 fmt.Println(err)37 }38 fmt.Println(browserName)39}40import (41func main() {42 driver := agouti.ChromeDriver()43 session, err := driver.NewSession()44 if err != nil {45 fmt.Println(err)46 }47 browserName, err := session.BrowserName()48 if err != nil {49 fmt.Println(err)50 }51 fmt.Println(browserName)52}53import (54func main() {55 driver := agouti.ChromeDriver()56 session, err := driver.NewSession()57 if err != nil {58 fmt.Println(err)59 }
BrowserName
Using AI Code Generation
1import (2func main() {3 driver := agouti.ChromeDriver()4 if err := driver.Start(); err != nil {5 panic(err)6 }7 page, err := driver.NewPage()8 if err != nil {9 panic(err)10 }11 panic(err)12 }13 fmt.Println(page.Session().BrowserName())14 if err := driver.Stop(); err != nil {15 panic(err)16 }17}18import (19func main() {20 driver := agouti.ChromeDriver()21 if err := driver.Start(); err != nil {22 panic(err)23 }24 page, err := driver.NewPage()25 if err != nil {26 panic(err)27 }28 panic(err)29 }30 fmt.Println(page.Session().BrowserName())31 if err := driver.Stop(); err != nil {32 panic(err)33 }34}35import (36func main() {37 driver := agouti.ChromeDriver()38 if err := driver.Start(); err != nil {39 panic(err)40 }41 page, err := driver.NewPage()42 if err != nil {43 panic(err)44 }45 panic(err)46 }47 fmt.Println(page.Session().BrowserName())48 if err := driver.Stop(); err != nil {49 panic(err)50 }51}52import (53func main() {54 driver := agouti.ChromeDriver()55 if err := driver.Start(); err != nil {56 panic(err)57 }58 page, err := driver.NewPage()59 if err != nil {60 panic(err)61 }62 panic(err)63 }64 fmt.Println(page.Session().BrowserName())
BrowserName
Using AI Code Generation
1import (2func main() {3 driver := agouti.ChromeDriver()4 if err := driver.Start(); err != nil {5 panic(err)6 }7 defer driver.Stop()8 page, err := driver.NewPage()9 if err != nil {10 panic(err)11 }12 panic(err)13 }14 session := page.Session()15 browserName, err := session.BrowserName()16 if err != nil {17 panic(err)18 }19 fmt.Println(browserName)20}21import (22func main() {23 driver := agouti.ChromeDriver()24 if err := driver.Start(); err != nil {25 panic(err)26 }27 defer driver.Stop()28 page, err := driver.NewPage()29 if err != nil {30 panic(err)31 }32 panic(err)33 }34 session := page.Session()35 browserVersion, err := session.BrowserVersion()36 if err != nil {37 panic(err)38 }39 fmt.Println(browserVersion)40}41import (42func main() {43 driver := agouti.ChromeDriver()44 if err := driver.Start(); err != nil {45 panic(err)46 }47 defer driver.Stop()48 page, err := driver.NewPage()49 if err != nil {50 panic(err)51 }52 panic(err)53 }54 session := page.Session()55 capabilities, err := session.Capabilities()56 if err != nil {57 panic(err)58 }59 fmt.Println(capabilities)60}61map[acceptInsecureCerts:false browserName:chrome browserVersion:75.0.3770.142 chrome:map[chromedriverVersion:75.0.3770.140 (b
BrowserName
Using AI Code Generation
1import (2func main() {3 driver := agouti.ChromeDriver()4 page, err := driver.NewPage()5 if err != nil {6 panic(err)7 }8 panic(err)9 }10 browserName, err := page.Session().BrowserName()11 if err != nil {12 panic(err)13 }14 fmt.Println("Browser Name:", browserName)15}16import (17func main() {18 driver := agouti.ChromeDriver()19 page, err := driver.NewPage()20 if err != nil {21 panic(err)22 }23 panic(err)24 }25 pageTitle, err := page.Title()26 if err != nil {27 panic(err)28 }29 fmt.Println("Page Title:", pageTitle)30}31import (32func main() {33 driver := agouti.ChromeDriver()34 page, err := driver.NewPage()35 if err != nil {36 panic(err)37 }38 panic(err)39 }40 pageURL, err := page.URL()41 if err != nil {42 panic(err)43 }44 fmt.Println("Page URL:", pageURL)45}
BrowserName
Using AI Code Generation
1import (2func main() {3 driver := agouti.ChromeDriver()4 if err := driver.Start(); err != nil {5 panic(err)6 }7 defer driver.Stop()8 page, err := driver.NewPage()9 if err != nil {10 panic(err)11 }12 panic(err)13 }14 browserName, err := page.Session().BrowserName()15 if err != nil {16 panic(err)17 }18 fmt.Println(browserName)19}20BrowserVersion() Method21func (s *Session) BrowserVersion() (string, error)22import (23func main() {24 driver := agouti.ChromeDriver()25 if err := driver.Start(); err != nil {26 panic(err)27 }28 defer driver.Stop()29 page, err := driver.NewPage()30 if err != nil {31 panic(err)32 }33 panic(err)34 }35 browserVersion, err := page.Session().BrowserVersion()36 if err != nil {37 panic(err)38 }39 fmt.Println(browserVersion)40}41ExecuteScript() Method42func (s *Session) ExecuteScript(script string, args ...interface{}) (interface{}, error)43import (
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!