@@ -52,45 +52,6 @@ describe('Utility features', () => {
5252 } )
5353 } )
5454
55- it ( 'should handle page objects failure' , ( ) => {
56- return testCaseFactory
57- . create ( 'page-object-failure-test' )
58- . pageObject ( 'calculator' , `module.exports = {
59- elements: {
60- numberA: '#a',
61- numberB: '#b',
62- addButton: '#add',
63- result: '#result'
64- }
65- }` )
66- . feature ( 'addition' )
67- . scenario ( 'small numbers' )
68- . given ( 'User is on the simple calculator page' , ( ) => client . init ( ) )
69- . and ( 'User enter 4 in A field' , ( ) => {
70- const calculator = client . page . calculator ( )
71- return calculator . setValue ( '@numberA' , 4 )
72- } )
73- . and ( 'User enter 5 in B field' , ( ) => {
74- const calculator = client . page . calculator ( )
75- return calculator . setValue ( '@numberB' , 5 )
76- } )
77- . when ( 'User press Add button' , ( ) => {
78- const calculator = client . page . calculator ( )
79- return calculator . click ( '@addButton' )
80- } )
81- . then ( 'The result should contain 10' , ( ) => {
82- const calculator = client . page . calculator ( )
83- return calculator . assert . containsText ( '@result' , 10 )
84- } )
85- . run ( )
86- . then ( ( result ) => {
87- result . features [ 0 ] . result . status . should . be . failed
88- result . features [ 0 ] . result . scenarioCounts . should . deep . equal ( { failed : 1 } )
89- result . features [ 0 ] . scenarios [ 0 ] . result . status . should . be . failed
90- result . features [ 0 ] . scenarios [ 0 ] . result . stepCounts . should . deep . equal ( { passed : 4 , failed : 1 } )
91- } )
92- } )
93-
9455 it ( 'should handle paralell tests' , ( ) => {
9556 return testCaseFactory
9657 . create ( 'paralell-test' , { paralell : true } )
@@ -277,96 +238,79 @@ describe('Utility features', () => {
277238 } )
278239 } )
279240
280- it ( 'should be able to provide Nightwatch client as step definition first parameter' , ( ) => {
281- return testCaseFactory
282- . create ( 'test-nightwatch-client-as-parameter' )
283- . feature ( 'addition' )
284- . scenario ( 'small numbers' )
285- . given ( 'User is on the simple calculator page' , ( ) => client . init ( ) )
286- . and ( 'User enter "4" in A field' , ( a ) => client . setValue ( '#a' , a ) )
287- . and ( 'User enter "5" in B field' , ( b ) => client . setValue ( '#b' , b ) )
288- . when ( 'User press Add button' , ( ) => client . click ( '#add' ) )
289- . then ( 'The result should contain "9"' , ( result ) => client . assert . containsText ( '#result' , result ) )
290- . scenario ( 'big numbers' )
291- . given ( 'User is on the simple calculator page' )
292- . and ( 'User enter "44" in A field' )
293- . and ( 'User enter "55" in B field' )
294- . when ( 'User press Add button' )
295- . then ( 'The result should contain "99"' )
296- . run ( )
297- . then ( ( result ) => {
298- result . features [ 0 ] . result . status . should . be . passed
299- result . features [ 0 ] . result . scenarioCounts . should . deep . equal ( { passed : 2 } )
300- result . features [ 0 ] . scenarios [ 0 ] . result . status . should . be . passed
301- result . features [ 0 ] . scenarios [ 0 ] . result . stepCounts . should . deep . equal ( { passed : 5 } )
302- result . features [ 0 ] . scenarios [ 1 ] . result . status . should . be . passed
303- result . features [ 0 ] . scenarios [ 1 ] . result . stepCounts . should . deep . equal ( { passed : 5 } )
304- } )
305- } )
306-
307241 it ( 'should work together with babel' , ( ) => {
308242 return testCaseFactory
309243 . create ( 'babel-example' , { babel : true } )
310244 . feature ( 'addition' )
311245 . scenario ( 'small numbers' )
312246 . given ( 'User is on the simple calculator page' , `async () => {
313247 await client.init()
314- }` )
315- . and ( 'User enter 4 in A field' , `async () => {
316248 await client.setValue('#a', 4)
317- }` )
318- . and ( 'User enter 5 in B field' , `async () => {
319249 await client.setValue('#b', 5)
320- }` )
321- . when ( 'User press Add button' , `async () => {
322250 await client.click('#add')
323251 }` )
324252 . then ( 'The result should contain 9' , `async () => {
325253 await client.assert.containsText('#result', 9)
326254 }` )
327- . scenario ( 'big numbers' )
328- . given ( 'User is on the simple calculator page' )
329- . and ( 'User enter 4 in A field' )
330- . and ( 'User enter 5 in B field' )
331- . when ( 'User press Add button' )
332- . then ( 'The result should contain 9' )
333- . feature ( 'subtraction' )
334- . scenario ( 'small numbers' )
335- . given ( 'User is on the simple calculator page' )
336- . and ( 'User enter 9 in A field' , `async () => {
337- await client.setValue('#a', 9)
338- }` )
339- . and ( 'User enter 3 in B field' , `async () => {
340- await client.setValue('#b', 3)
341- }` )
342- . when ( 'User press Subtract button' , `async () => {
343- await client.click('#subtract')
344- }` )
345- . then ( 'The result should contain 6' , `async () => {
346- await client.assert.containsText('#result', 6)
255+ . run ( )
256+ . then ( ( result ) => {
257+ result . features [ 0 ] . result . status . should . be . passed
258+ result . features [ 0 ] . result . scenarioCounts . should . deep . equal ( { passed : 1 } )
259+ result . features [ 0 ] . scenarios [ 0 ] . result . status . should . be . passed
260+ result . features [ 0 ] . scenarios [ 0 ] . result . stepCounts . should . deep . equal ( { passed : 2 } )
261+ } )
262+ } )
263+
264+ it ( 'should enable the usage of client in page object custom commands' , ( ) => {
265+ return testCaseFactory
266+ . create ( 'client-in-page-object-custom-commands-test' )
267+ . pageObject ( 'shared' , `module.exports = {
268+ url: 'http://yahoo.com',
269+ elements: {
270+ body: 'body',
271+ a: '#a',
272+ b: '#b',
273+ add: '#add',
274+ result: '#result'
275+ }
347276 }` )
348- . scenario ( 'big numbers' )
349- . given ( 'User is on the simple calculator page' )
350- . and ( 'User enter 4 in A field' )
351- . and ( 'User enter 5 in B field' )
352- . when ( 'User press Subtract button' )
353- . then ( 'The result should contain -1' , `async () => {
354- await client.assert.containsText('#result', -1)
277+ . pageObject ( 'calculator' , `const { client } = require('../../../lib/index')
278+ const shared = client.page.shared()
279+ const commands = {
280+ setA: function (value) {
281+ return shared.setValue('@a', value)
282+ },
283+ setB: function (value) {
284+ return shared.setValue('@b', value)
285+ },
286+ pressAdd: function () {
287+ return shared.click('@add')
288+ },
289+ checkResult: function (expectedResult) {
290+ return shared.assert.containsText('@result', expectedResult)
291+ }
292+ }
293+ module.exports = {
294+ url: 'http://yahoo.com',
295+ elements: {
296+ body: 'body',
297+ searchBar: 'input[name="p"]'
298+ },
299+ commands: [commands]
355300 }` )
301+ . feature ( 'addition' )
302+ . scenario ( 'small numbers' )
303+ . given ( 'User is on the simple calculator page' , ( ) => client . init ( ) )
304+ . and ( 'User enter 4 in A field' , ( ) => client . page . calculator ( ) . setA ( 4 ) )
305+ . and ( 'User enter 5 in B field' , ( ) => client . page . calculator ( ) . setB ( 5 ) )
306+ . when ( 'User press Add button' , ( ) => client . page . calculator ( ) . pressAdd ( ) )
307+ . then ( 'The result should contain 9' , ( ) => client . page . calculator ( ) . checkResult ( 9 ) )
356308 . run ( )
357309 . then ( ( result ) => {
358310 result . features [ 0 ] . result . status . should . be . passed
359- result . features [ 0 ] . result . scenarioCounts . should . deep . equal ( { passed : 2 } )
311+ result . features [ 0 ] . result . scenarioCounts . should . deep . equal ( { passed : 1 } )
360312 result . features [ 0 ] . scenarios [ 0 ] . result . status . should . be . passed
361313 result . features [ 0 ] . scenarios [ 0 ] . result . stepCounts . should . deep . equal ( { passed : 5 } )
362- result . features [ 0 ] . scenarios [ 1 ] . result . status . should . be . passed
363- result . features [ 0 ] . scenarios [ 1 ] . result . stepCounts . should . deep . equal ( { passed : 5 } )
364- result . features [ 1 ] . result . status . should . be . passed
365- result . features [ 1 ] . result . scenarioCounts . should . deep . equal ( { passed : 2 } )
366- result . features [ 1 ] . scenarios [ 0 ] . result . status . should . be . passed
367- result . features [ 1 ] . scenarios [ 0 ] . result . stepCounts . should . deep . equal ( { passed : 5 } )
368- result . features [ 1 ] . scenarios [ 1 ] . result . status . should . be . passed
369- result . features [ 1 ] . scenarios [ 1 ] . result . stepCounts . should . deep . equal ( { passed : 5 } )
370314 } )
371315 } )
372316} )
0 commit comments