Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate TypeScript Type declarations #791

Closed
12 tasks done
ka3de opened this issue Feb 23, 2023 · 13 comments
Closed
12 tasks done

Generate TypeScript Type declarations #791

ka3de opened this issue Feb 23, 2023 · 13 comments
Labels
Milestone

Comments

@ka3de
Copy link
Collaborator

ka3de commented Feb 23, 2023

This is a global task in order to track the generation of TS Type declarations for xk6-browser, the same way it's done for k6.

Type declarations should be generated for the following APIs:

Tasks

@ka3de ka3de added the ux label Feb 23, 2023
@inancgumus inancgumus changed the title Generate TS Type declarations Generate TypeScript Type declarations Feb 23, 2023
@ka3de ka3de mentioned this issue Feb 23, 2023
@kangliep
Copy link

can't wait this 💯 !!

@swathi-harwalkar1
Copy link

We are waiting for this too!!

@ankur22 ankur22 added this to the v0.11.0 milestone Jul 12, 2023
@ankur22
Copy link
Collaborator

ankur22 commented Jul 12, 2023

@swathi-harwalkar1 and @kangliep take a look at the most recent type definitions in https://github.com/DefinitelyTyped/DefinitelyTyped/. Most of the objects are now defined. There are a couple missing (browser and browserContext), which will be updated in an upcoming release.

We will not be updating browserType since we're unexporting it the next release (more news to follow in the next release notes).

@jevgenim7
Copy link

would be nice!

@ka3de ka3de closed this as completed Aug 8, 2023
@ArCiGo
Copy link

ArCiGo commented Aug 15, 2023

I'm curious: Could it be possible to use the browser member as the existing documentation suggests?

@ankur22
Copy link
Collaborator

ankur22 commented Aug 15, 2023

I'm curious: Could it be possible to use the browser member as the existing documentation suggests?

Hi, I think you are referring to the fact that browser doesn't seem to be a named export, but Browser is. We made a mistake when creating the type definitions, but we're working on a fix for this (DefinitelyTyped/DefinitelyTyped#66347) and should be out sometime this week.

@ArCiGo
Copy link

ArCiGo commented Aug 15, 2023

I'm curious: Could it be possible to use the browser member as the existing documentation suggests?

Hi, I think you are referring to the fact that browser doesn't seem to be a named export, but Browser is. We made a mistake when creating the type definitions, but we're working on a fix for this (DefinitelyTyped/DefinitelyTyped#66347) and should be out sometime this week.

I'm a little bit confused. What's the difference between the browser and Browser members?

I noticed that types/k6 (https://www.npmjs.com/package/@types/k6?activeTab=code) has the browser member. Doesn't work?

The new fix, can be followed with the documentation I mentioned?

@ankur22
Copy link
Collaborator

ankur22 commented Aug 21, 2023

@ArCiGo,

We've merged in the latest version of type definitions.

I'm a little bit confused. What's the difference between the browser and Browser members?

browser is the pre allocated browser instance that is the starting point for all tests when working with k6 browser. With this object you should be able to create a new context, or create a new page, and from there start interacting with the website under test.

Browser is the declared interface. browser is of type Browser.

I noticed that types/k6 (https://www.npmjs.com/package/@types/k6?activeTab=code) has the browser member. Doesn't work?

Can you elaborate on this please?

The new fix, can be followed with the documentation I mentioned?

Yes, the latest version of the type definitions should now reflect the browser docs correctly.

@ArCiGo
Copy link

ArCiGo commented Sep 13, 2023

@ankur22

I was trying the new version of types/k6 with my current solution of Playwright (using POM). I was able to use the browser, but now I got a new issue.

I passed the page object to my page classes, and this is the error.-

Argument of type 'import("/Users/my.username/Documents/Projects/my_tests/node_modules/@types/k6/experimental/browser").Page' is not assignable to parameter of type 'import("/Users/my.username/Documents/Projects/my_tests/node_modules/playwright-core/types/types").Page'.
  Type 'Page' is missing the following properties from type 'Page': addInitScript, $eval, $$eval, exposeBinding, and 36 more.ts(2345)

In fact, in my page classes, I'm passing a parameter to a constructor of type Page (of Playwright).

My code looks like this.-

import { browser } from 'k6/experimental/browser';

import { SLLoginPage } from '../pages/SLLoginPage';
import { SLProductPage } from '../pages/SLProductsPage';

let slLoginPage: SLLoginPage;
let slProductPage: SLProductPage;

export const options = {
    scenarios: {
        login: {
            executor: 'constant-vus',
            exec: 'login',
            vus: 1
        }
    },
};

export async function login() {
    const context = browser.newContext();
    const page = context.newPage();

    try { 
        slLoginPage = new SLLoginPage(page);
        slProductPage = new SLProductPage(page);

        await slLoginPage.goTo();
        await slLoginPage.fillLoginForm(process.env.USERNAME as string, process.env.PASSWORD as string);
        await page.waitForURL('**/dashboard', { timeout: 3000 });
} finally {
    page.close();
}

On the other hand, waitForUrl() is not available on types/k6? If not, is there an equivalent?

Thanks in advance! :)

@ankur22
Copy link
Collaborator

ankur22 commented Sep 21, 2023

Hi @ArCiGo,

Could you please open an issue in our community forum instead of answering in this issue 🙂 ?

I'd need to see the full test script, but in general the page in k6 isn't compatible with the page in Playwright. As you've spotted the page in k6 doesn't implement all of the APIs that the page in Playwright has implemented. Not only that, most of the k6 APIs are still synchronous, whereas most of the Playwright APIs are asynchronous. What is it that you are trying to do that requires both tools?

On the other hand, waitForUrl() is not available on types/k6? If not, is there an equivalent?

No plans yet to implement waitForUrl, and the current workaround would be to work with waitForNavigation instead. What's your use case for waitForUrl?

Cheers,
Ankur

@ArCiGo
Copy link

ArCiGo commented Sep 21, 2023

Hi, @ankur22 !

Thanks for your response.

What I want to do is load testing of my existing UI functional tests (I have different workflows that I would like to load with multiple users).

Maybe we can talk in-depth about my goal in another channel. What do you think? :)

Update.- I have a sample project to demo what I want.

@ankur22
Copy link
Collaborator

ankur22 commented Sep 25, 2023

Hi @ArCiGo,

Yes please, can you open an issue in our community forum for now, and we can go from there 👍

@ArCiGo
Copy link

ArCiGo commented Sep 25, 2023

Done, @ankur22 ! :D

https://community.grafana.com/t/loading-testing-for-ui-using-playwright/104281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants