1- using System . Text . RegularExpressions ;
1+ using System . Collections . Generic ;
2+ using System . Text . RegularExpressions ;
23using System . Threading . Tasks ;
34using NUnit . Framework ;
45using Playwright . ReactUI . Controls ;
@@ -8,152 +9,176 @@ namespace Playwright.ReactUI.Tests.Assertions;
89
910public class ButtonAssertionsV2Tests : TestsBase
1011{
12+ private static IEnumerable < TestCaseData > ButtonCases ( )
13+ {
14+ yield return new TestCaseData ( "button" ) ;
15+ // ReSharper disable once StringLiteralTypo
16+ yield return new TestCaseData ( "htmlbutton" ) ;
17+ }
18+
1119 [ Test ]
12- public async Task ToBeVisible ( )
20+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
21+ public async Task ToBeVisible ( string buttonType )
1322 {
14- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
23+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
1524 await button . ExpectV2 ( ) . ToBeVisibleAsync ( ) . ConfigureAwait ( false ) ;
1625 }
1726
1827 [ Test ]
19- public async Task ToBeHidden ( )
28+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
29+ public async Task ToBeHidden ( string buttonType )
2030 {
21- var button = await GetButtonAsync ( " hidden") . ConfigureAwait ( false ) ;
31+ var button = await GetButtonAsync ( $ " { buttonType } -- hidden") . ConfigureAwait ( false ) ;
2232 await button . WaitForAsync ( ) . ConfigureAwait ( false ) ;
2333
2434 await button . ExpectV2 ( ) . ToBeHiddenAsync ( ) . ConfigureAwait ( false ) ;
2535 }
2636
2737 [ Test ]
28- public async Task ToBeEnabled ( )
38+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
39+ public async Task ToBeEnabled ( string buttonType )
2940 {
30- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
41+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
3142 await button . ExpectV2 ( ) . ToBeEnabledAsync ( ) . ConfigureAwait ( false ) ;
3243 }
3344
3445 [ Test ]
35- public async Task ToBeDisabled ( )
46+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
47+ public async Task ToBeDisabled ( string buttonType )
3648 {
37- var button = await GetButtonAsync ( " disabled") . ConfigureAwait ( false ) ;
49+ var button = await GetButtonAsync ( $ " { buttonType } -- disabled") . ConfigureAwait ( false ) ;
3850 await button . ExpectV2 ( ) . ToBeDisabledAsync ( ) . ConfigureAwait ( false ) ;
3951 }
4052
4153 [ Test ]
4254 public async Task ToHaveError ( )
4355 {
44- var button = await GetButtonAsync ( "error" ) . ConfigureAwait ( false ) ;
56+ var button = await GetButtonAsync ( "button-- error" ) . ConfigureAwait ( false ) ;
4557 await button . ExpectV2 ( ) . ToHaveErrorAsync ( ) . ConfigureAwait ( false ) ;
4658 }
4759
4860 [ Test ]
4961 public async Task NotToHaveError ( )
5062 {
51- var button = await GetButtonAsync ( "default" ) . ConfigureAwait ( false ) ;
63+ var button = await GetButtonAsync ( "button-- default" ) . ConfigureAwait ( false ) ;
5264 await button . ExpectV2 ( ) . NotToHaveErrorAsync ( ) . ConfigureAwait ( false ) ;
5365 }
5466
5567 [ Test ]
5668 public async Task ToHaveWarning ( )
5769 {
58- var button = await GetButtonAsync ( "warning" ) . ConfigureAwait ( false ) ;
70+ var button = await GetButtonAsync ( "button-- warning" ) . ConfigureAwait ( false ) ;
5971 await button . ExpectV2 ( ) . ToHaveWarningAsync ( ) . ConfigureAwait ( false ) ;
6072 }
6173
6274 [ Test ]
6375 public async Task NotToHaveWarning ( )
6476 {
65- var button = await GetButtonAsync ( "default" ) . ConfigureAwait ( false ) ;
77+ var button = await GetButtonAsync ( "button-- default" ) . ConfigureAwait ( false ) ;
6678 await button . ExpectV2 ( ) . NotToHaveWarningAsync ( ) . ConfigureAwait ( false ) ;
6779 }
6880
6981 [ Test ]
70- public async Task ToHaveAttribute_With_Attribute_Value ( )
82+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
83+ public async Task ToHaveAttribute_With_Attribute_Value ( string buttonType )
7184 {
72- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
85+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
7386 await button . ExpectV2 ( ) . ToHaveAttributeAsync ( "data-tid" , "ButtonId" ) . ConfigureAwait ( false ) ;
7487 }
7588
7689 [ Test ]
77- public async Task ToHaveAttribute_Without_Attribute_Value ( )
90+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
91+ public async Task ToHaveAttribute_Without_Attribute_Value ( string buttonType )
7892 {
79- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
93+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
8094 await button . ExpectV2 ( ) . ToHaveAttributeAsync ( "data-tid" ) . ConfigureAwait ( false ) ;
8195 }
8296
8397 [ Test ]
84- public async Task NotToHaveAttribute_With_Attribute_Value ( )
98+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
99+ public async Task NotToHaveAttribute_With_Attribute_Value ( string buttonType )
85100 {
86- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
101+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
87102 await button . ExpectV2 ( ) . NotToHaveAttributeAsync ( "data-tid" , "WrongValue" ) . ConfigureAwait ( false ) ;
88103 }
89104
90105 [ Test ]
91- public async Task NotToHaveAttribute_Without_Attribute_Value ( )
106+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
107+ public async Task NotToHaveAttribute_Without_Attribute_Value ( string buttonType )
92108 {
93- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
109+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
94110 await button . ExpectV2 ( ) . NotToHaveAttributeAsync ( "data-tid-2" ) . ConfigureAwait ( false ) ;
95111 }
96112
97113 [ Test ]
98- public async Task ToHaveText ( )
114+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
115+ public async Task ToHaveText ( string buttonType )
99116 {
100- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
117+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
101118 await button . ExpectV2 ( ) . ToHaveTextAsync ( "TODO" ) . ConfigureAwait ( false ) ;
102119 }
103120
104121 [ Test ]
105- public async Task ToHaveText_With_Regex ( )
122+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
123+ public async Task ToHaveText_With_Regex ( string buttonType )
106124 {
107- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
125+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
108126 await button . ExpectV2 ( ) . ToHaveTextAsync ( new Regex ( "^TO.*" ) ) . ConfigureAwait ( false ) ;
109127 }
110128
111129 [ Test ]
112- public async Task NotToHaveText ( )
130+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
131+ public async Task NotToHaveText ( string buttonType )
113132 {
114- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
133+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
115134 await button . ExpectV2 ( ) . NotToHaveTextAsync ( "TODO777" ) . ConfigureAwait ( false ) ;
116135 }
117136
118137 [ Test ]
119- public async Task NotToHaveText_With_Regex ( )
138+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
139+ public async Task NotToHaveText_With_Regex ( string buttonType )
120140 {
121- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
141+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
122142 await button . ExpectV2 ( ) . NotToHaveTextAsync ( new Regex ( "^TOD1.*" ) ) . ConfigureAwait ( false ) ;
123143 }
124144
125145 [ Test ]
126- public async Task ToContainText ( )
146+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
147+ public async Task ToContainText ( string buttonType )
127148 {
128- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
149+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
129150 await button . ExpectV2 ( ) . ToContainTextAsync ( "TO" ) . ConfigureAwait ( false ) ;
130151 }
131152
132153 [ Test ]
133- public async Task ToContainText_With_Regex ( )
154+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
155+ public async Task ToContainText_With_Regex ( string buttonType )
134156 {
135- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
157+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
136158 await button . ExpectV2 ( ) . ToContainTextAsync ( new Regex ( "^T.*" ) ) . ConfigureAwait ( false ) ;
137159 }
138160
139161 [ Test ]
140- public async Task NotToContainText ( )
162+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
163+ public async Task NotToContainText ( string buttonType )
141164 {
142- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
165+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
143166 await button . ExpectV2 ( ) . NotToContainTextAsync ( "777" ) . ConfigureAwait ( false ) ;
144167 }
145168
146169 [ Test ]
147- public async Task NotToContainText_With_Regex ( )
170+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
171+ public async Task NotToContainText_With_Regex ( string buttonType )
148172 {
149- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
173+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
150174 await button . ExpectV2 ( ) . NotToContainTextAsync ( new Regex ( "^7.*" ) ) . ConfigureAwait ( false ) ;
151175 }
152176
153177 [ Test ]
154- public async Task ToBeFocused_And_NotToBeFocused ( )
178+ [ TestCaseSource ( nameof ( ButtonCases ) ) ]
179+ public async Task ToBeFocused_And_NotToBeFocused ( string buttonType )
155180 {
156- var button = await GetButtonAsync ( " default") . ConfigureAwait ( false ) ;
181+ var button = await GetButtonAsync ( $ " { buttonType } -- default") . ConfigureAwait ( false ) ;
157182
158183 await button . ExpectV2 ( ) . NotToBeFocusedAsync ( ) . ConfigureAwait ( false ) ;
159184
@@ -163,7 +188,7 @@ public async Task ToBeFocused_And_NotToBeFocused()
163188
164189 private async Task < Button > GetButtonAsync ( string storyName )
165190 {
166- await Page . GotoAsync ( StorybookUrl . Get ( $ "button-- { storyName } " ) ) . ConfigureAwait ( false ) ;
191+ await Page . GotoAsync ( StorybookUrl . Get ( storyName ) ) . ConfigureAwait ( false ) ;
167192 return new Button ( Page . GetByTestId ( "ButtonId" ) ) ;
168193 }
169194}
0 commit comments