Skip to content

Commit

Permalink
Merge db2e096 into a06f121
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed Oct 28, 2018
2 parents a06f121 + db2e096 commit 2460f55
Show file tree
Hide file tree
Showing 41 changed files with 7,117 additions and 12,088 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cache:
- packages/jest-example/node_modules
- packages/cucumber-example/node_modules
branches:
except:
- /^v\d+\.\d+\.\d+$/
only:
- master
notifications:
email: false
2 changes: 1 addition & 1 deletion packages/cucumber-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"chromedriver": "^2.43.0",
"chromedriver": "^2.43.1",
"cucumber": "^5.0.2",
"cucumber-pretty": "^1.4.4",
"geckodriver": "^1.12.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"babel-core": "^6.26.3",
"babel-jest": "^23.6.0",
"babel-preset-env": "^1.7.0",
"chromedriver": "^2.43.0",
"chromedriver": "^2.43.1",
"geckodriver": "^1.12.2",
"jest": "^23.6.0",
"nightwatch": "1.0.11",
Expand Down
18,250 changes: 6,376 additions & 11,874 deletions packages/nightwatch-api/package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/nightwatch-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"chai": "^4.2.0",
"chromedriver": "2.43.0",
"chromedriver": "2.43.1",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"del-cli": "^1.1.0",
Expand All @@ -103,7 +103,6 @@
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"typedoc": "^0.13.0",
"typescript": "^3.1.3"
}
}
31 changes: 13 additions & 18 deletions packages/nightwatch-api/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ import reporter from 'nightwatch/lib/testsuite/reporter';
import fs from 'fs';
import path from 'path';
import { log } from './logger';
import { IApiConfig } from '.';

let runner: CliRunnerInstance;
let client: Client;

