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
added experimental typescript support #1125
added experimental typescript support #1125
Conversation
Here is an example repo I just created using this PR branch for a Gauge TS Taiko example: |
@nuclearglow - what do you suggest is the best way to keep the types in sync? Is there any automated mechanism that you know of, which can be hooked up t0 husky? Do you think it makes sense to port some tests to TS and make them run in the pipeline? thanks for the contribution! PS - i had approved this PR, but then I figured we should discuss these... |
@sriv yes, I had a look at available tools that produce typings automatically, but my preliminary assessment is that they do not really work with the Taiko API, as it is really flexible and allows a lot in the method parameters, all of this is pretty hard to configure out automatically. So I would recommend that extensive testing of the typings should be implemented. It would certainly mean that a TypeScript project needs to test the Taiko API methods using the available parameters and should check whether the project still compiles. This way, any future changes to the API which breaks the typings would mean that TypeScript tests are failing - and then the typings could be enhanced to reflect the newest API changes. Of course, new methods would need new tests and possibly new typings. |
I would also recommend that Taiko declares TypeScript support as experimental for the next releases until we work these things out and would therefore only allow projects to set up the typings manually, this way we can get some feedback from real world projects out there if the typings work against their test projects - and at the same time we do not break existing TypeScript test projects where the typings are inadequate. If you think that is the way to go, I will update this PR so that the README, the folder structure and the setup only supports manually configured projects, just let me know. |
The most important thing we should discuss within the Typings themselves is the |
Agreed.
Fair enough. We usually toggle experimental features off, but manual config to enable it works equally well. On the types -
Regarding
As a result you'll see checks like this: https://github.com/getgauge/taiko/blob/master/lib/taiko.js#L1151 it'd be nice to have types, but we are just touching the interface here. I think it'd be good to constrain |
Hi @sriv thanks for your feedback, I have worked on the PR and made some updates:
|
👍 on (1) and (2). Regarding
Does this help? Perhaps we can start porting some of our tests to use the TS bindings? |
Hey @sriv thanks for the pointers to the helper methods, I managed to learn a bit more. I think we can restrict the SearchElement type to the types you mentioned, but I will need to go through the API and be on the lookout for special cases. I found this in taiko.js:1300: if (isSelector(selector) || isString(selector) || isElement(selector)) {
...
} else {
options = setClickOptions(options, selector.x, selector.y); This basically means that there are special cases for the selector which are going further than selector: SearchElement | MouseCoordinates And yes, we could start porting some test cases to use TypeScript, can you help with the initial setup and maybe provide an example if you know to to go about this, then I could help with some tests as far as my project budget allows. If we should think about how to do it, let me know, I will help. |
OK, a new update with some updated typings after I have taken a look at the helper functions and the API again. Basically, I have upgraded the basic SerachElement definition to allow only the stuff that Taiko would accept: // BasicSelector mimics isSelector
export interface BasicSelector {
// FIXME: @sriv: is that correct?
elements: Element[] | Node[] | string[];
exists(): boolean;
[key: string]: any;
};
// isSelector also allows ElementWrapper instances
export type Selector = BasicSelector | ElementWrapper;
// SearchElement mimics isSelector, isString, isElement
export type SearchElement = string | Selector | Element; |
802ade8
to
c37361f
Compare
Sounds like good progress @nuclearglow ! I will take a closer look soon (feel free to ping me here if I am blocking your work), in the meantime there are some merge conflicts :) |
611f0a4
to
c925236
Compare
@nuclearglow Thank you for contributing to taiko. Your pull request has been labeled as a release candidate 🎉🎉. Merging this PR will trigger a release. Please bump up the version as part of this PR.Instructions to bump the version can found at CONTRIBUTING.md If the CONTRIBUTING.md file does not exist or does not include instructions about bumping up the version, please looks previous commits in git history to see what changes need to be done. |
types/taiko/index.d.ts
Outdated
// https://taiko.gauge.org/#title | ||
export function title(): Promise<string>; | ||
// https://taiko.gauge.org/#click | ||
export function click(selector: SearchElement | MouseCoordinates, options?: ClickOptions, args?: string[]): Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args is a rest parameter and its type has to be RelativeSearchElement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
types/taiko/index.d.ts
Outdated
// https://taiko.gauge.org/#click | ||
export function click(selector: SearchElement | MouseCoordinates, options?: ClickOptions, args?: string[]): Promise<void>; | ||
// https://taiko.gauge.org/#doubleclick | ||
export function doubleClick(selector: SearchElement | MouseCoordinates, options?: BasicNavigationOptions, args?: string[]): Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args is a rest parameter and its type has to be RelativeSearchElement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
* Add FAQ file with general section * Remove summary text * Use summary tag for questions * Add FAQ for firefox support and installation * Add more FAQ and move to docs folder * Add link to FAQ in the TOC * Add link to Typescript and .npmrc info Co-authored-by: Srikanth <srikanth.ddit@gmail.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
…through package.json, added package.json schema Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
…ge.json, updated README Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
…e taiko already Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
* getgauge#818 Fix validation for browser session Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#818 fix closeWindow Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#818 Update validation error message Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#818 update error messaging Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> Co-authored-by: Srikanth <srikanth.ddit@gmail.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Bumps [prettier](https://github.com/prettier/prettier) from 2.0.3 to 2.0.4. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md) - [Commits](prettier/prettier@2.0.3...2.0.4) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Fixes getgauge#1175 Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Bumps [documentation](https://github.com/documentationjs/documentation) from 12.2.0 to 12.3.0. - [Release notes](https://github.com/documentationjs/documentation/releases) - [Changelog](https://github.com/documentationjs/documentation/blob/master/CHANGELOG.md) - [Commits](documentationjs/documentation@v12.2.0...v12.3.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
* [WIP] getgauge#1134 Case insensitive selectors for radioButton * [WIP] getgauge#1134 Case insensitive selectors for TextBox * [WIP] getgauge#1134 Case insensitive selectors for checkbox * remove permissions map, allow users to use CDP Permissions Signed-off-by: sriv <srikanth.ddit@gmail.com> Co-authored-by: Gabriel Peixinho <gabriel.peixinho@gmail.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.0.1 to 9.0.2. - [Release notes](https://github.com/sinonjs/sinon/releases) - [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md) - [Commits](https://github.com/sinonjs/sinon/commits) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
* getgauge#612 add time field selector that supports input type date, datetime-local, month, time, week Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * Bump lint-staged from 10.0.10 to 10.1.0 Bumps [lint-staged](https://github.com/okonet/lint-staged) from 10.0.10 to 10.1.0. - [Release notes](https://github.com/okonet/lint-staged/releases) - [Commits](lint-staged/lint-staged@v10.0.10...v10.1.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * Bump documentation from 12.1.4 to 12.2.0 Bumps [documentation](https://github.com/documentationjs/documentation) from 12.1.4 to 12.2.0. - [Release notes](https://github.com/documentationjs/documentation/releases) - [Changelog](https://github.com/documentationjs/documentation/blob/master/CHANGELOG.md) - [Commits](documentationjs/documentation@v12.1.4...v12.2.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#612 add tests and update timeField Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * Bump lint-staged from 10.1.0 to 10.1.1 Bumps [lint-staged](https://github.com/okonet/lint-staged) from 10.1.0 to 10.1.1. - [Release notes](https://github.com/okonet/lint-staged/releases) - [Commits](lint-staged/lint-staged@v10.1.0...v10.1.1) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * Fix beforeunload API (getgauge#1157) * Fixed beforeunload API. getgauge#1093 - Fixed existing API contract to only accept callback. - Wait for beforeunload popup handler to finish before closing the browser. * Fixed javascript popup FTs. getgauge#1093 * Force close browser after 5 second. getgauge#1093 * Fixed typo in warning message * Update beforeunload API documentation getgauge#1093 Co-authored-by: Srikanth <srikanth.ddit@gmail.com> Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * Make coresponding wrappers to use value wrapper Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#612 update timeField to use date object to select Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#612 wait for navigation and highlight element on action Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#612 add tests and fixes Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * Update timeField.js Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#612 fix min max validation and add tests Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#612 add more tests and fix min max validation Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#612 update docs Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * getgauge#612 Fix docs and test description Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Dharmendra Singh <dharmenn@thoughtworks.com> Co-authored-by: Srikanth <srikanth.ddit@gmail.com> Co-authored-by: Zabil Cheriya Maliackal <zabil@users.noreply.github.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
This is the fix of npm audit fix command Signed-off-by: Zabil Cheriya Maliackal <zabilcm@gmail.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Bumps [husky](https://github.com/typicode/husky) from 4.2.3 to 4.2.5. - [Release notes](https://github.com/typicode/husky/releases) - [Changelog](https://github.com/typicode/husky/blob/master/CHANGELOG.md) - [Commits](typicode/husky@v4.2.3...v4.2.5) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Bumps [lint-staged](https://github.com/okonet/lint-staged) from 10.1.2 to 10.1.3. - [Release notes](https://github.com/okonet/lint-staged/releases) - [Commits](lint-staged/lint-staged@v10.1.2...v10.1.3) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
* fix element screenshot with proximity selectors use isElement instead of Object Signed-off-by: Sai <saikrishna321@yahoo.com> * update patch version Signed-off-by: saikrishna321 <saikrishna321@yahoo.com> Co-authored-by: Dharmendra Singh <dharmenn@thoughtworks.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Bumps [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) from 3.1.2 to 3.1.3. - [Release notes](https://github.com/prettier/eslint-plugin-prettier/releases) - [Changelog](https://github.com/prettier/eslint-plugin-prettier/blob/master/CHANGELOG.md) - [Commits](https://github.com/prettier/eslint-plugin-prettier/commits) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
* fix screenshot for specific element with index Signed-off-by: saikrishna321 <saikrishna321@yahoo.com> * use isSelector fn from helpers Signed-off-by: saikrishna321 <saikrishna321@yahoo.com> Co-authored-by: Dharmendra Singh <dharmenn@thoughtworks.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
* Update chromium to revision 756035 * Add browser dependencies Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * Install dependencies only for linux Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> * Install browser dependencies for FT Signed-off-by: NivedhaSenthil <nivedhasenthil@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: NivedhaSenthil <nivedhasenthil@gmail.com> Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
7b56f15
to
f4b873b
Compare
Hi @NivedhaSenthil thank you for the great feedback, I have tried to add everything as far as I understood it. I still have some trouble with the relative searches, they are hard to type since it is a bunch of methods... But I superficially typed the RelativeSearchElement and added it as the return type of the proximity methods, I hope this will work out. At this point, I would need real TS tests to check that everything can be typed as we envision it. I will try to add some to my gauge TS example project soon. Please review my changes and let me know if you have more feedback! |
Signed-off-by: Sven Vowé <sven.vowe.ext@dwpbank.de>
PR looks fine for an initial TS support, this is a great effort :) Will try adding some test in TS and port some existing test also.. Do follow #1152 for any progress. |
Hi there. If I understand this thread correctly then the experimental Typescript is only available if Taiko is used in conjunction with Gauge. Is this correct? If not, could someone maybe explain (to a non-expert) how Typescript could be used for writing test cases if other test frameworks (e.g. Jest, Mocha) are used? |
The typescript bindings are for Taiko. You can use these binding with any test runner. You can refer https://docs.taiko.dev/experimental_features/#typescript-support on adding configuration to |
@zabil Great, that has clarified it, thanks a lot! |
Closes #209
This solution would mean that everyone using Taiko with TypeScript would be exposed to the Typings provided, but there is also an optional solution which would make the typings optional but requires a bit of configuration work for every project using it:
index.d.ts
tsconfig.json
in this way:If you prefer to keep this optional, let me know and I will update the PR.
Possible TODOs:
Hopefully, we can work together to include typings for Taiko :-)