Best Playwright-dotnet code snippet using Microsoft.Playwright.PageWaitForSelectorOptions.PageWaitForSelectorOptions
PageAssertions.cs
Source:PageAssertions.cs
...31 return new ReferenceTypeAssertion<IPage>(page);32 }33 private static IElementHandle GetElement(IPage page,34 string selector,35 PageWaitForSelectorOptions? waitOptions = null,36 PageQuerySelectorOptions? queryOptions = null)37 {38 page.WaitForSelector(selector, waitOptions);39 var element = page.QuerySelector(selector, queryOptions)!;40 return element!;41 }42 public static IPage HaveTitle(43 this ReferenceTypeAssertion<IPage> page,44 string expected,45 string because = "no reason given")46 {47 var actual = page.Value.Title();48 if (string.Compare(actual, expected) != 0)49 {50 throw new AssertException(@$"51HaveTitle Assert Exception52Expected:53{expected}54Actual:55{actual}56Because: {because}57");58 }59 return page.Value;60 }61 public static IPage HaveNotTitle(62 this ReferenceTypeAssertion<IPage> page,63 string notExpected,64 string because = "no reason given")65 {66 var actual = page.Value.Title();67 if (string.Compare(actual, notExpected) == 0)68 {69 throw new AssertException(@$"70HaveNotTitle Assert Exception71Not expected:72{notExpected}73Actual:74{actual}75Because:76{because}77");78 }79 return page.Value;80 }81 public static IPage HaveContent(82 this ReferenceTypeAssertion<IPage> page,83 string expected,84 string because = "no reason given")85 {86 var actual = page.Value.Content();87 if (string.Compare(actual, expected) != 0)88 {89 throw new AssertException(@$"90HaveContent Assert Exception91Not expected:92{expected}93Actual:94{actual}95Because:96{because}97");98 }99 return page.Value;100 }101 public static IPage HaveNotContent(102 this ReferenceTypeAssertion<IPage> page,103 string notExpected,104 string because = "no reason given")105 {106 var actual = page.Value.Content();107 if (string.Compare(actual, notExpected) == 0)108 {109 throw new AssertException(@$"110HaveNotContent Assert Exception111Not expected:112{notExpected}113Actual:114{actual}115Because:116{because}117");118 }119 return page.Value;120 }121 public static IPage HaveCheckedElement(122 this ReferenceTypeAssertion<IPage> page,123 string selector,124 string because = "no reason given",125 PageWaitForSelectorOptions? waitOptions = null,126 PageQuerySelectorOptions? queryOptions = null)127 {128 var element = GetElement(page.Value, selector, waitOptions, queryOptions);129 var isChecked = element.IsChecked();130 if (isChecked is false)131 {132 throw new AssertException(@$"133HaveElementChecked Assert Exception134Selector: {selector}135Expected: checked136Actual: not checked137Because: {because}138");139 }140 return page.Value;141 }142 public static IPage HaveNotCheckedElement(143 this ReferenceTypeAssertion<IPage> page,144 string selector,145 string because = "no reason given",146 PageWaitForSelectorOptions? waitOptions = null,147 PageQuerySelectorOptions? queryOptions = null)148 {149 var element = GetElement(page.Value, selector, waitOptions, queryOptions);150 var isChecked = element.IsChecked();151 if (isChecked is true)152 {153 throw new AssertException(@$"154HaveNotElementChecked Assert Exception155Selector: {selector}156Expected: not checked157Actual: checked158Because: {because}159");160 }161 return page.Value;162 }163 public static IPage HaveDisabledElement(164 this ReferenceTypeAssertion<IPage> page,165 string selector,166 string because = "no reason given",167 PageWaitForSelectorOptions? waitOptions = null,168 PageQuerySelectorOptions? queryOptions = null)169 {170 var element = GetElement(page.Value, selector, waitOptions, queryOptions);171 var isDisabled = element.IsDisabled();172 if (isDisabled is false)173 {174 throw new AssertException(@$"175HaveNotElementChecked Assert Exception176Selector: {selector}177Expected: disable178Actual: not disable179Because: {because}180");181 }182 return page.Value;183 }184 public static IPage HaveNotDisabledElement(185 this ReferenceTypeAssertion<IPage> page,186 string selector,187 string because = "no reason given",188 PageWaitForSelectorOptions? waitOptions = null,189 PageQuerySelectorOptions? queryOptions = null)190 {191 var element = GetElement(page.Value, selector, waitOptions, queryOptions);192 var isDisabled = element.IsDisabled();193 if (isDisabled is true)194 {195 throw new AssertException(@$"196HaveNotElementDisabled Assert Exception197Selector: {selector}198Expected: not disable199Actual: disable200Because: {because}201");202 }203 return page.Value;204 }205 public static IPage HaveEditableElement(206 this ReferenceTypeAssertion<IPage> page,207 string selector,208 string because = "no reason given",209 PageWaitForSelectorOptions? waitOptions = null,210 PageQuerySelectorOptions? queryOptions = null)211 {212 var element = GetElement(page.Value, selector, waitOptions, queryOptions);213 var isEditable = element.IsEditable();214 if (isEditable is false)215 {216 throw new AssertException(@$"217HaveElementEditable Assert Exception218Selector: {selector}219Expected: editable220Actual: not editable221Because: {because}222");223 }224 return page.Value;225 }226 public static IPage HaveNotEditableElement(227 this ReferenceTypeAssertion<IPage> page,228 string selector,229 string because = "no reason given",230 PageWaitForSelectorOptions? waitOptions = null,231 PageQuerySelectorOptions? queryOptions = null)232 {233 var element = GetElement(page.Value, selector, waitOptions, queryOptions);234 var isEditable = element.IsEditable();235 if (isEditable is true)236 {237 throw new AssertException(@$"238HaveElementEditable Assert Exception239Selector: {selector}240Expected: not editable241Actual: editable242Because: {because}243");244 }245 return page.Value;246 }247 public static IPage HaveEnabledElement(248 this ReferenceTypeAssertion<IPage> page,249 string selector,250 string because = "no reason given",251 PageWaitForSelectorOptions? waitOptions = null,252 PageQuerySelectorOptions? queryOptions = null)253 {254 var element = GetElement(page.Value, selector, waitOptions, queryOptions);255 var isEnabled = element.IsEnabled();256 if (isEnabled is false)257 {258 throw new AssertException(@$"259HaveElementEnabled Assert Exception260Selector: {selector}261Expected: enable262Actual: not enable263Because: {because}264");265 }266 return page.Value;267 }268 public static IPage HaveNotEnabledElement(269 this ReferenceTypeAssertion<IPage> page,270 string selector,271 string because = "no reason given",272 PageWaitForSelectorOptions? waitOptions = null,273 PageQuerySelectorOptions? queryOptions = null)274 {275 var element = GetElement(page.Value, selector, waitOptions, queryOptions);276 var isEnabled = element.IsEnabled();277 if (isEnabled is true)278 {279 throw new AssertException(@$"280HaveNotElementEnabled Assert Exception281Selector: {selector}282Expected: not enable283Actual: enable284Because: {because}285");286 }287 return page.Value;288 }289 public static IPage HaveHiddenElement(290 this ReferenceTypeAssertion<IPage> page,291 string selector,292 string because = "no reason given",293 PageWaitForSelectorOptions? waitOptions = null,294 PageQuerySelectorOptions? queryOptions = null)295 {296 var element = GetElement(page.Value, selector, waitOptions, queryOptions);297 var isHidden = element.IsHidden();298 if (isHidden is false)299 {300 throw new AssertException(@$"301HaveElementHidden Assert Exception302Selector: {selector}303Expected: hidden304Actual: not hidden305Because: {because}306");307 }308 return page.Value;309 }310 public static IPage HaveNotHiddenElement(311 this ReferenceTypeAssertion<IPage> page,312 string selector,313 string because = "no reason given",314 PageWaitForSelectorOptions? waitOptions = null,315 PageQuerySelectorOptions? queryOptions = null)316 {317 var element = GetElement(page.Value, selector, waitOptions, queryOptions);318 var isHidden = element.IsHidden();319 if (isHidden is true)320 {321 throw new AssertException(@$"322HaveNotElementHidden Assert Exception323Selector: {selector}324Expected: not hidden325Actual: hidden326Because: {because}327");328 }329 return page.Value;330 }331 public static IPage HaveVisibleElement(332 this ReferenceTypeAssertion<IPage> page,333 string selector,334 string because = "no reason given",335 PageWaitForSelectorOptions? waitOptions = null,336 PageQuerySelectorOptions? queryOptions = null)337 {338 var element = GetElement(page.Value, selector, waitOptions, queryOptions);339 var isVisible = element.IsVisible();340 if (isVisible is false)341 {342 throw new AssertException(@$"343HaveElementVisible Assert Exception344Selector: {selector}345Expected: visible346Actual: not visible347Because: {because}348");349 }350 return page.Value;351 }352 public static IPage HaveNotVisibleElement(353 this ReferenceTypeAssertion<IPage> page,354 string selector,355 string because = "no reason given",356 PageWaitForSelectorOptions? waitOptions = null,357 PageQuerySelectorOptions? queryOptions = null)358 {359 var element = GetElement(page.Value, selector, waitOptions, queryOptions);360 var isVisible = element.IsVisible();361 if (isVisible is true)362 {363 throw new AssertException(@$"364HaveElementVisible Assert Exception365Selector: {selector}366Expected: not visible367Actual: visible368Because: {because}369");370 }371 return page.Value;372 }373 public static IPage HaveElementTextContent(374 this ReferenceTypeAssertion<IPage> page,375 string selector,376 string expected,377 string because = "no reason given",378 PageWaitForSelectorOptions? waitOptions = null,379 PageQuerySelectorOptions? queryOptions = null)380 {381 var element = GetElement(page.Value, selector, waitOptions, queryOptions);382 var actual = element.TextContent() ?? "";383 if (string.Compare(actual, expected) != 0)384 {385 throw new AssertException(@$"386HaveElementTextContent Assert Exception387Selector: {selector}388Expected:389{expected}390Actual:391{actual}392Because:393{because}394");395 }396 return page.Value;397 }398 public static IPage HaveNotElementTextContent(399 this ReferenceTypeAssertion<IPage> page,400 string selector,401 string notExpected,402 string because = "no reason given",403 PageWaitForSelectorOptions? waitOptions = null,404 PageQuerySelectorOptions? queryOptions = null)405 {406 var element = GetElement(page.Value, selector, waitOptions, queryOptions);407 var actual = element.TextContent() ?? "";408 if (string.Compare(actual, notExpected) == 0)409 {410 throw new AssertException(@$"411HaveNotElementTextContent Assert Exception412Selector: {selector}413Not expected:414{notExpected}415Actual:416{actual}417Because:418{because}419");420 }421 return page.Value;422 }423 public static IPage HaveElementInnerHTML(424 this ReferenceTypeAssertion<IPage> page,425 string selector,426 string expected,427 string because = "no reason given",428 PageWaitForSelectorOptions? waitOptions = null,429 PageQuerySelectorOptions? queryOptions = null)430 {431 var element = GetElement(page.Value, selector, waitOptions, queryOptions);432 var actual = element.InnerHTML();433 if (string.Compare(actual, expected) != 0)434 {435 throw new AssertException(@$"436HaveElementInnerHTML Assert Exception437Selector: {selector}438Expected:439{expected}440Actual:441{actual}442Because:443{because}444");445 }446 return page.Value;447 }448 public static IPage HaveNotElementInnerHTML(449 this ReferenceTypeAssertion<IPage> page,450 string selector,451 string notExpected,452 string because = "no reason given",453 PageWaitForSelectorOptions? waitOptions = null,454 PageQuerySelectorOptions? queryOptions = null)455 {456 var element = GetElement(page.Value, selector, waitOptions, queryOptions);457 var actual = element.InnerHTML();458 if (string.Compare(actual, notExpected) == 0)459 {460 throw new AssertException(@$"461HaveNotElementInnerHTML Assert Exception462Selector: {selector}463Not expected:464{notExpected}465Actual:466{actual}467Because:468{because}469");470 }471 return page.Value;472 }473 public static IPage HaveElementInnerText(474 this ReferenceTypeAssertion<IPage> page,475 string selector,476 string expected,477 string because = "no reason given",478 PageWaitForSelectorOptions? waitOptions = null,479 PageQuerySelectorOptions? queryOptions = null)480 {481 var element = GetElement(page.Value, selector, waitOptions, queryOptions);482 var actual = element.InnerText();483 if (string.Compare(actual, expected) != 0)484 {485 throw new AssertException(@$"486HaveElementInnerText Assert Exception487Selector: {selector}488Expected:489{expected}490Actual:491{actual}492Because:493{because}494");495 }496 return page.Value;497 }498 public static IPage HaveNotElementInnerText(499 this ReferenceTypeAssertion<IPage> page,500 string selector,501 string notExpected,502 string because = "no reason given",503 PageWaitForSelectorOptions? waitOptions = null,504 PageQuerySelectorOptions? queryOptions = null)505 {506 var element = GetElement(page.Value, selector, waitOptions, queryOptions);507 var actual = element.InnerText();508 if (string.Compare(actual, notExpected) == 0)509 {510 throw new AssertException(@$"511HaveNotElementInnerText Assert Exception512Selector: {selector}513Not expected:514{notExpected}515Actual:516{actual}517Because:518{because}519");520 }521 return page.Value;522 }523 public static IPage HaveElementInputValue(524 this ReferenceTypeAssertion<IPage> page,525 string selector,526 string expected,527 string because = "no reason given",528 PageWaitForSelectorOptions? waitOptions = null,529 PageQuerySelectorOptions? queryOptions = null,530 ElementHandleInputValueOptions? inputOptions = null)531 {532 var element = GetElement(page.Value, selector, waitOptions, queryOptions);533 var actual = element.InputValue(inputOptions);534 if (string.Compare(actual, expected) != 0)535 {536 throw new AssertException(@$"537HaveElementInputValue Assert Exception538Selector: {selector}539Expected:540{expected}541Actual:542{actual}543Because:544{because}545");546 }547 return page.Value;548 }549 public static IPage HaveNotElementInputValue(550 this ReferenceTypeAssertion<IPage> page,551 string selector,552 string notExpected,553 string because = "no reason given",554 PageWaitForSelectorOptions? waitOptions = null,555 PageQuerySelectorOptions? queryOptions = null,556 ElementHandleInputValueOptions? inputOptions = null)557 {558 var element = GetElement(page.Value, selector, waitOptions, queryOptions);559 var actual = element.InputValue(inputOptions);560 if (string.Compare(actual, notExpected) == 0)561 {562 throw new AssertException(@$"563HaveNotElementInputValue Assert Exception564Selector: {selector}565Not expected:566{notExpected}567Actual:568{actual}569Because:570{because}571");572 }573 return page.Value;574 }575 public static IPage HaveElementAttribute(576 this ReferenceTypeAssertion<IPage> page,577 string selector,578 string attributeName,579 string because = "no reason given",580 PageWaitForSelectorOptions? waitOptions = null,581 PageQuerySelectorOptions? queryOptions = null)582 {583 var element = GetElement(page.Value, selector, waitOptions, queryOptions);584 var value = element.GetAttribute(attributeName);585 if (value is null)586 {587 throw new AssertException(@$"588HaveElementAttribute Assert Exception589Selector: {selector}590Expected attribute: {attributeName}591Because: {because}592");593 }594 return page.Value;595 }596 public static IPage HaveNotElementAttribute(597 this ReferenceTypeAssertion<IPage> page,598 string selector,599 string attributeName,600 string because = "no reason given",601 PageWaitForSelectorOptions? waitOptions = null,602 PageQuerySelectorOptions? queryOptions = null)603 {604 var element = GetElement(page.Value, selector, waitOptions, queryOptions);605 var value = element.GetAttribute(attributeName);606 if (value is not null)607 {608 throw new AssertException(@$"609HaveNotElementAttribute Assert Exception610Selector: {selector}611Not expected attribute: {attributeName}612Because: {because}613");614 }615 return page.Value;616 }617 public static IPage HaveElementAttributeValue(618 this ReferenceTypeAssertion<IPage> page,619 string selector,620 string attributeName,621 string expectedAttributeValue,622 string because = "no reason given",623 PageWaitForSelectorOptions? waitOptions = null,624 PageQuerySelectorOptions? queryOptions = null)625 {626 var element = GetElement(page.Value, selector, waitOptions, queryOptions);627 var value = element.GetAttribute(attributeName);628 if (value is null)629 {630 throw new AssertException($"Attribute not found. Attibute name: {attributeName}");631 }632 if (string.Compare(value, expectedAttributeValue) != 0)633 {634 throw new AssertException(@$"635HaveElementAttributeValue Assert Exception636Selector: {selector}637Expected attribute: {attributeName}638Expected attribute value: {expectedAttributeValue}639Actual attribute value: {value}640Because: {because}641");642 }643 return page.Value;644 }645 public static IPage HaveElementNotAttributeValue(646 this ReferenceTypeAssertion<IPage> page,647 string selector,648 string attributeName,649 string expectedAttributeValue,650 string because = "no reason given",651 PageWaitForSelectorOptions? waitOptions = null,652 PageQuerySelectorOptions? queryOptions = null)653 {654 var element = GetElement(page.Value, selector, waitOptions, queryOptions);655 var value = element.GetAttribute(attributeName);656 if (value is null)657 {658 throw new AssertException($"Attribute not found. Attibute name: {attributeName}");659 }660 if (string.Compare(value, expectedAttributeValue) == 0)661 {662 throw new AssertException(@$"663HaveElementNotAttributeValue Assert Exception664Selector: {selector}665Expected attribute: {attributeName}666Not expected attribute value: {expectedAttributeValue}667Actual attribute value: {value}668Because: {because}669");670 }671 return page.Value;672 }673 public static IPage HaveElementComputedStyle(674 this ReferenceTypeAssertion<IPage> page,675 string selector,676 string styleName,677 string expectedStyleValue,678 string because = "no reason given",679 PageWaitForSelectorOptions? waitOptions = null,680 PageQuerySelectorOptions? queryOptions = null)681 {682 var element = GetElement(page.Value, selector, waitOptions, queryOptions);683 var value = element.Evaluate($"e => getComputedStyle(e).{styleName}", element).ToString();684 if (value == "")685 {686 throw new AssertException($"Style not found. Style name: {styleName}");687 }688 if (string.Compare(value, expectedStyleValue) != 0)689 {690 throw new AssertException($@"691HaveElementComputedStyle Assert Exception692Selector: {selector}693Style name: {styleName}...
PageModelAssertions.cs
Source:PageModelAssertions.cs
...81 this ReferenceTypeAssertion<TPageModel> pageModel,82 string selector,83 string expectedTextContent,84 string because = "no reason given",85 PageWaitForSelectorOptions? waitOptions = null,86 PageQuerySelectorOptions? queryOptions = null)87 where TPageModel : PageModel88 {89 pageModel.Value.Page.Should().HaveElementTextContent(selector, expectedTextContent, because, waitOptions, queryOptions);90 return pageModel.Value;91 }92 public static TPageModel HaveNotElementTextContent<TPageModel>(93 this ReferenceTypeAssertion<TPageModel> pageModel,94 string selector,95 string notExpectedTextContent,96 string because = "no reason given",97 PageWaitForSelectorOptions? waitOptions = null,98 PageQuerySelectorOptions? queryOptions = null)99 where TPageModel : PageModel100 {101 pageModel.Value.Page.Should().HaveNotElementTextContent(selector, notExpectedTextContent, because, waitOptions, queryOptions);102 return pageModel.Value;103 }104 public static TPageModel HaveElementInnerHTML<TPageModel>(105 this ReferenceTypeAssertion<TPageModel> pageModel,106 string selector,107 string expectedInnerHtml,108 string because = "no reason given",109 PageWaitForSelectorOptions? waitOptions = null,110 PageQuerySelectorOptions? options = null)111 where TPageModel : PageModel112 {113 pageModel.Value.Page.Should().HaveElementInnerHTML(selector, expectedInnerHtml, because, waitOptions, options);114 return pageModel.Value;115 }116 public static TPageModel HaveNotElementInnerHTML<TPageModel>(117 this ReferenceTypeAssertion<TPageModel> pageModel,118 string selector,119 string notExpectedInnerHtml,120 string because = "no reason given",121 PageWaitForSelectorOptions? waitOptions = null,122 PageQuerySelectorOptions? options = null)123 where TPageModel : PageModel124 {125 pageModel.Value.Page.Should().HaveNotElementInnerHTML(selector, notExpectedInnerHtml, because, waitOptions, options);126 return pageModel.Value;127 }128 public static TPageModel HaveElementInnerText<TPageModel>(129 this ReferenceTypeAssertion<TPageModel> pageModel,130 string selector,131 string expectedInnerText,132 string because = "no reason given",133 PageWaitForSelectorOptions? waitOptions = null,134 PageQuerySelectorOptions? options = null)135 where TPageModel : PageModel136 {137 pageModel.Value.Page.Should().HaveElementInnerText(selector, expectedInnerText, because, waitOptions, options);138 return pageModel.Value;139 }140 public static TPageModel HaveNotElementInnerText<TPageModel>(141 this ReferenceTypeAssertion<TPageModel> pageModel,142 string selector,143 string notExpectedInnerText,144 string because = "no reason given",145 PageWaitForSelectorOptions? waitOptions = null,146 PageQuerySelectorOptions? options = null)147 where TPageModel : PageModel148 {149 pageModel.Value.Page.Should().HaveNotElementInnerText(selector, notExpectedInnerText, because, waitOptions, options);150 return pageModel.Value;151 }152 public static TPageModel HaveElementInputValue<TPageModel>(153 this ReferenceTypeAssertion<TPageModel> pageModel,154 string selector,155 string expectedInputValue,156 string because = "no reason given",157 PageWaitForSelectorOptions? waitOptions = null,158 PageQuerySelectorOptions? options = null)159 where TPageModel : PageModel160 {161 pageModel.Value.Page.Should().HaveElementInputValue(selector, expectedInputValue, because, waitOptions, options);162 return pageModel.Value;163 }164 public static TPageModel HaveNotElementInputValue<TPageModel>(165 this ReferenceTypeAssertion<TPageModel> pageModel,166 string selector,167 string notExpectedInputValue,168 string because = "no reason given",169 PageWaitForSelectorOptions? waitOptions = null,170 PageQuerySelectorOptions? options = null)171 where TPageModel : PageModel172 {173 pageModel.Value.Page.Should().HaveNotElementInputValue(selector, notExpectedInputValue, because, waitOptions, options);174 return pageModel.Value;175 }176 public static TPageModel HaveCheckedElement<TPageModel>(177 this ReferenceTypeAssertion<TPageModel> pageModel,178 string selector,179 string because = "no reason given",180 PageWaitForSelectorOptions? waitOptions = null,181 PageQuerySelectorOptions? options = null)182 where TPageModel : PageModel183 {184 pageModel.Value.Page.Should().HaveCheckedElement(selector, because, waitOptions, options);185 return pageModel.Value;186 }187 public static TPageModel HaveNotCheckedElement<TPageModel>(188 this ReferenceTypeAssertion<TPageModel> pageModel,189 string selector,190 string because = "no reason given",191 PageWaitForSelectorOptions? waitOptions = null,192 PageQuerySelectorOptions? options = null)193 where TPageModel : PageModel194 {195 pageModel.Value.Page.Should().HaveNotCheckedElement(selector, because, waitOptions, options);196 return pageModel.Value;197 }198 public static TPageModel HaveDisabledElement<TPageModel>(199 this ReferenceTypeAssertion<TPageModel> pageModel,200 string selector,201 string because = "no reason given",202 PageWaitForSelectorOptions? waitOptions = null,203 PageQuerySelectorOptions? options = null)204 where TPageModel : PageModel205 {206 pageModel.Value.Page.Should().HaveDisabledElement(selector, because, waitOptions, options);207 return pageModel.Value;208 }209 public static TPageModel HaveNotDisabledElement<TPageModel>(210 this ReferenceTypeAssertion<TPageModel> pageModel,211 string selector,212 string because = "no reason given",213 PageWaitForSelectorOptions? waitOptions = null,214 PageQuerySelectorOptions? options = null)215 where TPageModel : PageModel216 {217 pageModel.Value.Page.Should().HaveNotDisabledElement(selector, because, waitOptions, options);218 return pageModel.Value;219 }220 public static TPageModel HaveEditableElement<TPageModel>(221 this ReferenceTypeAssertion<TPageModel> pageModel,222 string selector,223 string because = "no reason given",224 PageWaitForSelectorOptions? waitOptions = null,225 PageQuerySelectorOptions? options = null)226 where TPageModel : PageModel227 {228 pageModel.Value.Page.Should().HaveEditableElement(selector, because, waitOptions, options);229 return pageModel.Value;230 }231 public static TPageModel HaveNotEditableElement<TPageModel>(232 this ReferenceTypeAssertion<TPageModel> pageModel,233 string selector,234 string because = "no reason given",235 PageWaitForSelectorOptions? waitOptions = null,236 PageQuerySelectorOptions? options = null)237 where TPageModel : PageModel238 {239 pageModel.Value.Page.Should().HaveNotEditableElement(selector, because, waitOptions, options);240 return pageModel.Value;241 }242 public static TPageModel HaveEnabledElement<TPageModel>(243 this ReferenceTypeAssertion<TPageModel> pageModel,244 string selector,245 string because = "no reason given",246 PageWaitForSelectorOptions? waitOptions = null,247 PageQuerySelectorOptions? options = null)248 where TPageModel : PageModel249 {250 pageModel.Value.Page.Should().HaveEnabledElement(selector, because, waitOptions, options);251 return pageModel.Value;252 }253 public static TPageModel HaveNotEnabledElement<TPageModel>(254 this ReferenceTypeAssertion<TPageModel> pageModel,255 string selector,256 string because = "no reason given",257 PageWaitForSelectorOptions? waitOptions = null,258 PageQuerySelectorOptions? options = null)259 where TPageModel : PageModel260 {261 pageModel.Value.Page.Should().HaveNotEnabledElement(selector, because, waitOptions, options);262 return pageModel.Value;263 }264 public static TPageModel HaveHiddenElement<TPageModel>(265 this ReferenceTypeAssertion<TPageModel> pageModel,266 string selector,267 string because = "no reason given",268 PageWaitForSelectorOptions? waitOptions = null,269 PageQuerySelectorOptions? options = null)270 where TPageModel : PageModel271 {272 pageModel.Value.Page.Should().HaveHiddenElement(selector, because, waitOptions, options);273 return pageModel.Value;274 }275 public static TPageModel HaveNotHiddenElement<TPageModel>(276 this ReferenceTypeAssertion<TPageModel> pageModel,277 string selector,278 string because = "no reason given",279 PageWaitForSelectorOptions? waitOptions = null,280 PageQuerySelectorOptions? options = null)281 where TPageModel : PageModel282 {283 pageModel.Value.Page.Should().HaveNotHiddenElement(selector, because, waitOptions, options);284 return pageModel.Value;285 }286 public static TPageModel HaveVisibleElement<TPageModel>(287 this ReferenceTypeAssertion<TPageModel> pageModel,288 string selector,289 string because = "no reason given",290 PageWaitForSelectorOptions? waitOptions = null,291 PageQuerySelectorOptions? options = null)292 where TPageModel : PageModel293 {294 pageModel.Value.Page.Should().HaveVisibleElement(selector, because, waitOptions, options);295 return pageModel.Value;296 }297 public static TPageModel HaveNotVisibleElement<TPageModel>(298 this ReferenceTypeAssertion<TPageModel> pageModel,299 string selector,300 string because = "no reason given",301 PageWaitForSelectorOptions? waitOptions = null,302 PageQuerySelectorOptions? options = null)303 where TPageModel : PageModel304 {305 pageModel.Value.Page.Should().HaveNotVisibleElement(selector, because, waitOptions, options);306 return pageModel.Value;307 }308 public static TPageModel HaveElementAttribute<TPageModel>(309 this ReferenceTypeAssertion<TPageModel> pageModel,310 string selector,311 string attributeName,312 string because = "no reason given",313 PageWaitForSelectorOptions? waitOptions = null,314 PageQuerySelectorOptions? options = null)315 where TPageModel : PageModel316 {317 pageModel.Value.Page.Should().HaveElementAttribute(selector, attributeName, because, waitOptions, options);318 return pageModel.Value;319 }320 public static TPageModel HaveElementAttributeValue<TPageModel>(321 this ReferenceTypeAssertion<TPageModel> pageModel,322 string selector,323 string attributeName,324 string expectedValue,325 string because = "no reason given",326 PageWaitForSelectorOptions? waitOptions = null,327 PageQuerySelectorOptions? options = null)328 where TPageModel : PageModel329 {330 pageModel.Value.Page.Should().HaveElementAttributeValue(selector, attributeName, expectedValue, because, waitOptions, options);331 return pageModel.Value;332 }333 public static TPageModel HaveNotElementAttribute<TPageModel>(334 this ReferenceTypeAssertion<TPageModel> pageModel,335 string selector,336 string attributeName,337 string because = "no reason given",338 PageWaitForSelectorOptions? waitOptions = null,339 PageQuerySelectorOptions? options = null)340 where TPageModel : PageModel341 {342 pageModel.Value.Page.Should().HaveNotElementAttribute(selector, attributeName, because, waitOptions, options);343 return pageModel.Value;344 }345 public static TPageModel HaveComputedStyle<TPageModel>(346 this ReferenceTypeAssertion<TPageModel> pageModel,347 string selector,348 string styleName,349 string expectedStyleValue,350 string because = "no reason given",351 PageWaitForSelectorOptions? waitOptions = null,352 PageQuerySelectorOptions? options = null)353 where TPageModel : PageModel354 {355 pageModel.Value.Page.Should().HaveElementComputedStyle(selector, styleName, expectedStyleValue, because, waitOptions, options);356 return pageModel.Value;357 }358}...
PlaywrightTest.cs
Source:PlaywrightTest.cs
...48 await dialog.AcceptAsync();49 page.Dialog -= page_Dialog1_EventHandler;50 }51 page.Url.Should().Be(startingPageUrl);52 await page.WaitForSelectorAsync("#signInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Hidden });53 var signInForm = await page.QuerySelectorAsync("#signInModal");54 var signInFormAriaHidden = await signInForm.GetAttributeAsync("aria-hidden");55 signInFormAriaHidden.Should().Be("true");56 }57 [Test]58 public async Task SignUp_Failed()59 {60 //arrange61 string startingPageUrl = "https://www.demoblaze.com/index.html";62 string login = "andrew.telychyn";63 string password = "andrew.telychyn";64 //act 65 var page = await _browser.NewPageAsync();66 await page.GotoAsync(startingPageUrl);67 page.Dialog += page_Dialog1_EventHandler;68 await page.ClickAsync("#signin2");69 await page.FillAsync("#sign-username", login);70 await page.FillAsync("#sign-password", password);71 await page.ClickAsync("#signInModal > div > div > div.modal-footer > button.btn.btn-primary");72 //assert73 async void page_Dialog1_EventHandler(object sender, IDialog dialog)74 {75 dialog.Message.Should().Be("This user already exist.");76 await dialog.AcceptAsync();77 page.Dialog -= page_Dialog1_EventHandler;78 }79 page.Url.Should().Be(startingPageUrl);80 await page.WaitForSelectorAsync("#signInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible });81 var signInForm = await page.QuerySelectorAsync("#signInModal");82 var signInFormStyle = await signInForm.GetAttributeAsync("style");83 signInFormStyle.Should().Contain("display: block");84 }85 [Test]86 public async Task LogIn_Successful()87 {88 //arrange89 string startingPageUrl = "https://www.demoblaze.com/index.html";90 string login = "andrew.telychyn";91 string password = "andrew.telychyn";92 //act 93 var page = await _browser.NewPageAsync();94 await page.GotoAsync(startingPageUrl);95 await page.ClickAsync("#login2");96 await page.FillAsync("#loginusername", login);97 await page.FillAsync("#loginpassword", password);98 await page.ClickAsync("#logInModal > div > div > div.modal-footer > button.btn.btn-primary");99 await page.WaitForSelectorAsync("#nameofuser", new PageWaitForSelectorOptions() { State = WaitForSelectorState.Visible });100 //assert101 string username = await page.TextContentAsync("#nameofuser");102 username.Should().Contain(login);103 page.Url.Should().Be(startingPageUrl);104 await page.WaitForSelectorAsync("#logInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Hidden });105 var loginForm = await page.QuerySelectorAsync("#logInModal");106 var loginFormAriaHidden = await loginForm.GetAttributeAsync("aria-hidden");107 loginFormAriaHidden.Should().Be("true");108 }109 [Test]110 public async Task LogIn_Failed_UserDoesntExist()111 {112 //arrange113 string startingPageUrl = "https://www.demoblaze.com/index.html";114 string seed = Guid.NewGuid().ToString();115 string login = seed.Substring(0, 5);116 string password = seed.Substring(5, 5);117 //act 118 var page = await _browser.NewPageAsync();119 await page.GotoAsync(startingPageUrl);120 page.Dialog += page_Dialog1_EventHandler;121 await page.ClickAsync("#login2");122 await page.FillAsync("#loginusername", login);123 await page.FillAsync("#loginpassword", password);124 await page.ClickAsync("#logInModal > div > div > div.modal-footer > button.btn.btn-primary");125 //assert126 async void page_Dialog1_EventHandler(object sender, IDialog dialog)127 {128 dialog.Message.Should().Be("User does not exist.");129 await dialog.AcceptAsync();130 page.Dialog -= page_Dialog1_EventHandler;131 }132 page.Url.Should().Be(startingPageUrl);133 await page.WaitForSelectorAsync("#logInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible });134 var loginForm = await page.QuerySelectorAsync("#logInModal");135 var loginFormStyle = await loginForm.GetAttributeAsync("style");136 loginFormStyle.Should().Contain("display: block");137 }138 [Test]139 public async Task LogIn_Failed_WrongPassword()140 {141 //arrange142 string startingPageUrl = "https://www.demoblaze.com/index.html";143 string seed = Guid.NewGuid().ToString();144 string login = "andrew.telychyn";145 string password = seed.Substring(0, 5);146 //act 147 var page = await _browser.NewPageAsync();148 await page.GotoAsync(startingPageUrl);149 page.Dialog += page_Dialog1_EventHandler;150 await page.ClickAsync("#login2");151 await page.FillAsync("#loginusername", login);152 await page.FillAsync("#loginpassword", password);153 await page.ClickAsync("#logInModal > div > div > div.modal-footer > button.btn.btn-primary");154 //assert155 async void page_Dialog1_EventHandler(object sender, IDialog dialog)156 {157 dialog.Message.Should().Be("Wrong password.");158 await dialog.AcceptAsync();159 page.Dialog -= page_Dialog1_EventHandler;160 }161 page.Url.Should().Be(startingPageUrl);162 await page.WaitForSelectorAsync("#logInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible });163 var loginForm = await page.QuerySelectorAsync("#logInModal");164 var loginFormStyle = await loginForm.GetAttributeAsync("style");165 loginFormStyle.Should().Contain("display: block");166 }167 [Test]168 public async Task MakePurchase_Successful()169 {170 //arrange171 string startingPageUrl = "https://www.demoblaze.com/index.html";172 string cartUrl = "https://www.demoblaze.com/cart.html";173 string name = "Andrew Telychyn";174 string country = "Ukraine";175 string city = "Kyiv";176 string creditCard = "1234567890";...
DemoblazeTestsWithPlaywright.cs
Source:DemoblazeTestsWithPlaywright.cs
...48 await dialog.AcceptAsync();49 page.Dialog -= page_Dialog1_EventHandler;50 }51 page.Url.Should().Be(startingPageUrl);52 await page.WaitForSelectorAsync("#signInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Hidden });53 var signInForm = await page.QuerySelectorAsync("#signInModal");54 var signInFormAriaHidden = await signInForm.GetAttributeAsync("aria-hidden");55 signInFormAriaHidden.Should().Be("true");56 }57 [Test]58 public async Task SignUp_Failed()59 {60 //arrange61 string startingPageUrl = "https://www.demoblaze.com/index.html";62 string login = "vadym.mulish";63 string password = "vadym.mulish";64 //act 65 var page = await _browser.NewPageAsync();66 await page.GotoAsync(startingPageUrl);67 page.Dialog += page_Dialog1_EventHandler;68 await page.ClickAsync("#signin2");69 await page.FillAsync("#sign-username", login);70 await page.FillAsync("#sign-password", password);71 await page.ClickAsync("#signInModal > div > div > div.modal-footer > button.btn.btn-primary");72 //assert73 async void page_Dialog1_EventHandler(object sender, IDialog dialog)74 {75 dialog.Message.Should().Be("This user already exist.");76 await dialog.AcceptAsync();77 page.Dialog -= page_Dialog1_EventHandler;78 }79 page.Url.Should().Be(startingPageUrl);80 await page.WaitForSelectorAsync("#signInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible });81 var signInForm = await page.QuerySelectorAsync("#signInModal");82 var signInFormStyle = await signInForm.GetAttributeAsync("style");83 signInFormStyle.Should().Contain("display: block");84 }85 [Test]86 public async Task LogIn_Successful()87 {88 //arrange89 string startingPageUrl = "https://www.demoblaze.com/index.html";90 string login = "vadym.mulish";91 string password = "vadym.mulish";92 //act 93 var page = await _browser.NewPageAsync();94 await page.GotoAsync(startingPageUrl);95 await page.ClickAsync("#login2");96 await page.FillAsync("#loginusername", login);97 await page.FillAsync("#loginpassword", password);98 await page.ClickAsync("#logInModal > div > div > div.modal-footer > button.btn.btn-primary");99 await page.WaitForSelectorAsync("#nameofuser", new PageWaitForSelectorOptions() { State = WaitForSelectorState.Visible });100 //assert101 string username = await page.TextContentAsync("#nameofuser");102 username.Should().Contain(login);103 page.Url.Should().Be(startingPageUrl);104 await page.WaitForSelectorAsync("#logInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Hidden });105 var loginForm = await page.QuerySelectorAsync("#logInModal");106 var loginFormAriaHidden = await loginForm.GetAttributeAsync("aria-hidden");107 loginFormAriaHidden.Should().Be("true");108 }109 [Test]110 public async Task LogIn_Failed_UserDoesntExist()111 {112 //arrange113 string startingPageUrl = "https://www.demoblaze.com/index.html";114 string seed = Guid.NewGuid().ToString();115 string login = seed.Substring(0, 5);116 string password = seed.Substring(5, 5);117 //act 118 var page = await _browser.NewPageAsync();119 await page.GotoAsync(startingPageUrl);120 page.Dialog += page_Dialog1_EventHandler;121 await page.ClickAsync("#login2");122 await page.FillAsync("#loginusername", login);123 await page.FillAsync("#loginpassword", password);124 await page.ClickAsync("#logInModal > div > div > div.modal-footer > button.btn.btn-primary");125 //assert126 async void page_Dialog1_EventHandler(object sender, IDialog dialog)127 {128 dialog.Message.Should().Be("User does not exist.");129 await dialog.AcceptAsync();130 page.Dialog -= page_Dialog1_EventHandler;131 }132 page.Url.Should().Be(startingPageUrl);133 await page.WaitForSelectorAsync("#logInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible });134 var loginForm = await page.QuerySelectorAsync("#logInModal");135 var loginFormStyle = await loginForm.GetAttributeAsync("style");136 loginFormStyle.Should().Contain("display: block");137 }138 [Test]139 public async Task LogIn_Failed_WrongPassword()140 {141 //arrange142 string startingPageUrl = "https://www.demoblaze.com/index.html";143 string seed = Guid.NewGuid().ToString();144 string login = "vadym.mulish";145 string password = seed.Substring(0, 5);146 //act 147 var page = await _browser.NewPageAsync();148 await page.GotoAsync(startingPageUrl);149 page.Dialog += page_Dialog1_EventHandler;150 await page.ClickAsync("#login2");151 await page.FillAsync("#loginusername", login);152 await page.FillAsync("#loginpassword", password);153 await page.ClickAsync("#logInModal > div > div > div.modal-footer > button.btn.btn-primary");154 //assert155 async void page_Dialog1_EventHandler(object sender, IDialog dialog)156 {157 dialog.Message.Should().Be("Wrong password.");158 await dialog.AcceptAsync();159 page.Dialog -= page_Dialog1_EventHandler;160 }161 page.Url.Should().Be(startingPageUrl);162 await page.WaitForSelectorAsync("#logInModal", new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible });163 var loginForm = await page.QuerySelectorAsync("#logInModal");164 var loginFormStyle = await loginForm.GetAttributeAsync("style");165 loginFormStyle.Should().Contain("display: block");166 }167 [Test]168 public async Task MakePurchase_Successful()169 {170 //arrange171 string startingPageUrl = "https://www.demoblaze.com/index.html";172 string cartUrl = "https://www.demoblaze.com/cart.html";173 string name = "Vadym Mulish";174 string country = "Ukraine";175 string city = "Kyiv";176 string creditCard = "1234567890";...
Program.cs
Source:Program.cs
...29 await pwPage.Locator("[href='/dotnet/docs/trace-viewer']").ClickAsync();30 // Assert.AreEqual("https://playwright.dev/dotnet/docs/trace-viewer", page.Url);31 // Click img[alt="Playwright Trace Viewer"]32 await pwPage.WaitForSelectorAsync("img[alt=\"Playwright Trace Viewer\"]", 33 new PageWaitForSelectorOptions{34 State = WaitForSelectorState.Visible35 });36 await pwContext.Tracing.StopAsync(new TracingStopOptions37 {38 Path = "trace.zip"39 });40 await pwContext.CloseAsync();41 await browser.CloseAsync();42 }43}...
HomePageObject.cs
Source:HomePageObject.cs
...17 public IPage Page { get; set; }18 public IBrowser Browser { get; set; }19 public async Task NavigateToGreeting()20 {21 await Page.WaitForSelectorAsync(HelloLinkSelector, new PageWaitForSelectorOptions22 {23 State = WaitForSelectorState.Attached24 });25 await Page.ClickAsync(HelloLinkSelector);26 }27 public async Task<string> GetGreetingMessage()28 {29 await Page.WaitForSelectorAsync(GreetingSelector, new PageWaitForSelectorOptions30 {31 State = WaitForSelectorState.Attached32 });33 return await Page.InnerHTMLAsync(GreetingSelector);34 }35 }36 public interface IHomePageObject : IPageObject37 {38 public Task NavigateToGreeting();39 public Task<string> GetGreetingMessage();40 }41}...
Scenario01.cs
Source:Scenario01.cs
...11 [Test]12 public async Task CanWaitForAnElementToAppear()13 {14 await AppHelpers.VisitURL(Page);15 await Page.WaitForSelectorAsync("#elementappearschild", new PageWaitForSelectorOptions{ State = WaitForSelectorState.Visible, Timeout = 5000 });16 }1718 [Test]19 public async Task AutomaticallyWaitsForElementsThatAppearAfterOnLoad()20 {21 await AppHelpers.VisitURL(Page);22 string text = await Page.TextContentAsync("#loadedchild");23 Assert.AreEqual("Loaded!", text);24 }25 }26}
...
Scenario03.cs
Source:Scenario03.cs
...13 {14 Page.Dialog += (_, dialog) => dialog.AcceptAsync();15 await AppHelpers.VisitURL(Page, "/leave");16 await Page.ClickAsync("#homelink");17 await Page.WaitForSelectorAsync("#elementappearsparent", new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible, Timeout = 5000 });18 }19 }20}
...
PageWaitForSelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 static async Task Main(string[] args)5 {6 using var playwright = await Playwright.CreateAsync();7 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions8 {9 });10 var page = await browser.NewPageAsync();11 var element = await page.WaitForSelectorAsync("input[name=q]", new PageWaitForSelectorOptions12 {13 });14 }15}
PageWaitForSelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 static async Task Main()5 {6 using IPlaywright playwright = await Playwright.CreateAsync();7 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions8 {9 });10 var context = await browser.NewContextAsync();11 var page = await context.NewPageAsync();12 await page.ClickAsync("text=Sign in");13 var elementHandle = await page.WaitForSelectorAsync("input[name='password']", new PageWaitForSelectorOptions { State = WaitForSelectorState.Attached });14 }15}
PageWaitForSelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 static async Task Main()5 {6 using IPlaywright playwright = await Playwright.CreateAsync();7 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions8 {9 });10 var context = await browser.NewContextAsync();11 var page = await context.NewPageAsync();12 await page.ClickAsync("text=Sign in");13 var elementHandle = await page.WaitForSelectorAsync("input[name='password']", new PageWaitForSelectorOptions { State = WaitForSelectorState.Attached });14 }15}
PageWaitForSelectorOptions
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using Microsoft.Playwright;4{5 {6 static async Task Main(string[] args)7 {8 await using var playwright = await Playwright.CreateAsync();9 await using var browser = await playwright.Chromium.LaunchAsync();10 var page = await browser.NewPageAsync();11 await page.TypeAsync("input[name=q]", "Playwright");12 await page.ClickAsync("input[value='Google Search']");13 {14 };15 await element.ClickAsync();16 await page.ScreenshotAsync("screenshot.png");17 }18 }19}20using System;21using System.Threading.Tasks;22using Microsoft.Playwright;23{24 {25 static async Task Main(string[] args)26 {27 await using var playwright = await Playwright.CreateAsync();28 await using var browser = await playwright.Chromium.LaunchAsync();29 var page = await browser.NewPageAsync();30 await page.TypeAsync("input[name=q]", "Playwright");31 await page.ClickAsync("input[value='Google Search']");32 {33 };34 await element.ClickAsync();35 await page.ScreenshotAsync("screenshot.png");36 }37 }38}
PageWaitForSelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System;3using System.Threading.Tasks;4{5 {6 static async Task Main(string[] args)7 {8 await using var playwright = await Playwright.CreateAsync();9 await using var browser = await playwright.Chromium.LaunchAsync();10 var page = await browser.NewPageAsync();11 {12 };13 await page.WaitForSelectorAsync("#searchInput", options);14 }15 }16}17public Task WaitForTimeoutAsync(int milliseconds)18using Microsoft.Playwright;19using System;20using System.Threading.Tasks;21{22 {23 static async Task Main(string[] args)24 {25 await using var playwright = await Playwright.CreateAsync();26 await using var browser = await playwright.Chromium.LaunchAsync();27 var page = await browser.NewPageAsync();28 await page.WaitForTimeoutAsync(2000);29 }30 }31}32public Task WaitForFunctionAsync(string pageFunction, object arg = null, WaitForFunctionOptions options = null)
PageWaitForSelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 {5 static async Task Main(string[] args)6 {7 using var playwright = await Playwright.CreateAsync();8 await using var browser = await playwright.Chromium.LaunchAsync();9 var page = await browser.NewPageAsync();10 var result = await page.WaitForSelectorAsync("input[name='q']", new PageWaitForSelectorOptions11 {12 });13 }14 }15}
PageWaitForSelectorOptions
Using AI Code Generation
1var options = new PageWaitForSelectorOptions();2options.State = WaitForSelectorState.Attached;3await page.WaitForSelectorAsync("css=div", options);4var options = new PageWaitForSelectorOptions();5options.State = WaitForSelectorState.Visible;6await page.WaitForSelectorAsync("css=div", options);7var options = new PageWaitForSelectorOptions();8options.State = WaitForSelectorState.Hidden;9await page.WaitForSelectorAsync("css=div", options);10var options = new PageWaitForSelectorOptions();11options.State = WaitForSelectorState.Detached;12await page.WaitForSelectorAsync("css=div", options);13var options = new PageWaitForSelectorOptions();14options.State = WaitForSelectorState.Attached;15await page.WaitForSelectorAsync("css=div", options);16var options = new PageWaitForSelectorOptions();17options.State = WaitForSelectorState.Visible;
PageWaitForSelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System;3using System.Threading.Tasks;4{5 {6 static async Task Main(string[] args)7 {8 using var playwright = await Playwright.CreateAsync();9 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions10 {11 });12 var context = await browser.NewContextAsync();13 var page = await context.NewPageAsync();14 await page.FillAsync("input[title='Search']", "Playwright");15 await page.ClickAsync("input[type='submit']");16 var element = await page.WaitForSelectorAsync("div#result-stats", new PageWaitForSelectorOptions { Timeout = 10000 });17 Console.WriteLine("Element found");18 }19 }20}21await page.WaitForSelectorAsync("css=div", options);22var options = new PageWaitForSelectorOptions();23options.State = WaitForSelectorState.Hidden;24await page.WaitForSelectorAsync("css=div", options);25var options = new PageWaitForSelectorOptions();26options.State = WaitForSelectorState.Detached;27await page.WaitForSelectorAsync("css=div", options);28var options = new PageWaitForSelectorOptions();29options.State = WaitForSelectorState.Attached;30await page.WaitForSelectorAsync("css=div
PageWaitForSelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 {5 static async Task Main(string[] args)6 {7 using var playwright = await Playwright.CreateAsync();8 await using var browser = await playwright.Chromium.LaunchAsync();9 var page = await browser.NewPageAsync();10 var result = await page.WaitForSelectorAsync("input[name='q']", new PageWaitForSelectorOptions11 {12 });13 }14 }15}
PageWaitForSelectorOptions
Using AI Code Generation
1var options = new PageWaitForSelectorOptions();2options.State = WaitForSelectorState.Attached;3await page.WaitForSelectorAsync("css=div", options);4var options = new PageWaitForSelectorOptions();5options.State = WaitForSelectorState.Visible;6await page.WaitForSelectorAsync("css=div", options);7var options = new PageWaitForSelectorOptions();8options.State = WaitForSelectorState.Hidden;9await page.WaitForSelectorAsync("css=div", options);10var options = new PageWaitForSelectorOptions();11options.State = WaitForSelectorState.Detached;12await page.WaitForSelectorAsync("css=div", options);13var options = new PageWaitForSelectorOptions();14options.State = WaitForSelectorState.Attached;15await page.WaitForSelectorAsync("css=div", options);16var options = new PageWaitForSelectorOptions();17options.State = WaitForSelectorState.Visible;18await page.WaitForSelectorAsync("css=div", options);19var options = new PageWaitForSelectorOptions();20options.State = WaitForSelectorState.Hidden;21await page.WaitForSelectorAsync("css=div", options);22var options = new PageWaitForSelectorOptions();23options.State = WaitForSelectorState.Detached;24await page.WaitForSelectorAsync("css=div", options);25var options = new PageWaitForSelectorOptions();26options.State = WaitForSelectorState.Attached;27await page.WaitForSelectorAsync("css=div
PageWaitForSelectorOptions
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using Microsoft.Playwright;4{5 {6 static async Task Main(string[] args)7 {8 using var playwright = await Playwright.CreateAsync();9 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions10 {11 });12 var context = await browser.NewContextAsync();13 var page = await context.NewPageAsync();14 await page.TypeAsync("input[title='Search']", "Hello World");15 await page.ClickAsync("input[value='Google Search']");16 {17 };18 await page.WaitForSelectorAsync("a[title='Next page']", options);19 Console.WriteLine("Next page button is visible");20 await browser.CloseAsync();21 }22 }23}
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!