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

Commit

Permalink
feat(typescript): move typescript variable instances from protractor/… (
Browse files Browse the repository at this point in the history
#3565)

Breaking change for TypeScript:

Instead of importing globals like `browser` from `protractor/globals`, import from `protractor`.

Before:

```ts
import {browser, element} from 'protractor/globals';
import {ElementFinder} from 'protractor';

describe('my app', () => {
  myElement: ElementFinder;

  beforeEach(() => {
    browser.get('example.com');
    myElement = element(by.css('foo'));
  });
});
```

After

```ts
import {browser, element, ElementFinder} from 'protractor';

describe('my app', () => {
  myElement: ElementFinder;

  beforeEach(() => {
    browser.get('example.com');
    myElement = element(by.css('foo'));
  });
});
```

Closes #3564
  • Loading branch information
juliemr authored and cnishina committed Sep 16, 2016
1 parent 7c124f3 commit 5034c89
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 46 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ npm-debug.log
.idea/

*.swp
globals.js
globals.d.ts

1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ libpeerconnection.log
npm-debug.log
xmloutput*
release.md
globals.ts
4 changes: 2 additions & 2 deletions exampleTypescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ npm install

## Protractor typings

To use Protractor types, you'll need to import `protractor/globals`. After this is imported, you should have autocompletion hints when typing.
To use Protractor types, you'll need to import `protractor`. After this is imported, you should have autocompletion hints when typing.

```
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor/globals';
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
```

Although the Protractor configuration file can be written in javascript, creating it in typescript will have some hints. These hints and the reference configuration can be found in `lib/config.ts`. Below we are importing the Config interface and applying that interface to the config variable:
Expand Down
2 changes: 1 addition & 1 deletion exampleTypescript/angularPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// import {browser, element, by, By, $, $$, ExpectedConditions}
// from 'protractor/globals';
//
import {browser, element, by} from 'protractor/globals';
import {browser, element, by} from 'protractor';

export class AngularHomepage {
nameInput = element(by.model('yourName'));
Expand Down
2 changes: 1 addition & 1 deletion exampleTypescript/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// from 'protractor/globals';
//
// The jasmine typings are brought in via DefinitelyTyped ambient typings.
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor/globals';
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';

describe('protractor with typescript typings', () => {
beforeEach(() => {
Expand Down
21 changes: 0 additions & 21 deletions globals.ts

This file was deleted.

9 changes: 2 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,14 @@ gulp.task('tsc', function(done) {
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
});

gulp.task('tsc:globals', function(done) {
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '-d', 'globals.ts'],
'ignore');
});

gulp.task('prepublish', function(done) {
runSequence('checkVersion', ['jshint', 'format'], 'tsc', 'tsc:globals',
runSequence('checkVersion', ['jshint', 'format'], 'tsc',
'built:copy', done);
});

gulp.task('pretest', function(done) {
runSequence('checkVersion',
['webdriver:update', 'jshint', 'format'], 'tsc', 'tsc:globals',
['webdriver:update', 'jshint', 'format'], 'tsc',
'built:copy', done);
});

Expand Down
7 changes: 0 additions & 7 deletions lib/index.d.ts

This file was deleted.

36 changes: 36 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// <reference path="../typings/index.d.ts" />

// TODO: we'd like to remove the triple-slash reference, but it's necessary
// until definitely-typed is updated for selenium-webdriver.

import {ElementHelper, ProtractorBrowser} from './browser';
import {ElementArrayFinder, ElementFinder} from './element';
import {ProtractorExpectedConditions} from './expectedConditions';
import {ProtractorBy} from './locators';
import {Ptor} from './ptor';

// Re-export public types.
export {ElementHelper, ProtractorBrowser} from './browser';
export {Config} from './config';
export {ElementArrayFinder, ElementFinder} from './element';
export {ProtractorExpectedConditions} from './expectedConditions';
export {ProtractorBy} from './locators';
export {Ptor} from './ptor';

// Export API instances based on the global Protractor object.
// We base this on NodeJS `global` because we do not want to mask
// with a different instance of Protractor if the module is
// installed both globally and locally.
export let protractor: Ptor = (global as any)['protractor'];
export let browser: ProtractorBrowser = protractor.browser;
export let $: (search: string) => ElementFinder = protractor.$;
export let $$: (search: string) => ElementArrayFinder = protractor.$$;
export let element: ElementHelper = protractor.element;
export let By: ProtractorBy = protractor.By;
export let by: ProtractorBy = protractor.by;
export let wrapDriver:
(webdriver: any, baseUrl?: string, rootElement?: string,
untrackOutstandingTimeouts?: boolean) => ProtractorBrowser =
protractor.wrapDriver;
export let ExpectedConditions: ProtractorExpectedConditions =
protractor.ExpectedConditions;
1 change: 1 addition & 0 deletions spec/install/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
typings
conf.js
typescript_spec.js
npm-debug.log
4 changes: 2 additions & 2 deletions spec/install/typescript_spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {browser, by, By, element, $, $$, ExpectedConditions, protractor} from 'protractor/globals';
import {ProtractorBrowser} from 'protractor';
import {browser, by, By, element, $, $$, ExpectedConditions, protractor} from 'protractor';

describe('typescript imports', () => {
it('should have global objects that match the protractor namespace', () => {
expect(protractor.browser === browser).toBeTruthy();
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
"testapp",
"website",
"scripts",
"globals.ts",
"globals.d.ts",
"exampleTypescript",
"typings/globals",
"spec"
Expand Down

0 comments on commit 5034c89

Please sign in to comment.