11package io .udash .web .guide .demos .frontend
22
3- import com .avsystem .commons .*
43import io .udash .web .SeleniumTest
54import org .openqa .selenium .By .{ByClassName , ByCssSelector , ByTagName }
65
@@ -18,12 +17,12 @@ class FrontendFormsTest extends SeleniumTest {
1817 val checkbox = checkboxes.findElement(new ByClassName (s " checkbox-demo- $propertyName" ))
1918 checkbox.click()
2019 eventually {
21- checkboxes.findElements(new ByCssSelector (s " [data-bind= $propertyName] " )).asScala.forall (el => {
22- el.getText == expect
23- }) should be( true )
24- checkboxes.findElements(new ByClassName (s " checkbox-demo- $propertyName" )).asScala.forall (el => {
25- el.getDomAttribute( " selected " ) == checkbox.getDomAttribute( " selected " )
26- }) should be( true )
20+ forAll( checkboxes.findElements(new ByCssSelector (s " [data-bind= $propertyName] " ))) (el =>
21+ el.getText shouldBe expect
22+ )
23+ forAll( checkboxes.findElements(new ByClassName (s " checkbox-demo- $propertyName" ))) (el =>
24+ el.isSelected shouldBe checkbox.isSelected
25+ )
2726 }
2827 }
2928
@@ -44,13 +43,13 @@ class FrontendFormsTest extends SeleniumTest {
4443 val checkbox = checkButtons.findElement(new ByCssSelector (s " [data-label= $propertyName] " )).findElement(new ByTagName (" input" ))
4544 checkbox.click()
4645 eventually {
47- checkButtons.findElements(new ByClassName (" check-buttons-demo-fruits" )).asScala.forall (el => {
46+ forAll( checkButtons.findElements(new ByClassName (" check-buttons-demo-fruits" ))) (el => {
4847 val contains = el.getText.contains(propertyName)
49- if (checkbox.getDomAttribute( " selected " ) != null ) contains else ! contains
50- }) should be( true )
51- checkButtons.findElements(new ByCssSelector (s " [data-label= $propertyName] " )).asScala.forall (el => {
52- el.findElement(new ByTagName (" input" )).getDomAttribute( " selected " ) == checkbox.getDomAttribute( " selected " )
53- }) should be( true )
48+ assert( if (checkbox.isSelected) contains else ! contains)
49+ })
50+ forAll( checkButtons.findElements(new ByCssSelector (s " [data-label= $propertyName] " ))) (el =>
51+ el.findElement(new ByTagName (" input" )).isSelected shouldBe checkbox.isSelected
52+ )
5453 }
5554 }
5655
@@ -67,13 +66,13 @@ class FrontendFormsTest extends SeleniumTest {
6766 val option = select.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " ))
6867 option.click()
6968 eventually {
70- multiSelect.findElements(new ByClassName (" multi-select-demo-fruits" )).asScala.forall (el => {
69+ forAll( multiSelect.findElements(new ByClassName (" multi-select-demo-fruits" ))) (el => {
7170 val contains = el.getText.contains(propertyName)
72- if (option.getDomAttribute( " selected " ) != null ) contains else ! contains
73- }) should be( true )
74- multiSelect.findElements(new ByTagName (" select" )).asScala.forall (el => {
75- el.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " )).getDomAttribute( " selected " ) == option.getDomAttribute( " selected " )
76- }) should be( true )
71+ assert( if (option.isSelected) contains else ! contains)
72+ })
73+ forAll( multiSelect.findElements(new ByTagName (" select" ))) (el => {
74+ el.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " )).isSelected shouldBe option.isSelected
75+ })
7776 }
7877 }
7978
@@ -91,13 +90,13 @@ class FrontendFormsTest extends SeleniumTest {
9190 val radio = radioButtons.findElement(new ByCssSelector (s " [data-label= $propertyName] " )).findElement(new ByTagName (" input" ))
9291 driver.executeScript(" arguments[0].click();" , radio)
9392 eventually {
94- radioButtons.findElements(new ByClassName (" radio-buttons-demo-fruits" )).asScala.forall (el => {
95- el.getText == propertyName
96- }) should be( true )
97- radioButtons.findElements(new ByCssSelector (s " input " )).asScala.forall (el => {
98- val eq = el.getDomAttribute( " selected " ) == radio.getDomAttribute( " selected " )
99- if (el.getDomProperty(" value" ).toInt == propertyIdx) eq else ! eq
100- }) should be( true )
93+ forAll( radioButtons.findElements(new ByClassName (" radio-buttons-demo-fruits" ))) (el =>
94+ el.getText shouldBe propertyName
95+ )
96+ forAll( radioButtons.findElements(new ByCssSelector (s " input " ))) (el => {
97+ val eq = el.isSelected == radio.isSelected
98+ assert( if (el.getDomProperty(" value" ).toInt == propertyIdx) eq else ! eq)
99+ })
101100 }
102101 }
103102
@@ -116,12 +115,12 @@ class FrontendFormsTest extends SeleniumTest {
116115 val option = select.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " ))
117116 option.click()
118117 eventually {
119- selectDemo.findElements(new ByClassName (" select-demo-fruits" )).asScala.forall (el => {
120- el.getText == propertyName
121- }) should be( true )
122- selectDemo.findElements(new ByTagName (s " select " )).asScala.forall (el => {
123- el.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " )).getDomAttribute( " selected " ) == option.getDomAttribute( " selected " )
124- }) should be( true )
118+ forAll( selectDemo.findElements(new ByClassName (" select-demo-fruits" ))) (el => {
119+ el.getText shouldBe propertyName
120+ })
121+ forAll( selectDemo.findElements(new ByTagName (s " select " ))) (el => {
122+ el.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " )).isSelected shouldBe option.isSelected
123+ })
125124 }
126125 }
127126
@@ -140,9 +139,9 @@ class FrontendFormsTest extends SeleniumTest {
140139 textArea.clear()
141140 textArea.sendKeys(text)
142141 eventually {
143- textAreaDemo.findElements(new ByTagName (s " textarea " )).asScala.forall (el => {
144- el.getDomProperty(" value" ) == text
145- }) should be( true )
142+ forAll( textAreaDemo.findElements(new ByTagName (s " textarea " ))) (el => {
143+ el.getDomProperty(" value" ) shouldBe text
144+ })
146145 }
147146 }
148147
@@ -159,9 +158,9 @@ class FrontendFormsTest extends SeleniumTest {
159158 input.clear()
160159 input.sendKeys(text)
161160 eventually {
162- inputsDemo.findElements(new ByCssSelector (s " input[type= $tpe] " )).asScala.forall (el => {
163- el.getDomProperty(" value" ) == text
164- }) should be( true )
161+ forAll( inputsDemo.findElements(new ByCssSelector (s " input[type= $tpe] " ))) (el => {
162+ el.getDomProperty(" value" ) shouldBe text
163+ })
165164 }
166165 }
167166
0 commit comments