-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(screenplay): New Questions and Interactions
`Hit` interaction allows for a key stroke to be sent into an element. There are several new questions too: `Attribute` - to retrieve a value of an element attribute, `Value` - to get a value of an input element, `Website` to retrieve properties of the website, such as a title.
- Loading branch information
Showing
25 changed files
with
649 additions
and
55 deletions.
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,56 @@ | ||
import { by, protractor } from 'protractor/globals'; | ||
|
||
import { | ||
BrowseTheWeb, | ||
Click, | ||
Enter, | ||
Open, | ||
Target, | ||
Text, | ||
Value, | ||
Website, | ||
} from '../../../src/serenity-protractor/screenplay'; | ||
import { Actor } from '../../../src/serenity/screenplay'; | ||
|
||
import test = require('selenium-webdriver/testing'); | ||
|
||
import expect = require('../../expect'); | ||
import { Attribute } from '../../../src/serenity-protractor/screenplay/questions/attribute'; | ||
|
||
class DemoApp { | ||
static Header = Target.the('header').located(by.css('header>h1')); | ||
static Item_Field = Target.the('name field').located(by.model('item')); | ||
static Items = Target.the('list of items').located(by.repeater('item in items')); | ||
static Submit_Button = Target.the('submit button').located(by.css('input[type="submit"]')); | ||
} | ||
|
||
test.describe ('Interactions', () => { | ||
|
||
let james = Actor.named('James').whoCan(BrowseTheWeb.using(protractor.browser)); | ||
|
||
test.beforeEach(() => james.attemptsTo( | ||
Open.browserOn('resources/index.html') | ||
)); | ||
|
||
test.it ('should allow to verify the title of a page', () => | ||
expect(james.toSee(Website.title())).eventually.equal('demo app') ); | ||
|
||
test.it ('should allow to verify text on the page', () => | ||
expect(james.toSee(Text.of(DemoApp.Header))).eventually.equal('Angular demo app') ); | ||
|
||
test.it ('should allow to interact with an input field', () => | ||
james.attemptsTo( | ||
Enter.theValue('buy some milk').into(DemoApp.Item_Field), | ||
Click.on(DemoApp.Submit_Button) | ||
).then(() => | ||
expect(james.toSee(Text.ofAll(DemoApp.Items))).eventually.deep.equal([ 'buy some milk' ]) )); | ||
|
||
test.it ('should allow to read the value of an input field', () => | ||
james.attemptsTo( | ||
Enter.theValue('buy some milk').into(DemoApp.Item_Field) | ||
).then(() => | ||
expect(james.toSee(Value.of(DemoApp.Item_Field))).eventually.equal('buy some milk') )); | ||
|
||
test.it ('should allow to read the value of an arbitrary attribute', () => | ||
expect(james.toSee(Attribute.of(DemoApp.Item_Field).called('id'))).eventually.equal('item') ); | ||
}); |
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,39 @@ | ||
'use strict'; | ||
require('ts-node/register'); | ||
|
||
var path = require('path'), | ||
protractor = require.resolve('protractor'), | ||
node_modules = protractor.substring(0, protractor.lastIndexOf('node_modules') + 12); | ||
|
||
exports.config = { | ||
seleniumServerJar: path.resolve(node_modules, 'protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-2.53.1.jar'), | ||
|
||
framework: 'mocha', | ||
specs: [ 'integration/**/*.js' ], | ||
|
||
capabilities: { | ||
'browserName': 'phantomjs', | ||
'phantomjs.binary.path': path.resolve(node_modules, 'phantomjs-prebuilt/lib/phantom/bin/phantomjs'), | ||
}, | ||
|
||
// capabilities: { | ||
// browserName: 'chrome', | ||
// chromeOptions: { | ||
// args: [ | ||
// 'incognito' | ||
// // 'show-fps-counter=true' | ||
// ] | ||
// } | ||
// }, | ||
|
||
baseUrl: 'file://' + __dirname + '/', | ||
|
||
onPrepare: function () { | ||
|
||
// By default, Protractor uses data:text/html,<html></html> as resetUrl, but | ||
// location.replace from the data: to the file: protocol is not allowed | ||
// (we'll get ‘not allowed local resource’ error), so we replace resetUrl with one | ||
// that uses the file: protocol | ||
browser.resetUrl = 'file://'; | ||
} | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,36 @@ | ||
<!DOCTYPE html> | ||
<html ng-app="demo"> | ||
<head> | ||
<script src="angular.min.js"></script> | ||
<title>demo app</title> | ||
</head> | ||
<body ng-controller="main"> | ||
|
||
|
||
<header> | ||
<h1>{{ title }}</h1> | ||
</header> | ||
|
||
<form> | ||
<label for="item">name</label> | ||
<input id="item" type="text" ng-model="item" /> | ||
<input type="submit" ng-click="add(item)" value="add" /> | ||
</form> | ||
|
||
<ul> | ||
<li ng-repeat="item in items track by $index">{{ item }}</li> | ||
</ul> | ||
|
||
<script> | ||
angular.module('demo', []). | ||
controller('main', ['$scope', function ($scope) { | ||
$scope.title = 'Angular demo app'; | ||
$scope.items = []; | ||
|
||
$scope.add = function (item) { | ||
$scope.items.push(item); | ||
} | ||
}]); | ||
</script> | ||
</body> | ||
</html> |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,18 @@ | ||
import { keyNameOf } from '../../src/serenity-protractor/keys'; | ||
|
||
import expect = require('../expect'); | ||
import * as webdriver from 'selenium-webdriver'; | ||
|
||
describe('Protractor', () => { | ||
|
||
describe ('keyNameOf', () => { | ||
|
||
it ('should determine the name of the key pressed', () => { | ||
expect(keyNameOf(webdriver.Key.ENTER)).to.equal('ENTER'); | ||
}); | ||
|
||
it ('should return the name of the searched for key, if it could not be found', () => { | ||
expect(keyNameOf('unknown-key')).to.equal('unknown-key'); | ||
}); | ||
}); | ||
}); |
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
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,18 @@ | ||
import { protractor } from 'protractor'; | ||
import * as webdriver from 'selenium-webdriver'; | ||
|
||
export function keyNameOf(key: string) { | ||
let keys = definitionsFrom(protractor, webdriver); | ||
|
||
for ( let candidate in keys ) { | ||
if ( keys.hasOwnProperty(candidate) && keys[ candidate ] === key ) { | ||
return candidate; | ||
} | ||
} | ||
|
||
return key; | ||
} | ||
|
||
function definitionsFrom(...potentialSources) { | ||
return potentialSources.concat({ Key: [] }).find(source => source && source.Key).Key; | ||
} |
Oops, something went wrong.