Skip to content

Instantly share code, notes, and snippets.

@Secreto31126
Created June 11, 2025 00:17
Show Gist options
  • Select an option

  • Save Secreto31126/128a340c941c86ded480ced6312457d7 to your computer and use it in GitHub Desktop.

Select an option

Save Secreto31126/128a340c941c86ded480ced6312457d7 to your computer and use it in GitHub Desktop.
k6 ITBA Exchange
import type { Options } from 'k6/options';
import { browser } from 'k6/browser';
import { check } from 'k6';
export const options: Options = {
scenarios: {
ui: {
executor: 'shared-iterations',
vus: 10,
iterations: 15,
options: {
browser: {
type: 'chromium'
}
}
}
},
thresholds: {
checks: ['rate==1.0']
},
cloud: {
distribution: {
brazil: { loadZone: 'amazon:br:sao paulo', percent: 100 }
}
}
};
export default async function () {
const page = await browser.newPage();
try {
await page.goto('http://pawserver.it.itba.edu.ar/paw-2024b-08');
const logo = page.locator('nav a:has(img)');
check(await logo.getAttribute('href'), {
'logo href is correct': (href) => href === '/paw-2024b-08'
});
const link = page.locator('a:has(article):first-child');
const title = (await page.locator('a:has(article):first-child h3').textContent())?.trim();
const href = await link.getAttribute('href');
check(href, {
'article link is correct': (h) => h?.startsWith('/paw-2024b-08/thread/') ?? false
});
await page.goto(`http://pawserver.it.itba.edu.ar${href}`);
const articleTitle = page.locator('h3');
check((await articleTitle.textContent())?.trim(), {
'article has a title': (t) => !!t,
'article title is consistent': (t) => t === title
});
} finally {
await page.close();
}
}
import type { Options } from 'k6/options';
import { browser } from 'k6/browser';
import { check } from 'k6';
export const options: Options = {
scenarios: {
ui: {
executor: 'shared-iterations',
vus: 10,
iterations: 30,
options: {
browser: {
type: 'chromium'
}
}
}
},
thresholds: {
checks: ['rate==1.0']
}
};
export default async function () {
const page = await browser.newPage();
try {
await page.goto('http://pawserver.it.itba.edu.ar/paw-2024b-08/login');
await page.locator('input[name="email"]').fill('***');
await page.locator('input[name="password"]').fill('***');
await page.waitForLoadState();
await page.locator('button[type="submit"]').click();
await page.waitForLoadState();
await page.locator('nav a[href="/paw-2024b-08/user/test.admin"]').click();
await page.waitForLoadState();
const username = await page
.locator('.profile-content div:has(input[type="file"]) h1')
.textContent();
check(username?.trim(), {
'The username matches': (t) => t === 'test.admin'
});
} finally {
await page.close();
}
}
import { check, sleep } from 'k6';
import http from 'k6/http';
export const options = {
thresholds: {
http_req_failed: [{ threshold: 'rate<0.01', abortOnFail: true }],
http_req_duration: ['p(99)<1000'],
},
scenarios: {
breaking: {
executor: 'ramping-vus',
stages: [
{ duration: '10s', target: 5 },
{ duration: '30s', target: 10 },
{ duration: '30s', target: 12 },
{ duration: '30s', target: 15 },
{ duration: '20s', target: 20 },
],
},
},
cloud: {
distribution: {
brazil: { loadZone: 'amazon:br:sao paulo', percent: 100 }
}
},
};
export default function () {
const url = 'http://pawserver.it.itba.edu.ar/paw-2024b-08/api/v1/users/login';
const params = {
headers: {
'Authorization': 'Basic ***'
},
};
const res = http.post(url, null, params);
check(res, {
'response code was 200': (res) => res.status == 200,
});
sleep(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment