admin管理员组文章数量:1431727
I have problem with making API request in my playwright project. Here is example of code
const { test, expect, request, chromium } = require('@playwright/test');
test('API request with browser automation', async ({ page }) => {
// Launch the browser
const browser = await chromium.launch();
const context = await browser.newContext();
// Correctly formatted URL with "https"
const apiUrl = '';
console.log('Making API request to:', apiUrl);
// Perform the GET request
const apiResponse = await context.request.get(apiUrl);
// Check the response status
expect(apiResponse.status()).toBe(200);
// Parse and log the response body
const apiResponseBody = await apiResponse.json();
console.log('API Response:', apiResponseBody);
// Validate response data
expect(apiResponseBody).toHaveProperty('userId');
expect(apiResponseBody.userId).toBe(1);
expect(apiResponseBody).toHaveProperty('title', 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit');
expect(apiResponseBody).toHaveProperty('body');
// Optionally interact with the browser
await page.goto('');
const title = await page.title();
console.log('Page Title:', title);
// Clean up: close the page and browser
await page.close();
await browser.close();
});
I see that if I have test in main catalog of project, the test finishes with success, but when file is in subfolder x/y/z/a/apiTest.spec.ts I see error:
TypeError: apiRequestContext.get: Invalid URL',
(also when I add just a string to line const apiResponse = await context.request.get('myUrl');
)
What am I missing/doing wrong?
本文标签: typescriptapiRequestContextget Invalid URL error during playwright testsStack Overflow
版权声明:本文标题:typescript - apiRequestContext.get: Invalid URL error during playwright tests - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745575699a2664315.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论