@@ -34,3 +34,160 @@ Then(
3434 validation ( elementText , expectedValue ) ;
3535 }
3636) ;
37+
38+ /**
39+ * Verify that property of element satisfies condition
40+ * @param {string } property - element to verify
41+ * @param {string } alias - element to verify
42+ * @param {string } validationType - validation
43+ * @param {string } value - expected value
44+ * @example I expect 'value' property of 'Search Input' to be equal 'text'
45+ * @example I expect 'innerHTML' property of 'Label' to contain '<b>'
46+ */
47+ Then (
48+ 'I expect {string} property of {string} {playwrightValidation} {string}' ,
49+ async function ( property : string , alias : string , validationType : string , value : string ) {
50+ const propertyName = await getValue ( property ) ;
51+ const expectedValue = await getValue ( value ) ;
52+ const element = await getElement ( alias ) ;
53+ const validation = getValidation ( validationType ) ;
54+ const actualValue = await element . evaluate ( ( node : any , propertyName : string ) => node [ propertyName ] , propertyName ) ;
55+ validation ( actualValue , expectedValue ) ;
56+ }
57+ ) ;
58+
59+ /**
60+ * Verify that attribute of element satisfies condition
61+ * @param {string } attribute - element to verify
62+ * @param {string } alias - element to verify
63+ * @param {string } validationType - validation
64+ * @param {string } value - expected value
65+ * @example I expect 'href' attribute of 'Home Link' to contain '/home'
66+ */
67+ Then (
68+ 'I expect {string} attribute of {string} {playwrightValidation} {string}' ,
69+ async function ( attribute : string , alias : string , validationType : string , value : string ) {
70+ const attributeName = await getValue ( attribute ) ;
71+ const expectedValue = await getValue ( value ) ;
72+ const element = await getElement ( alias ) ;
73+ const validation = getValidation ( validationType ) ;
74+ const actualValue = await element . getAttribute ( attributeName ) ;
75+ validation ( actualValue , expectedValue ) ;
76+ }
77+ ) ;
78+
79+ /**
80+ * Verify that current url satisfies condition
81+ * @param {string } validationType - validation
82+ * @param {string } expected - expected value
83+ * @example I expect current url contains 'wikipedia'
84+ * @example I expect current url equals 'https://wikipedia.org'
85+ */
86+ Then (
87+ 'I expect current url {playwrightValidation} {string}' ,
88+ async function ( validationType : string , expected : string ) {
89+ const validation = getValidation ( validationType ) ;
90+ const expectedUrl = await getValue ( expected ) ;
91+ const actualUrl = page . url ( ) ;
92+ validation ( actualUrl , expectedUrl ) ;
93+ }
94+ ) ;
95+
96+ /**
97+ * Verify that number of element in collection satisfies condition
98+ * @param {string } alias - collection to verify
99+ * @param {string } validationType - validation
100+ * @param {string } value - expected value
101+ * @example I expect number of elements in 'Search Results' collection to be equal '50'
102+ * @example I expect number of elements in 'Search Results' collection to be above '49'
103+ * @example I expect number of elements in 'Search Results' collection to be below '51'
104+ */
105+ Then (
106+ 'I expect number of elements in {string} collection {playwrightValidation} {string}' ,
107+ async function ( alias : string , validationType : string , value : string ) {
108+ const expectedValue = await getValue ( value ) ;
109+ const collection = await getElement ( alias ) ;
110+ const validation = getValidation ( validationType ) ;
111+ validation ( await collection . count ( ) , expectedValue ) ;
112+ }
113+ ) ;
114+
115+ /**
116+ * Verify that page title satisfies condition
117+ * @param {string } validationType - validation
118+ * @param {string } expected - expected value
119+ * @example I expect page title equals 'Wikipedia'
120+ */
121+ Then (
122+ 'I expect page title {playwrightValidation} {string}' ,
123+ async function ( validationType : string , expected : string ) {
124+ const validation = getValidation ( validationType ) ;
125+ const expectedTitle = await getValue ( expected ) ;
126+ const actualTitle = await page . title ( ) ;
127+ validation ( actualTitle , expectedTitle ) ;
128+ }
129+ ) ;
130+
131+ /**
132+ * Verify that all texts in collection satisfy condition
133+ * @param {string } alias - collection to get texts
134+ * @param {string } validationType - validation
135+ * @param {string } value - expected result
136+ * @example I expect text of every element in 'Search Results' collection equals to 'google'
137+ * @example I expect text of every element in 'Search Results' collection does not contain 'yandex'
138+ */
139+ Then (
140+ 'I expect text of every element in {string} collection {playwrightValidation} {string}' ,
141+ async function ( alias : string , validationType : string , value : string ) {
142+ const expectedValue = await getValue ( value ) ;
143+ const collection = await getElement ( alias ) ;
144+ const validation = getValidation ( validationType ) ;
145+ for ( let i = 0 ; i < await collection . count ( ) ; i ++ ) {
146+ const elementText : string = await collection . nth ( i ) . innerText ( ) ;
147+ validation ( elementText , expectedValue ) ;
148+ }
149+ }
150+ ) ;
151+
152+ /**
153+ * Verify that all particular attributes in collection satisfy condition
154+ * @param {string } alias - collection to get attrs
155+ * @param {string } validationType - validation
156+ * @param {string } value - expected result
157+ * @example I expect 'href' attribute of every element in 'Search Results' collection to contain 'google'
158+ */
159+ Then (
160+ 'I expect {string} attribute of every element in {string} collection {playwrightValidation} {string}' ,
161+ async function ( attribute : string , alias : string , validationType : string , value : string ) {
162+ const expectedValue = await getValue ( value ) ;
163+ const collection = await getElement ( alias ) ;
164+ const validation = getValidation ( validationType ) ;
165+ for ( let i = 0 ; i < await collection . count ( ) ; i ++ ) {
166+ const attributeValue : string | null = await collection . nth ( i ) . getAttribute ( attribute ) ;
167+ validation ( attributeValue , expectedValue ) ;
168+ }
169+ }
170+ ) ;
171+
172+ /**
173+ * Verify that all particular properties in collection satisfy condition
174+ * @param {string } alias - collection to get props
175+ * @param {string } validationType - validation
176+ * @param {string } value - expected result
177+ * @example I expect 'href' property of every element in 'Search Results' collection to contain 'google'
178+ */
179+ Then (
180+ 'I expect {string} property of every element in {string} collection {playwrightValidation} {string}' ,
181+ async function ( property : string , alias : string , validationType : string , value : string ) {
182+ const expectedValue = await getValue ( value ) ;
183+ const collection = await getElement ( alias ) ;
184+ const validation = getValidation ( validationType ) ;
185+ for ( let i = 0 ; i < await collection . count ( ) ; i ++ ) {
186+ const propertyValue : string | null = await collection . nth ( i ) . evaluate (
187+ ( node : any , property : string ) => node [ property ] , property
188+ ) ;
189+ validation ( propertyValue , expectedValue ) ;
190+ }
191+ }
192+ ) ;
193+
0 commit comments