File Upload from a drap and drop

Hello,

I am trying to do a very simple script, for a website, to fill a form that has upload file.

but I am having this file and I add screenshot step after every line, and the screenshot after the last line is return but the script doesn’t complete, can someone help me on why is that ?

ERRO[0102] Ignored call to ‘alert()’. The document is sandboxed, and the ‘allow-modals’ keyword is not set. browser_source=security line_number=639 source=browser stacktrace=“&{ [0xc001004e40 0xc001004e80 0xc001004f00 0xc001004f80 0xc001004fc0 0xc001005040 0xc001005080] }” url=“”

and this is my code

import http from ‘k6/http’;
import { File } from ‘k6/experimental/fs’;
import { sleep, check } from ‘k6’;
import { browser } from ‘k6/experimental/browser’;

export const options = {
scenarios: {
browser: {
executor: ‘shared-iterations’,
iterations: 1,
vus: 1,
options: {
browser: {
type: ‘chromium’,
headless: false, // You can set it to false for debugging purposes
},
},
},
},
};

export default async function () {
const context = browser.newContext();
const page = await context.newPage();
const url = ‘x’;
console.log(‘Navigating to:’, url);
await page.goto(url);
sleep(10);
await page.screenshot({ path: ‘screenshots/LoginPage.png’ });

const otherLoginOptionsButton = page.locator(“label[class=‘button-options show-options’]”);
await otherLoginOptionsButton.click();

const usernameField = page.locator(“input[id=‘UserName’]”); // Use the appropriate selector
await usernameField.fill(‘admin’);

const passwordField = page.locator(“input[id=‘Password’]”); // Use the appropriate selector
await passwordField.fill(‘Admin1!’);

const loginButton = page.locator(“button[data-tst-action=‘LogIn’]”); // Use the appropriate selector
await loginButton.click();

sleep(10);

await page.screenshot({ path: ‘screenshots/InboxPage.png’ });

const NewCaseButton = page.locator(“button[data-tst-action=‘NewCase’]”); // Use the appropriate selector
await NewCaseButton.click();

sleep(10);

await page.screenshot({ path: ‘screenshots/NewCasePage.png’ });

const CaseName = page.locator(“input[data-tst-field-text=‘Case’]”); // Use the appropriate selector

await CaseName.fill(Case+${(() => { const now = new Date(); return ${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, ‘0’)}${String(now.getDate()).padStart(2, ‘0’)}${String(now.getHours()).padStart(2, ‘0’)}${String(now.getMinutes()).padStart(2, ‘0’)}${String(now.getSeconds()).padStart(2, ‘0’)}${String(now.getMilliseconds()).padStart(3, ‘0’)}; })()});

await page.screenshot({ path: ‘screenshots/AddNewCaseName.png’ });

await page.setInputFiles(‘input[type=“file”]’, { name: ‘Tests/docs/2pages.pdf’ });
sleep(120);
await page.screenshot({ path: ‘screenshots/FileUploaded.png’ });

console.log(‘Test completed successfully’);
}

Hi @mariammaibrahim127,

It looks like you might want to set allow-modals with K6_BROWSER_ARGS for some reason. See the documentation here. Also, note what is explained on this thread.