Quantcast
Viewing latest article 11
Browse Latest Browse All 328

Not able to run a k6 script through an executor with blazemeter

Hello, this is my script:

import { browser } from 'k6/browser';
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
import { Trend } from 'k6/metrics'; 

const transactionDuration = new Trend('T001_Login');
const trdurationlistproject =new Trend('T002_OpenProject');




export const options = {
  scenarios: {
   ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
      startTime: '3s',
      vus: 1,
      iterations: 1,
      maxDuration: '1m',
    },
  },
  thresholds: {
    checks: ['rate==1.0'],
  },
};

export default async function () {
        const startTime = new Date().getTime();  
        const page = await browser.newPage();
        try {
                await page.goto(landingPage,{ waitUntil: 'networkidle' });

                const elementSelector = 'div#shotgun_version'; // Replace with your actual selector
                await page.waitForSelector(elementSelector);
            
                // Get the text content of the element
                const elementText = await page.textContent(elementSelector);
            
                // Define the expected text
                const expectedText = 'v8.72.0.6213 (build 08f8ecf)'; // Replace with the text you expect
            
                // Check if the text matches the expected value
                check(elementText, {
                    'App Version element has correct text': (text) => text === expectedText,
                });
            
                // // Optionally, you can also check if the text contains a specific substring
                // const substring = 'partial text'; // Replace with the substring you want to check
                // check(elementText, {
                //     'element contains substring': (text) => text.includes(substring),
                // });

                await page.locator('input[id="user_login"]').type(userName);
                await page.locator('input[id="user_password"]').type(userPwd);
                await page.waitForLoadState('networkidle');
                const submit = page.locator('button[type="submit"]')
                await Promise.all([page.waitForNavigation(), submit.click(),{ waitUntil: 'networkidle' },{ tags: { name: 'ClickSignIn' }}]);

    


                 // Wait for the span element to appear
                const spanSelector = 'div.page_name.page_rename_target'; // Replace with your actual selector
                await page.waitForSelector(spanSelector);

                // Check if the span element is visible
                const spanVisible = await page.isVisible(spanSelector);
                check(spanVisible, {
                                    'Projects span is visible': (v) => v === true,
                                   });

                const spanText = await page.textContent(spanSelector);
                check(spanText, {
                                    'Projects span has correct text': (text) => text === 'Projects', // Replace with your expected text
                                });

                const endTime = new Date().getTime();
                const duration = endTime - startTime;
 
                transactionDuration.add(duration);

                const startTime2 = new Date().getTime();

                await page.goto(projectsPage,{ waitUntil: 'networkidle' });

                const spanSelector2 = 'div.project_name';
                await page.waitForSelector(spanSelector2);
                const spanVisible2 = await page.isVisible(spanSelector2);
                check(spanVisible2, {
                                    'Project Name span is visible': (v) => v === true,
                                   });

                const spanText2 = await page.textContent(spanSelector2);
                check(spanText2, {
                                    'Project Name span has correct text': (text) => text === 'Project JZJJNLJSCZ', // Replace with your expected text
                                });
                const endTime2 = new Date().getTime();
                const duration2 = endTime2 - startTime2;  
                trdurationlistproject.add(duration2);                
            } finally {
    await page.close();
  }

}

if I run it locally it runs fine:


```K6_BROWSER_HEADLESS=false k6 run sampleScriptNoId.js

         /\      Grafana   /‾‾/  
    /\  /  \     |\  __   /  /   
   /  \/    \    | |/ /  /   ‾‾\ 
  /          \   |   (  |  (‾)  |
 / __________ \  |_|\_\  \_____/ 

     execution: local
        script: sampleScriptNoId.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 1m33s max duration (incl. graceful stop):
              * ui: 1 iterations shared among 1 VUs (maxDuration: 1m0s, startTime: 3s, gracefulStop: 30s)

WARN[0014] sid:270AF62FF1A70661CA8177E4BBD3C3EF tid:3AD577340D23D54F6477A6A9F771A7D6 bctxid:667A2975CFA4284A75CD67A5E84BBB22 bctx nil:false, unknown target type: "shared_worker"  category="Browser:isAttachedPageValid" elapsed="0 ms" source=browser

     ✓ App Version element has correct text
     ✓ Projects span is visible
     ✓ Projects span has correct text
     ✓ Project Name span is visible
     ✓ Project Name span has correct text

     browser_data_received.......: 52 MB   2.2 MB/s
     browser_data_sent...........: 160 kB  6.9 kB/s
     browser_http_req_duration...: avg=385.71ms min=24µs     med=270.03ms max=3.79s    p(90)=820.62ms p(95)=1.46s  
     browser_http_req_failed.....: 0.00%   0 out of 160
     browser_web_vital_cls.......: avg=0.037893 min=0.000499 med=0.002503 max=0.110677 p(90)=0.089042 p(95)=0.09986
     browser_web_vital_fcp.......: avg=3.76s    min=1.36s    med=3.2s     max=6.73s    p(90)=6.02s    p(95)=6.38s  
     browser_web_vital_fid.......: avg=2.79ms   min=2.79ms   med=2.79ms   max=2.79ms   p(90)=2.79ms   p(95)=2.79ms 
     browser_web_vital_inp.......: avg=48ms     min=48ms     med=48ms     max=48ms     p(90)=48ms     p(95)=48ms   
     browser_web_vital_lcp.......: avg=4.04s    min=1.36s    med=3.88s    max=6.89s    p(90)=6.29s    p(95)=6.59s  
     browser_web_vital_ttfb......: avg=1s       min=373ms    med=947ms    max=1.7s     p(90)=1.55s    p(95)=1.62s  
   ✓ checks......................: 100.00% 5 out of 5
     data_received...............: 0 B     0 B/s
     data_sent...................: 0 B     0 B/s
     iteration_duration..........: avg=19.23s   min=19.23s   med=19.23s   max=19.23s   p(90)=19.23s   p(95)=19.23s 
     iterations..................: 1       0.04301/s
     T001_Login..................: avg=13718    min=13718    med=13718    max=13718    p(90)=13718    p(95)=13718  
     T002_OpenProject............: avg=5455     min=5455     med=5455     max=5455     p(90)=5455     p(95)=5455   
     vus.........................: 1       min=0        max=1
     vus_max.....................: 1       min=1        max=1


running (0m23.3s), 0/1 VUs, 1 complete and 0 interrupted iterations
ui   ✓ [======================================] 1 VUs  0m20.3s/1m0s  1/1 shared iters

type or paste code here


but when I run it from Blazemeter I got this error message in k6.err

time=“2025-03-26T01:34:05Z” level=warning msg=“"cli" level configuration overrode scenarios configuration entirely”
time=“2025-03-26T01:34:05Z” level=error msg=“Uncaught (in promise) browser not found in registry. make sure to set browser type option in scenario definition in order to use the browser module” executor=constant-vus scenario=default

Any idea would be appreciated

1 post - 1 participant

Read full topic


Viewing latest article 11
Browse Latest Browse All 328

Trending Articles