Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Better typings Support for the webdriver api #3430

Closed
KrauseStefan opened this issue Aug 1, 2016 · 8 comments · Fixed by #3520
Closed

Better typings Support for the webdriver api #3430

KrauseStefan opened this issue Aug 1, 2016 · 8 comments · Fixed by #3520
Assignees
Milestone

Comments

@KrauseStefan
Copy link

Feature Request

Better typings Support for the webdriver api

Currently many of the webdriver functions specified in the selenium api are not possible to use with the new protractor typings. I see why you might want to hide some of the api, however a lot is missing right now.

We upgraded to 4.0.2 and want to use the new typings however we are unable to as long as parts of the api is missing. (at least in a easy and clean way)

We specifically use

  executeScript: (script: string) => webdriver.promise.Promise<any[]>;
  manage: () => Options;

But more can be found her: http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html

As a small note shouldn't

export class Webdriver {

}

be an interface instead? I believe an interface would be possible to extend without changes code in the protractor module.

Let me know if you are interested in a pull request

@cnishina
Copy link
Member

cnishina commented Aug 1, 2016

I thought I had this as an opened issue...I probably wrote my plan in a Google Doc. Anyway, I am trying to upgrade the DefinitelyTyped selenium-webdriver ambient typings. Using an up-to-date selenium-webdriver ambient typings will fix some of the weird things we are doing in TypeScript to fake in types for webdriver.

So as part of the task list is to clean up the Protractor codebase. This would mean that export class Webdriver would disappear from the codebase.

So your items:

  • executeScript could be accessed from browser.driver.executeScript; however, driver is of type any and executeScript does not have an interface or a return type. Does this prevent you from using this method?

    export interface Driver {
      executeScript: (script: string) => webdriver.promise.Promise<any[]>;
      manage: () => Options;
    }
    
    (browser.driver as Driver).executeScript(<your script>).then(() => ...
    
  • export class Webdriver could be written as either a class or an interface. This will eventually be removed from the code base since this was used to fake in types for selenium-webdriver.

@cnishina cnishina added this to the 4.1.0 milestone Aug 1, 2016
@cnishina cnishina self-assigned this Aug 1, 2016
@KrauseStefan
Copy link
Author

No it does not prevent me

(<any> browser).executeScript(...)

Works in both cases, however it always nice to have the issue fixed at the root instead of using workarounds. 😏

I actually ended up having to add a different workaround to my codebase that hides the above issue.

declare const browser: any;

The above typing is needed since importing 'protractor/globals' before the configuration has been fully loaded throws an exception, because the global variables are not defined before then.

globals.ts:21 throws an exception: TypeError: Cannot read property 'browser' of undefined.

export var browser: Browser = global['protractor']['browser'];

However I need to be able to call execute script from the onPrepare hook.
Hence the typings workaround.

However I see you already made changes related to this, I haven't test it though.

@cnishina
Copy link
Member

cnishina commented Aug 2, 2016

Workarounds! Win! I agree that fixing the root problem (selenium-webdriver DefinitelyTyped) will solve some of TypeScript issues.

I'll come back to comment on this issue on 'protractor/globals'. I hope to put to rest some of these issues with missing tests.

@cnishina
Copy link
Member

Related issue to clean up typings: #3500

@cnishina
Copy link
Member

Related issue to not having manage on browser: #3477

@cnishina
Copy link
Member

Will need to be resolved when requiring selenium-webdriver ambient typings with protractor typings: #3423

@cnishina
Copy link
Member

DefinitelyTyped selenium-webdriver typings PR DefinitelyTyped/DefinitelyTyped#10852.

@cnishina
Copy link
Member

cnishina commented Sep 2, 2016

To keep track of progress:

Also, we should think about how we are importing promise from selenium-webdriver. Currently we are using import {promise} from 'selenium-webdriver; and we are using promise.Promise<T>. Maybe we could do one of the following:

  • bring in the namespace and rename Promise to differentiate from es6 Promises: import {Promise as WebDriverPromise} from 'selenium-webdriver/promise';
  • change the namespace: import {promise as webdriverpromise} from 'selenium-webdriver';

Option 1 does not take into account for using promise.all. Option 2 might work better with webdriverpromise.all. @mgiambalvo What are your thoughts on this?

cnishina added a commit to cnishina/protractor that referenced this issue Sep 7, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 7, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 7, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 7, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 9, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 9, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 9, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 9, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 9, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 13, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
cnishina added a commit to cnishina/protractor that referenced this issue Sep 13, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- refactor gulpfile task 'types' to use multiple files from tsc
- add browser method types applied from webdriver

this closes angular#3430, closes angular#3477, and closes angular#3500
@cnishina cnishina modified the milestones: 4.0.7, 4.1.0 Sep 13, 2016
cnishina added a commit that referenced this issue Sep 13, 2016
- fix exampleTypescript to have noGlobals
- change the exampleTypescript tsconfig.json to include @types
- alias promise as wdpromise everywhere
- add browser method types applied from webdriver
- remove gulpfile 'types' task
- remove webdriver namespace from globals.d.ts

this closes #3430, closes #3477, and closes #3500
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants