@@ -2,9 +2,7 @@ package io.udash.web.guide.demos.frontend
22
33import io .udash .web .SeleniumTest
44import org .openqa .selenium .By .{ByClassName , ByCssSelector , ByTagName }
5- import org .openqa .selenium .{By , Keys }
65
7- import com .avsystem .commons ._
86import scala .util .Random
97
108class FrontendFormsTest extends SeleniumTest {
@@ -19,12 +17,12 @@ class FrontendFormsTest extends SeleniumTest {
1917 val checkbox = checkboxes.findElement(new ByClassName (s " checkbox-demo- $propertyName" ))
2018 checkbox.click()
2119 eventually {
22- checkboxes.findElements(new ByCssSelector (s " [data-bind= $propertyName] " )).asScala.forall (el => {
23- el.getText == expect
24- }) should be( true )
25- checkboxes.findElements(new ByClassName (s " checkbox-demo- $propertyName" )).asScala.forall (el => {
26- el.getAttribute( " selected " ) == checkbox.getAttribute( " selected " )
27- }) 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+ )
2826 }
2927 }
3028
@@ -45,13 +43,13 @@ class FrontendFormsTest extends SeleniumTest {
4543 val checkbox = checkButtons.findElement(new ByCssSelector (s " [data-label= $propertyName] " )).findElement(new ByTagName (" input" ))
4644 checkbox.click()
4745 eventually {
48- checkButtons.findElements(new ByClassName (" check-buttons-demo-fruits" )).asScala.forall (el => {
46+ forAll( checkButtons.findElements(new ByClassName (" check-buttons-demo-fruits" ))) (el => {
4947 val contains = el.getText.contains(propertyName)
50- if (checkbox.getAttribute( " selected " ) != null ) contains else ! contains
51- }) should be( true )
52- checkButtons.findElements(new ByCssSelector (s " [data-label= $propertyName] " )).asScala.forall (el => {
53- el.findElement(new ByTagName (" input" )).getAttribute( " selected " ) == checkbox.getAttribute( " selected " )
54- }) 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+ )
5553 }
5654 }
5755
@@ -68,13 +66,13 @@ class FrontendFormsTest extends SeleniumTest {
6866 val option = select.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " ))
6967 option.click()
7068 eventually {
71- multiSelect.findElements(new ByClassName (" multi-select-demo-fruits" )).asScala.forall (el => {
69+ forAll( multiSelect.findElements(new ByClassName (" multi-select-demo-fruits" ))) (el => {
7270 val contains = el.getText.contains(propertyName)
73- if (option.getAttribute( " selected " ) != null ) contains else ! contains
74- }) should be( true )
75- multiSelect.findElements(new ByTagName (" select" )).asScala.forall (el => {
76- el.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " )).getAttribute( " selected " ) == option.getAttribute( " selected " )
77- }) 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+ })
7876 }
7977 }
8078
@@ -92,13 +90,13 @@ class FrontendFormsTest extends SeleniumTest {
9290 val radio = radioButtons.findElement(new ByCssSelector (s " [data-label= $propertyName] " )).findElement(new ByTagName (" input" ))
9391 driver.executeScript(" arguments[0].click();" , radio)
9492 eventually {
95- radioButtons.findElements(new ByClassName (" radio-buttons-demo-fruits" )).asScala.forall (el => {
96- el.getText == propertyName
97- }) should be( true )
98- radioButtons.findElements(new ByCssSelector (s " input " )).asScala.forall (el => {
99- val eq = el.getAttribute( " selected " ) == radio.getAttribute( " selected " )
100- if (el.getAttribute (" value" ).toInt == propertyIdx) eq else ! eq
101- }) 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+ })
102100 }
103101 }
104102
@@ -117,12 +115,12 @@ class FrontendFormsTest extends SeleniumTest {
117115 val option = select.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " ))
118116 option.click()
119117 eventually {
120- selectDemo.findElements(new ByClassName (" select-demo-fruits" )).asScala.forall (el => {
121- el.getText == propertyName
122- }) should be( true )
123- selectDemo.findElements(new ByTagName (s " select " )).asScala.forall (el => {
124- el.findElement(new ByCssSelector (s " [value=' $propertyIdx'] " )).getAttribute( " selected " ) == option.getAttribute( " selected " )
125- }) 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+ })
126124 }
127125 }
128126
@@ -141,9 +139,9 @@ class FrontendFormsTest extends SeleniumTest {
141139 textArea.clear()
142140 textArea.sendKeys(text)
143141 eventually {
144- textAreaDemo.findElements(new ByTagName (s " textarea " )).asScala.forall (el => {
145- el.getAttribute (" value" ) == text
146- }) should be( true )
142+ forAll( textAreaDemo.findElements(new ByTagName (s " textarea " ))) (el => {
143+ el.getDomProperty (" value" ) shouldBe text
144+ })
147145 }
148146 }
149147
@@ -160,9 +158,9 @@ class FrontendFormsTest extends SeleniumTest {
160158 input.clear()
161159 input.sendKeys(text)
162160 eventually {
163- inputsDemo.findElements(new ByCssSelector (s " input[type= $tpe] " )).asScala.forall (el => {
164- el.getAttribute (" value" ) == text
165- }) should be( true )
161+ forAll( inputsDemo.findElements(new ByCssSelector (s " input[type= $tpe] " ))) (el => {
162+ el.getDomProperty (" value" ) shouldBe text
163+ })
166164 }
167165 }
168166
0 commit comments