function getDefautEnvironment() {
interface IOptions {
env: string;
configFile: string;
}

export function getDefautEnvironment() {
return 'default';
}

function getDefaultConfigFile() {
export function getDefaultConfigFile() {
const jsonConfigFile = './nightwatch.json';
const jsConfigFie = path.resolve('./nightwatch.conf.js');

Expand All @@ -42,12 +46,9 @@ function getDefaultConfigFile() {
);
}

function createRunner({
env = getDefautEnvironment(),
configFile = getDefaultConfigFile()
}: IApiConfig = {}) {
function createRunner(options: IOptions) {
if (!runner) {
runner = CliRunner({ env, config: configFile });
runner = CliRunner({ env: options.env, config: options.configFile });
runner.isWebDriverManaged = function() {
if (this.baseSettings.selenium) {
this.baseSettings.selenium.start_process = true;
Expand All @@ -60,11 +61,8 @@ function createRunner({
return runner;
}

export async function startWebDriver({
env = getDefautEnvironment(),
configFile = getDefaultConfigFile()
}: IApiConfig = {}) {
createRunner({ env, configFile });
export async function startWebDriver(options: IOptions) {
createRunner(options);
const { port } = runner.test_settings.webdriver;
await runner.startWebDriver();
log(`WebDriver started on port ${port}`);
Expand All @@ -76,11 +74,8 @@ export async function stopWebDriver() {
log(`WebDriver stopped on port ${port}`);
}

export async function createSession({
env = getDefautEnvironment(),
configFile = getDefaultConfigFile()
}: IApiConfig = {}): Promise<Api> {
createRunner({ env, configFile });
export async function createSession(options: IOptions): Promise<Api> {
createRunner(options);
const settings = runner.test_settings;
client = createClient(settings, new reporter([], 0, {}, {}));
await client.startSession();
Expand Down
201 changes: 189 additions & 12 deletions packages/nightwatch-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,207 @@
import { createSession as createNightwatchSession, runQueue } from './client';
import * as Client from './client';
import { promisifyApi, promisifySection, promisifyExpect, promisifyPageObjects } from './promisify';
import proxy from './proxy';
import { Api } from 'nightwatch';
import section from 'nightwatch/lib/page-object/section';

let nightwatchClient: Api;

export { startWebDriver, stopWebDriver, closeSession } from './client';
/**
* This variable represents the Nightwatch WebDriver client.
* This is the main part of this package.
* All Nightwatch [API](http://nightwatchjs.org/api) is available on this variable.
* Important to note that every method call is wrapped in a promise.
* So you can await it's execution using `await` keyword.
* Also chaining is supported as well.
* Before using it you need to create a WebDriver session.
* @example
* const { client } = require('nightwatch-api');
*
* (async function() {
* await client
* .url('https://duckduckgo.com/')
* .setValue('input[name="q"]', 'WebDriver')
* .click('input[type="submit"]')
* .assert.containsText('#links', 'WebDriver - w3.org');
* )();
* @example
* const { client } = require('nightwatch-api');
*
* (async function() {
* // This is much easier to debug, place console.logs, use if conditions and for loops
* await client.url('https://duckduckgo.com/');
* await client.setValue('input[name="q"]', 'WebDriver');
* await client.click('input[type="submit"]');
* await client.assert.containsText('#links', 'WebDriver - w3.org');
* )();
* @example
*
* const { client } = require('nightwatch-api');
*
* const googleSearch = client.page.google();
*
* (async function() {
* await googleSearch.init();
* await googleSearch.setValue('@searchField', 'WebDriver');
* await googleSearch.click('@searchButton');
* await googleSearch.assert.containsText('@searchResult', 'WebDriver - w3.org');
* )();
*/
export const client = proxy(() => nightwatchClient);

export interface IApiConfig {
env?: string;
configFile?: string;
/**
* Starts WebDriver server according to selected environment configuration.
* You can use it to start chromedriver, geckodriver, selenium server and other WebDrivers.
* @example
* const { startWebDriver, stopWebDriver } = require('nightwatch-api');
*
* beforeAll(async () => {
* await startWebDriver({ env: 'firefox' });
* });
*
* afterAll(async () => {
* await stopWebDriver();
* });
* @example
* const { startWebDriver, stopWebDriver } = require('nightwatch-api');
*
* (async function() {
* try {
* await startWebDriver({ env: 'chrome' });
* // create WebDriver client
* // use WebDriver session
* } catch (err) {
* console.log(err.stack);
* } finally {
* // close WebDriver session
* await stopWebDriver();
* }
* )();
*/
export async function startWebDriver(
options: {
/**
* Selected Nightwatch [environment](http://nightwatchjs.org/gettingstarted#test-settings).
* By default it's `default`.
*/
env?: string;
/**
* Nightwatch configuration file location.
* By default it's `nightwatch.json` or `nightwatch.conf.js` in current process working directory.
*/
configFile?: string;
} = {}
) {
const {
env = Client.getDefautEnvironment(),
configFile = Client.getDefaultConfigFile()
} = options;
return Client.startWebDriver({ env, configFile });
}

export async function createSession({ env, configFile }: IApiConfig = {}) {
nightwatchClient = await createNightwatchSession({ env, configFile });
promisifyApi(nightwatchClient, runQueue);
promisifyExpect(nightwatchClient, runQueue);
promisifyPageObjects(nightwatchClient, runQueue);
/**
* Stops the currently running WebDriver.
*/
export async function stopWebDriver() {
await Client.stopWebDriver();
}

export const client = proxy(() => nightwatchClient);
/**
* Creates a new WebDriver session.
* You need to create a session to be able to communicate with the browser.
* @example
* const { createSession, closeSession } = require('nightwatch-api');
*
* beforeAll(async () => {
* await createSession({ env: 'firefox' });
* });
*
* afterAll(async () => {
* await closeSession();
* });
* @example
* const { createSession, closeSession } = require('nightwatch-api');
*
* (async function() {
* try {
* // create WebDriver session
* await createSession({ env: 'chrome' });
* // use WebDriver client
* } catch (err) {
* console.log(err.stack);
* } finally {
* await closeSession();
* // close WebDriver session
* }
* )();
*/
export async function createSession(
/**
* Options are ignored if you already started a the WebDriver using `startWebDriver`.
*/
options: {
/**
* Selected Nightwatch [environment](http://nightwatchjs.org/gettingstarted#test-settings).
* By default it's `default`.
*/
env?: string;
/**
* Nightwatch configuration file location.
* By default it's `nightwatch.json` or `nightwatch.conf.js` in current process working directory.
*/
configFile?: string;
} = {}
) {
const {
env = Client.getDefautEnvironment(),
configFile = Client.getDefaultConfigFile()
} = options;
nightwatchClient = await Client.createSession({ env, configFile });
promisifyApi(nightwatchClient, Client.runQueue);
promisifyExpect(nightwatchClient, Client.runQueue);
promisifyPageObjects(nightwatchClient, Client.runQueue);
}

/**
* Closes the active WebDriver session.
*/
export async function closeSession() {
await Client.closeSession();
}

/**
* This class enables creations of Nightwatch page object sections dynamically.
* @example
* const { client, Section } = require('nightwatch-api');
*
* function createSearchSection(provider, parent) {
* if (provider === 'google') {
* return new Section(
* {
* selector: 'body',
* elements: {
* searchField: 'input[name="q"]',
* searchButton: 'input[type="submit"]',
* },
* },
* {
* name: 'Search Section',
* parent: client
* }
* );
* }
* }
*
* (async function() {
* const section = createSearchSection('google');
* await client.init();
* await section.setValue('@searchField', 'WebDriver');
* await section.click('@searchButton');
* )();
*/
export class Section extends section {
constructor(definition: object, options: object) {
super(definition, options);
promisifySection(this.api, runQueue);
promisifySection(this.api, Client.runQueue);
}
}
2 changes: 1 addition & 1 deletion packages/node-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "Igor Mucsicska <mucsi_96@yahoo.com>",
"license": "MIT",
"devDependencies": {
"chromedriver": "^2.43.0",
"chromedriver": "^2.43.1",
"geckodriver": "^1.12.2",
"nightwatch": "^1.0.11",
"nightwatch-api": "latest"
Expand Down
7 changes: 7 additions & 0 deletions packages/website/.all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
"avatar_url": "https://avatars1.githubusercontent.com/u/6883314?v=4",
"profile": "https://github.com/maoberlehner",
"contributions": []
},
{
"login": "spnraju",
"name": "Padmanabha Raju Sagi",
"avatar_url": "https://avatars1.githubusercontent.com/u/33729221?v=4",
"profile": "https://github.com/spnraju",
"contributions": []
}
]
}
1 change: 1 addition & 0 deletions packages/website/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
*.log
dist
typedoc.json
4 changes: 2 additions & 2 deletions packages/website/components/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Body = styled.body`
--sidebar-gutter: 40px;
--animation-duration: 0.15s;
@media (min-width: 720px) {
@media (min-width: 720px) and (min-height: 1000px) {
--header-height: 50px;
}
Expand All @@ -19,7 +19,7 @@ const Body = styled.body`
--sidebar-width: 300px;
}
@media (min-width: 1280px) {
@media (min-width: 1280px) and (min-height: 1000px) {
--header-height: 60px;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/website/components/Contributors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import styled from 'styled-components';
import { withContributors } from './ContributorsProvider';
import Link from './Link';
import { withSiteConfig } from './SiteConfigProvider';

const Avatar = styled.img`
width: 100px;
Expand Down Expand Up @@ -38,4 +38,4 @@ const Contributors = ({ contributors }) => (
<ContributorsContainer>{contributors.map(Contributor)}</ContributorsContainer>
);

export default withContributors(Contributors);
export default withSiteConfig(Contributors);

0 comments on commit 2460f55

Please sign in to comment.