-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve TSDoc for page object's url property. (#4297)
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Page object file | ||
import {EnhancedPageObject, PageObjectModel} from '..'; | ||
|
||
const fileUploadPageElements = { | ||
fileUploadInput: 'input#file-upload', | ||
submitButton: 'input#file-submit', | ||
uploadFiles: '#uploaded-files' | ||
}; | ||
|
||
const fileUploadPage = { | ||
url(this: EnhancedPageObject) { | ||
return `${this.api.launch_url}/upload`; | ||
}, | ||
elements: fileUploadPageElements | ||
} satisfies PageObjectModel; | ||
|
||
export interface FileUploadPage extends | ||
EnhancedPageObject<{}, typeof fileUploadPageElements, {}, {}, () => string> {} // eslint-disable-line @typescript-eslint/ban-types | ||
|
||
export default fileUploadPage; | ||
|
||
|
||
// Declare the newly created page object in the NightwatchCustomPageObjects interface. | ||
// This will allow you to access the page object type in your test files. | ||
declare module '..' { | ||
interface NightwatchCustomPageObjects { | ||
FileUpload(): FileUploadPage; | ||
} | ||
} | ||
|
||
|
||
// test file | ||
describe('File Upload', function() { | ||
it('File Upload test', function() { | ||
const fileUploadPage = browser.page.FileUpload(); | ||
const url = fileUploadPage.url(); | ||
|
||
fileUploadPage | ||
.navigate(url) | ||
.uploadFile('@fileUploadInput', 'test.txt') | ||
// alternate way of passing an element instead of '@submitButton' | ||
.click(fileUploadPage.elements.submitButton) | ||
.expect.element('@uploadFiles').text.to.equal('test.txt'); | ||
|
||
browser.end(); | ||
}); | ||
}); |