A fully fledged example of a nightwatch test using the typescript language.
CustomPageObjects are not used in the way Nightwatch allows you to use them. They are just simple classes.
A fully fledged example of a nightwatch test using the typescript language.
Downloaded this, and with no instructions provided, ran npm install.
Got these messages:
found 16 vulnerabilities (2 low, 8 moderate, 5 high, 1 critical)
Ran npm audit, as suggested, to get details:
=== npm audit security report ===
SEMVER WARNING: Recommended action is a potentially breaking change
Low Regular Expression Denial of Service
Package debug
Dependency of nightwatch
Path nightwatch > mocha-nightwatch > debug
More info https://nodesecurity.io/advisories/534
High Denial of Service
Package https-proxy-agent
Dependency of nightwatch
Path nightwatch > proxy-agent > https-proxy-agent
More info https://nodesecurity.io/advisories/593
High Denial of Service
Package https-proxy-agent
Dependency of nightwatch
Path nightwatch > proxy-agent > pac-proxy-agent >
https-proxy-agent
More info https://nodesecurity.io/advisories/593
Critical Command Injection
Package growl
Dependency of nightwatch
Path nightwatch > mocha-nightwatch > growl
More info https://nodesecurity.io/advisories/146
High Denial of Service
Package http-proxy-agent
Dependency of nightwatch
Path nightwatch > proxy-agent > http-proxy-agent
More info https://nodesecurity.io/advisories/607
High Denial of Service
Package http-proxy-agent
Dependency of nightwatch
Path nightwatch > proxy-agent > pac-proxy-agent >
http-proxy-agent
More info https://nodesecurity.io/advisories/607
Manual Review
Some vulnerabilities require your attention to resolve
Visit https://go.npm.me/audit-guide for additional guidance
Moderate Prototype pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of phantomjs
Path phantomjs > request > hawk > boom > hoek
More info https://nodesecurity.io/advisories/566
Moderate Prototype pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of phantomjs
Path phantomjs > request > hawk > cryptiles > boom > hoek
More info https://nodesecurity.io/advisories/566
Moderate Prototype pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of phantomjs
Path phantomjs > request > hawk > hoek
More info https://nodesecurity.io/advisories/566
Moderate Prototype pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of phantomjs
Path phantomjs > request > hawk > sntp > hoek
More info https://nodesecurity.io/advisories/566
Moderate ReDoS via long string of semicolons
Package tough-cookie
Patched in >=2.3.0
Dependency of phantomjs
Path phantomjs > request > tough-cookie
More info https://nodesecurity.io/advisories/130
High Regular Expression Denial of Service
Package tough-cookie
Patched in >=2.3.3
Dependency of phantomjs
Path phantomjs > request > tough-cookie
More info https://nodesecurity.io/advisories/525
Moderate Memory Exposure
Package concat-stream
Patched in >=1.5.2 || >=1.4.11 <1.5.0 || >=1.3.2 <1.4.0
Dependency of phantomjs
Path phantomjs > extract-zip > concat-stream
More info https://nodesecurity.io/advisories/597
Moderate Remote Memory Exposure
Package request
Patched in >=2.68.0
Dependency of phantomjs
Path phantomjs > request
More info https://nodesecurity.io/advisories/309
Moderate Memory Exposure
Package tunnel-agent
Patched in >=0.6.0
Dependency of phantomjs
Path phantomjs > request > tunnel-agent
More info https://nodesecurity.io/advisories/598
Low Regular Expression Denial of Service
Package debug
Patched in >= 2.6.9 < 3.0.0 || >= 3.1.0
Dependency of phantomjs
Path phantomjs > extract-zip > debug
More info https://nodesecurity.io/advisories/534
found 16 vulnerabilities (2 low, 8 moderate, 5 high, 1 critical) in 2379 scanned packages
6 vulnerabilities require semver-major dependency updates.
10 vulnerabilities require manual review. See the full report for details.
I am getting below error while running this project:
โ TypeError: _this.browser.url is not a function
at ApplicationHomePage.BasePage.navigate (../../src/pages/BasePage.ts:26:18)
And this Type error is coming for all functions used in Base class. I have not changed anything and using as its but not able to run the scripts. Could you please help me with this one.
Base class
`export abstract class BasePage {
protected url: string | undefined = undefined;
protected pageLoadedElement: string | undefined = undefined;
protected navigateCompleteTimeout: number = 1000;
protected browser: NightwatchBrowser;
constructor(browser: NightwatchBrowser) {
this.browser = browser;
}
public navigate = () => {
if (!this.url) {
throw new Error('Page does not support navigating manually.');
}
console.log(this.url)
**this.browser.url(this.url);** error is coming for this line
return this.waitForLoad();
};
public waitForLoad = () => {
if (this.pageLoadedElement) {
this.browser.waitForElementVisible(this.pageLoadedElement, this.navigateCompleteTimeout);
}
return this;
};
}
`
Test class
`import { NightwatchBrowser } from 'nightwatch';
import { NightwachWebsitePage } from '../pages/NightwatchWebsitePage';
import { ApplicationHomePage} from '../pages/ApplicationHomePage';
import { ApplicationHomePageEnglishVersion } from '../pages/ApplicationHomePageEnglishVersion';
module.exports = {
'search for "nightwatch"': (browser: NightwatchBrowser) => {
const applicationHomePage= new ApplicationHomePage(browser);
const homePageEnglishVersion = new applicationHomePageEnglishVersion(browser);
applicationHomePage
.navigate()
.waitForLoad()
.search('nightwatch');
homePageEnglishVersion.waitForLoad();
browser.assert.containsText(homePageEnglishVersion.selectors.searchContents, 'Nightwatch.js').end();
},
'opening good luck result for "nightwatch"': (browser: NightwatchBrowser) => {
const applicationHomePage= new ApplicationHomePage(browser);
const nightwatchWebsitePage = new NightwachWebsitePage(browser);
applicationHomePage
.navigate()
.waitForLoad()
.goodLuck('nightwatch');
nightwatchWebsitePage.waitForLoad();
browser.assert.containsText(nightwatchWebsitePage.selectors.body, 'Nightwatch.js').end();
}
};
`
Page Object class
`import { BasePage } from './BasePage';
//@ts-check
export class ApplicationcHomePage extends BasePage {
public selectors = {
searchField: '//input[@name="q"]',
searchButton: '//input[@name="btnK"]',
goodLuckButton: '//input[@name="btnI"]'
};
protected url = 'application url';
protected pageLoadedElement = '//body';
public search = (query: string) => {
this.browser
.setValue(this.selectors.searchField, query)
.keys([this.browser.Keys.ESCAPE]) // Closes auto completion which might obscure search button
.click(this.selectors.searchButton);
return this;
};
public goodLuck = (query: string) => {
this.browser
.setValue(this.selectors.searchField, query)
.keys([this.browser.Keys.ESCAPE]) // Closes auto completion which might obscure good luck button
.click(this.selectors.goodLuckButton);
return this;
};
}
`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.