├── .DS_Store ├── .gitignore ├── .idea └── .idea.PlaywrightDotnet │ └── .idea │ ├── .gitignore │ ├── .name │ ├── encodings.xml │ ├── indexLayout.xml │ └── vcs.xml ├── PlaywrightAPITesting ├── Driver │ └── PlaywrightDriver.cs ├── PlaywrightAPITesting.csproj ├── UnitTest1.cs └── Usings.cs ├── PlaywrightDemo ├── .DS_Store ├── .idea │ └── .idea.PlaywrightDemo.dir │ │ └── .idea │ │ ├── .gitignore │ │ ├── encodings.xml │ │ ├── indexLayout.xml │ │ └── vcs.xml ├── GlobalUsings.cs ├── NUnitPlaywright.cs ├── Pages │ ├── LoginPage.cs │ └── LoginPageUpgraded.cs ├── PlaywrightBasics.cs ├── PlaywrightDemo.csproj ├── PlaywrightLocator.cs └── architecture.drawio ├── PlaywrightDotnet.sln ├── PlaywrightNUnitDemo ├── PlaywrightNUnitDemo.csproj ├── UnitTest1.cs ├── UnitTest2.cs ├── Usings.cs └── playwrightconfig.runsettings ├── PlaywrightSpecflow ├── SpecFlowProject1.sln └── SpecFlowProject1 │ ├── Drivers │ └── Driver.cs │ ├── Features │ ├── EALogin.feature │ ├── EALogin.feature.cs │ ├── EALogin2.feature │ └── EALogin2.feature.cs │ ├── Hooks │ └── Hook.cs │ ├── Pages │ └── LoginPage.cs │ ├── SpecFlowProject1.csproj │ └── Steps │ └── EALoginSteps.cs └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/executeautomation/Playwrightdotnet/e098bf7da0d0a282126a5e6176a95b2f3c36c886/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /.idea/.idea.PlaywrightDotnet/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /modules.xml 6 | /contentModel.xml 7 | /projectSettingsUpdater.xml 8 | /.idea.PlaywrightDotnet.iml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | -------------------------------------------------------------------------------- /.idea/.idea.PlaywrightDotnet/.idea/.name: -------------------------------------------------------------------------------- 1 | PlaywrightDotnet -------------------------------------------------------------------------------- /.idea/.idea.PlaywrightDotnet/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/.idea.PlaywrightDotnet/.idea/indexLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | . 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/.idea.PlaywrightDotnet/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PlaywrightAPITesting/Driver/PlaywrightDriver.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Playwright; 2 | 3 | namespace PlaywrightAPITesting.Driver; 4 | 5 | public class PlaywrightDriver : IDisposable 6 | { 7 | private readonly Task? _requestContext; 8 | 9 | public PlaywrightDriver() 10 | { 11 | _requestContext = CreateApiContext(); 12 | } 13 | 14 | public IAPIRequestContext? ApiRequestContext => _requestContext?.GetAwaiter().GetResult(); 15 | 16 | public void Dispose() 17 | { 18 | _requestContext?.Dispose(); 19 | } 20 | 21 | 22 | private async Task CreateApiContext() 23 | { 24 | var playwright = await Playwright.CreateAsync(); 25 | 26 | return await playwright.APIRequest.NewContextAsync(new APIRequestNewContextOptions 27 | { 28 | BaseURL = "https://localhost:5001/", 29 | IgnoreHTTPSErrors = true 30 | }); 31 | } 32 | } -------------------------------------------------------------------------------- /PlaywrightAPITesting/PlaywrightAPITesting.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | all 19 | 20 | 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | all 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /PlaywrightAPITesting/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using FluentAssertions; 3 | using Microsoft.Playwright; 4 | using PlaywrightAPITesting.Driver; 5 | using Xunit.Abstractions; 6 | namespace PlaywrightAPITesting; 7 | 8 | public class UnitTest1 : IClassFixture 9 | { 10 | private readonly PlaywrightDriver _playwrightDriver; 11 | private readonly ITestOutputHelper _testOutputHelper; 12 | 13 | 14 | public UnitTest1(PlaywrightDriver playwrightDriver, ITestOutputHelper testOutputHelper) 15 | { 16 | _playwrightDriver = playwrightDriver; 17 | _testOutputHelper = testOutputHelper; 18 | } 19 | 20 | [Fact] 21 | public async Task AuthenticateTest() 22 | { 23 | var response = await _playwrightDriver.ApiRequestContext?.PostAsync("api/Authenticate/Login", 24 | new APIRequestContextOptions 25 | { 26 | DataObject = new 27 | { 28 | UserName = "KK", 29 | Password = "123456" 30 | } 31 | })!; 32 | 33 | 34 | var jsonString = await response.JsonAsync(); 35 | 36 | // var token = jsonString?.GetProperty("token").ToString(); 37 | 38 | var authencationResponse = jsonString?.Deserialize(new JsonSerializerOptions 39 | { 40 | PropertyNameCaseInsensitive = true 41 | }); 42 | 43 | _testOutputHelper.WriteLine(jsonString.ToString()); 44 | 45 | 46 | authencationResponse?.Token.Should().NotBeNull(); 47 | authencationResponse?.Token.Should().NotBe(string.Empty); 48 | } 49 | 50 | 51 | [Fact] 52 | public async Task GetProduct() 53 | { 54 | var token = await GetToken(); 55 | 56 | var response = await _playwrightDriver.ApiRequestContext?.GetAsync("Product/GetProductById/1", 57 | new APIRequestContextOptions 58 | { 59 | Headers = new Dictionary 60 | { 61 | { "Authorization", $"Bearer {token}" } 62 | } 63 | })!; 64 | 65 | var data = await response.JsonAsync(); 66 | 67 | _testOutputHelper.WriteLine(data.ToString()); 68 | 69 | //Reference wont works, since product type needs RestSharp course source code 70 | // var product = data?.Deserialize(new JsonSerializerOptions 71 | // { 72 | // PropertyNameCaseInsensitive = true 73 | // }); 74 | // 75 | // 76 | // using (new AssertionScope()) 77 | // { 78 | // response.Status.Should().Be(201); 79 | // product?.Name.Should().Be("Keyboards"); 80 | // product?.ProductId.Should().Be(2); 81 | // } 82 | } 83 | 84 | private async Task GetToken() 85 | { 86 | var response = await _playwrightDriver.ApiRequestContext?.PostAsync("api/Authenticate/Login", 87 | new APIRequestContextOptions 88 | { 89 | DataObject = new 90 | { 91 | UserName = "KK", 92 | Password = "123456" 93 | } 94 | })!; 95 | 96 | var jsonString = await response.JsonAsync(); 97 | 98 | return jsonString?.Deserialize(new JsonSerializerOptions 99 | { 100 | PropertyNameCaseInsensitive = true 101 | })?.Token; 102 | } 103 | 104 | 105 | private record Authenticate(string Token) 106 | { 107 | } 108 | } -------------------------------------------------------------------------------- /PlaywrightAPITesting/Usings.cs: -------------------------------------------------------------------------------- 1 | global using Xunit; -------------------------------------------------------------------------------- /PlaywrightDemo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/executeautomation/Playwrightdotnet/e098bf7da0d0a282126a5e6176a95b2f3c36c886/PlaywrightDemo/.DS_Store -------------------------------------------------------------------------------- /PlaywrightDemo/.idea/.idea.PlaywrightDemo.dir/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /contentModel.xml 6 | /.idea.PlaywrightDemo.iml 7 | /projectSettingsUpdater.xml 8 | /modules.xml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | -------------------------------------------------------------------------------- /PlaywrightDemo/.idea/.idea.PlaywrightDemo.dir/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /PlaywrightDemo/.idea/.idea.PlaywrightDemo.dir/.idea/indexLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PlaywrightDemo/.idea/.idea.PlaywrightDemo.dir/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PlaywrightDemo/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | // Global using directives 2 | 3 | global using System; 4 | global using System.Threading.Tasks; 5 | global using System.Web; 6 | global using Microsoft.Playwright.NUnit; 7 | global using PlaywrightDemo.Pages; 8 | global using FluentAssertions; 9 | global using Microsoft.Playwright; 10 | global using NUnit.Framework; -------------------------------------------------------------------------------- /PlaywrightDemo/NUnitPlaywright.cs: -------------------------------------------------------------------------------- 1 | namespace PlaywrightDemo; 2 | 3 | public class NUnitPlaywright : PageTest 4 | { 5 | [SetUp] 6 | public async Task Setup() 7 | { 8 | await Page.GotoAsync("http://www.eaapp.somee.com"); 9 | } 10 | 11 | [Test] 12 | public async Task Test1() 13 | { 14 | //Using Locators 15 | var lnkLogin = Page.Locator("text=Login"); 16 | await lnkLogin.ClickAsync(); 17 | await Page.ClickAsync("text=Login"); 18 | await Page.FillAsync("#UserName", "admin"); 19 | await Page.FillAsync("#Password", "password"); 20 | //Using Locator with Page Locator Options 21 | var btnLogin = Page.Locator("input", new PageLocatorOptions { HasTextString = "Log in" }); 22 | await btnLogin.ClickAsync(); 23 | //await Page.ClickAsync("text=Log in"); 24 | await Expect(Page.Locator("text='Employee Details'")).ToBeVisibleAsync(); 25 | } 26 | } -------------------------------------------------------------------------------- /PlaywrightDemo/Pages/LoginPage.cs: -------------------------------------------------------------------------------- 1 | namespace PlaywrightDemo.Pages; 2 | 3 | public class LoginPage 4 | { 5 | private readonly ILocator _btnLogin; 6 | private readonly ILocator _lnkEmployeeDetails; 7 | private readonly ILocator _lnkLogin; 8 | 9 | private readonly IPage _page; 10 | private readonly ILocator _txtPassword; 11 | private readonly ILocator _txtUserName; 12 | 13 | public LoginPage(IPage page) 14 | { 15 | _page = page; 16 | _lnkLogin = _page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Login" }); 17 | _txtUserName = _page.GetByLabel("UserName"); 18 | _txtPassword = _page.GetByLabel("Password"); 19 | _btnLogin = _page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Log in" }); 20 | _lnkEmployeeDetails = _page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Employee List" }); 21 | } 22 | 23 | public async Task ClickLogin() 24 | { 25 | await _lnkLogin.ClickAsync(); 26 | } 27 | 28 | public async Task Login(string userName, string password) 29 | { 30 | await _txtUserName.FillAsync(userName); 31 | await _txtPassword.FillAsync(password); 32 | await _btnLogin.ClickAsync(); 33 | } 34 | 35 | public async Task IsEmployeeDetailsExists() 36 | { 37 | return await _lnkEmployeeDetails.IsVisibleAsync(); 38 | } 39 | } -------------------------------------------------------------------------------- /PlaywrightDemo/Pages/LoginPageUpgraded.cs: -------------------------------------------------------------------------------- 1 | namespace PlaywrightDemo.Pages; 2 | 3 | public class LoginPageUpgraded 4 | { 5 | private readonly IPage _page; 6 | 7 | public LoginPageUpgraded(IPage page) 8 | { 9 | _page = page; 10 | } 11 | 12 | private ILocator _lnkLogin => _page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Login" }); 13 | private ILocator _txtUserName => _page.GetByLabel("UserName"); 14 | private ILocator _txtPassword => _page.GetByLabel("Password"); 15 | private ILocator _btnLogin => _page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Log in" }); 16 | 17 | private ILocator _lnkEmployeeDetails => 18 | _page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Employee List" }); 19 | 20 | private ILocator _lnkEmployeeLists => _page.Locator("text='Employee List'"); 21 | 22 | 23 | public async Task ClickLogin() 24 | { 25 | await _page.RunAndWaitForNavigationAsync(async () => { await _lnkLogin.ClickAsync(); }, 26 | new PageRunAndWaitForNavigationOptions 27 | { 28 | UrlString = "**/Login" 29 | }); 30 | } 31 | 32 | public async Task ClickEmployeeList() 33 | { 34 | await _lnkEmployeeLists.ClickAsync(); 35 | } 36 | 37 | public async Task Login(string userName, string password) 38 | { 39 | await _txtUserName.FillAsync(userName); 40 | await _txtPassword.FillAsync(password); 41 | await _btnLogin.ClickAsync(); 42 | } 43 | 44 | public async Task IsEmployeeDetailsExists() 45 | { 46 | return await _lnkEmployeeDetails.IsVisibleAsync(); 47 | } 48 | } -------------------------------------------------------------------------------- /PlaywrightDemo/PlaywrightBasics.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Reflection; 3 | 4 | namespace PlaywrightDemo; 5 | 6 | public class Tests 7 | { 8 | [SetUp] 9 | public void Setup() 10 | { 11 | } 12 | 13 | [Test] 14 | public async Task Test1() 15 | { 16 | //Playwright 17 | using var playwright = await Playwright.CreateAsync(); 18 | //Browser 19 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 20 | { 21 | Headless = false 22 | }); 23 | //Page 24 | var page = await browser.NewPageAsync(); 25 | await page.GotoAsync("http://www.eaapp.somee.com"); 26 | await page.ClickAsync("text=Login"); 27 | await page.ScreenshotAsync(new PageScreenshotOptions 28 | { 29 | Path = "EAApp.jpg" 30 | }); 31 | await page.FillAsync("#UserName", "admin"); 32 | await page.FillAsync("#Password", "password"); 33 | await page.ClickAsync("text=Log in"); 34 | var isExist = await page.Locator("text='Employee Details'").IsVisibleAsync(); 35 | Assert.IsTrue(isExist); 36 | } 37 | 38 | [Test] 39 | public async Task TestWithPOM() 40 | { 41 | //Playwright 42 | using var playwright = await Playwright.CreateAsync(); 43 | //Browser 44 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 45 | { 46 | Headless = false 47 | }); 48 | //Page 49 | var page = await browser.NewPageAsync(); 50 | await page.GotoAsync("http://www.eaapp.somee.com"); 51 | 52 | var loginPage = new LoginPageUpgraded(page); 53 | await loginPage.ClickLogin(); 54 | await loginPage.Login("admin", "password"); 55 | var isExist = await loginPage.IsEmployeeDetailsExists(); 56 | Assert.IsTrue(isExist); 57 | } 58 | 59 | 60 | [Test] 61 | public async Task WaitTest() 62 | { 63 | using var playwright = await Playwright.CreateAsync(); 64 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 65 | { 66 | Headless = false 67 | }); 68 | var context = await browser.NewContextAsync(); 69 | var page = await context.NewPageAsync(); 70 | await page.GotoAsync("https://demos.telerik.com/kendo-ui/window/angular"); 71 | await page.Locator( 72 | "text=Calendar May 2022SuMoTuWeThFrSa1234567891011121314151617181920212223242526272829 >> [aria-label=\"Close\"]") 73 | .ClickAsync(); 74 | await page.Locator( 75 | "text=Calendar May 2022SuMoTuWeThFrSa1234567891011121314151617181920212223242526272829 >> [aria-label=\"Close\"]") 76 | .ClickAsync(); 77 | // Click button:has-text("Open AJAX content") 78 | await page.Locator("button:has-text(\"Open AJAX content\")").ClickAsync(); 79 | } 80 | 81 | [Test] 82 | public async Task TestNetwork() 83 | { 84 | //Playwright 85 | using var playwright = await Playwright.CreateAsync(); 86 | //Browser 87 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 88 | { 89 | Headless = false 90 | }); 91 | //Page 92 | var page = await browser.NewPageAsync(); 93 | await page.GotoAsync("http://www.eaapp.somee.com"); 94 | 95 | var loginPage = new LoginPageUpgraded(page); 96 | await loginPage.ClickLogin(); 97 | await loginPage.Login("admin", "password"); 98 | 99 | //Wait for response - Way 1 100 | var waitResponse = page.WaitForResponseAsync("**/Employee"); 101 | //while the button is clicked 102 | await loginPage.ClickEmployeeList(); 103 | //give the response details 104 | var getResponse = await waitResponse; 105 | 106 | //Way 2 - Wait for response 107 | var response = await page.RunAndWaitForResponseAsync(async () => { await loginPage.ClickEmployeeList(); }, 108 | x => x.Url.Contains("/Employee") && x.Status == 200); 109 | 110 | var isExist = await loginPage.IsEmployeeDetailsExists(); 111 | Assert.IsTrue(isExist); 112 | } 113 | 114 | [Test] 115 | public async Task Flipkart() 116 | { 117 | using var playwright = await Playwright.CreateAsync(); 118 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 119 | { 120 | Headless = false 121 | }); 122 | var context = await browser.NewContextAsync(); 123 | var page = await context.NewPageAsync(); 124 | await page.GotoAsync("https://www.flipkart.com/", new PageGotoOptions 125 | { 126 | WaitUntil = WaitUntilState.NetworkIdle 127 | }); 128 | await page.Locator("text=✕").ClickAsync(); 129 | 130 | await page.Locator("a", new PageLocatorOptions 131 | { 132 | HasTextString = "Login" 133 | }).ClickAsync(); 134 | 135 | var request = await page.RunAndWaitForRequestAsync(async () => { await page.Locator("text=✕").ClickAsync(); }, 136 | x => x.Url.Contains("flipkart.d1.sc.omtrdc.net") && x.Method == "GET"); 137 | 138 | var returnData = HttpUtility.UrlDecode(request.Url); 139 | 140 | returnData.Should().Contain("Account Login:Displayed Exit"); 141 | } 142 | 143 | [Test] 144 | public async Task? FlipkartNetworkInterception() 145 | { 146 | using var playwright = await Playwright.CreateAsync(); 147 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 148 | { 149 | Headless = false 150 | }); 151 | var context = await browser.NewContextAsync(); 152 | var page = await context.NewPageAsync(); 153 | 154 | page.Request += (_, request) => Console.WriteLine(request.Method + "---" + request.Url); 155 | page.Response += (_, response) => Console.WriteLine(response.Status + "---" + response.Url); 156 | 157 | await page.RouteAsync("**/*", async route => 158 | { 159 | if (route.Request.ResourceType == "image") 160 | await route.AbortAsync(); 161 | else 162 | await route.ContinueAsync(); 163 | }); 164 | 165 | await page.GotoAsync("https://www.flipkart.com/", new PageGotoOptions 166 | { 167 | WaitUntil = WaitUntilState.NetworkIdle 168 | }); 169 | } 170 | 171 | 172 | [Test] 173 | public async Task TestForHar() 174 | { 175 | //Playwright 176 | using var playwright = await Playwright.CreateAsync(); 177 | //Browser 178 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 179 | { 180 | Headless = false 181 | }); 182 | 183 | //Page 184 | var page = await browser.NewPageAsync(new BrowserNewPageOptions 185 | { 186 | RecordHarPath = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}/eapp.har" 187 | //RecordHarUrlFilter = "**/Product/**" 188 | }); 189 | 190 | 191 | await page.RouteFromHARAsync($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}/eapp.har", 192 | new PageRouteFromHAROptions 193 | { 194 | Url = "**/Product/List", 195 | Update = false 196 | }); 197 | 198 | await page.GotoAsync("http://localhost:5001/"); 199 | 200 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Product" }).ClickAsync(); 201 | 202 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Create" }).ClickAsync(); 203 | 204 | await page.GetByLabel("Name").ClickAsync(); 205 | 206 | await page.GetByLabel("Name").FillAsync("karthik"); 207 | 208 | await page.GetByLabel("Name").PressAsync("Tab"); 209 | 210 | await page.GetByLabel("Description").FillAsync("12"); 211 | 212 | await page.GetByLabel("Description").PressAsync("Tab"); 213 | 214 | await page.Locator("#Price").FillAsync("100"); 215 | 216 | await page.Locator("#Price").PressAsync("Tab"); 217 | 218 | await page.GetByLabel("ProductType").SelectOptionAsync(new[] { "1" }); 219 | 220 | await page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Create" }).ClickAsync(); 221 | 222 | await Task.Delay(1000); 223 | 224 | await page.CloseAsync(); 225 | } 226 | } -------------------------------------------------------------------------------- /PlaywrightDemo/PlaywrightDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /PlaywrightDemo/PlaywrightLocator.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Reflection; 3 | 4 | namespace PlaywrightDemo; 5 | 6 | public class PlaywrightLocator 7 | { 8 | [Test] 9 | public async Task LocatorTestsInPlaywright() 10 | { 11 | using var playwright = await Playwright.CreateAsync(); 12 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 13 | { 14 | Headless = false 15 | }); 16 | var context = await browser.NewContextAsync(); 17 | 18 | var page = await context.NewPageAsync(); 19 | 20 | await page.GotoAsync("http://eaapp.somee.com/"); 21 | 22 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Login" }).ClickAsync(); 23 | 24 | await page.GetByLabel("UserName").ClickAsync(); 25 | 26 | await page.GetByLabel("UserName").FillAsync("admin"); 27 | 28 | await page.GetByLabel("UserName").PressAsync("Tab"); 29 | 30 | await page.GetByLabel("Password").FillAsync("password"); 31 | 32 | await page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Log in" }).ClickAsync(); 33 | 34 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Employee List" }).ClickAsync(); 35 | 36 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Create New" }).ClickAsync(); 37 | 38 | await page.GetByLabel("Name").ClickAsync(); 39 | 40 | await page.GetByLabel("Name").FillAsync("Adam"); 41 | 42 | await page.GetByLabel("Name").PressAsync("Tab"); 43 | 44 | await page.GetByLabel("Salary").FillAsync("10000"); 45 | 46 | await page.GetByLabel("Salary").PressAsync("Tab"); 47 | 48 | await page.GetByLabel("DurationWorked").FillAsync("1"); 49 | 50 | await page.GetByLabel("DurationWorked").PressAsync("Tab"); 51 | 52 | await page.GetByLabel("Grade").FillAsync("1"); 53 | 54 | await page.GetByLabel("Grade").PressAsync("Tab"); 55 | 56 | await page.GetByLabel("Email").FillAsync("adam@adam.com"); 57 | 58 | await page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Create" }).ClickAsync(); 59 | 60 | await page 61 | .GetByRole(AriaRole.Row, new PageGetByRoleOptions { Name = "Adam" }) 62 | .GetByRole(AriaRole.Link, new LocatorGetByRoleOptions { Name = "Delete" }).ClickAsync(); 63 | 64 | await page.ScreenshotAsync(new PageScreenshotOptions 65 | { 66 | Path = "screenshot.png", 67 | FullPage = true 68 | }); 69 | } 70 | 71 | [Test] 72 | public async Task LocatorTestForEA() 73 | { 74 | using var playwright = await Playwright.CreateAsync(); 75 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 76 | { 77 | Headless = false 78 | }); 79 | var context = await browser.NewContextAsync(); 80 | 81 | //Page 82 | var page = await browser.NewPageAsync(new BrowserNewPageOptions 83 | { 84 | RecordHarPath = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}/eapp.har", 85 | RecordHarUrlFilterString = "**/Product/List" 86 | }); 87 | 88 | 89 | await page.RouteFromHARAsync($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}/eapp.har", 90 | new PageRouteFromHAROptions 91 | { 92 | Url = "**/Product/List", 93 | Update = true 94 | }); 95 | 96 | await page.GotoAsync("https://executeautomation.com/"); 97 | 98 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Sign In" }).ClickAsync(); 99 | 100 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Sign Up" }).ClickAsync(); 101 | 102 | await page.GetByPlaceholder("First Name").FillAsync("DemoUser1"); 103 | 104 | await page.GetByPlaceholder("Last Name").FillAsync("KK"); 105 | 106 | await page.Locator("#react-select-2-input").FillAsync("New"); 107 | 108 | await page.GetByText("New Zealand", new PageGetByTextOptions { Exact = true }).ClickAsync(); 109 | 110 | await page.GetByPlaceholder("Email Address").FillAsync("demouser1@demo1.com"); 111 | 112 | await page.GetByPlaceholder("Password", new PageGetByPlaceholderOptions { Exact = true }).FillAsync("password"); 113 | 114 | await page.GetByPlaceholder("Enter Password Again").FillAsync("password"); 115 | 116 | await page.GetByPlaceholder("Profession").FillAsync("Tester"); 117 | 118 | await page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Create Account" }).ClickAsync(); 119 | 120 | await page.Locator("img:nth-child(2)").ClickAsync(); 121 | 122 | await page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Create Account" }).ClickAsync(); 123 | 124 | await page.Locator(".ct-logo-header").ClickAsync(); 125 | 126 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Codeless automation Lean" }) 127 | .ClickAsync(); 128 | 129 | await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "1 Katalon Studio" }).ClickAsync(); 130 | 131 | await page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Watch" }).ClickAsync(); 132 | 133 | await page.GetByRole(AriaRole.Heading, new PageGetByRoleOptions { Name = "Part 2 - Record & playback," }) 134 | .ClickAsync(); 135 | 136 | await page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Close" }).ClickAsync(); 137 | } 138 | 139 | 140 | [Test] 141 | public async Task LocatorTestsForEA2() 142 | { 143 | using var playwright = await Playwright.CreateAsync(); 144 | await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 145 | { 146 | Headless = false 147 | }); 148 | var context = await browser.NewContextAsync(); 149 | 150 | var page = await context.NewPageAsync(); 151 | 152 | await page.GotoAsync("http://localhost:8000/Product/Create"); 153 | 154 | var form1 = page.GetByRole(AriaRole.Form, new PageGetByRoleOptions { Name = "form1" }); 155 | var form2 = page.GetByRole(AriaRole.Form, new PageGetByRoleOptions { Name = "form2" }); 156 | 157 | await form1.GetByLabel("Name").FillAsync("keyboard"); 158 | 159 | await form1.GetByLabel("Description").FillAsync("gaming keyboard"); 160 | 161 | await form1.GetByRole(AriaRole.Spinbutton).FillAsync("20"); 162 | 163 | await form1.Locator("#ProductType").SelectOptionAsync(new[] { "1" }); 164 | 165 | await form2.Locator("#Name").FillAsync("Mouse"); 166 | 167 | await form2.Locator("#Description").FillAsync("Gaming mouse"); 168 | 169 | await form2.GetByRole(AriaRole.Spinbutton).FillAsync("10"); 170 | 171 | await form2.Locator("#ProductType").SelectOptionAsync(new[] { "1" }); 172 | } 173 | } -------------------------------------------------------------------------------- /PlaywrightDemo/architecture.drawio: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /PlaywrightDotnet.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightDemo", "PlaywrightDemo\PlaywrightDemo.csproj", "{2908FCFD-2BC9-41E6-8E0A-1FF5D3263AFF}" 4 | EndProject 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpecFlowProject1", "PlaywrightSpecflow\SpecFlowProject1\SpecFlowProject1.csproj", "{8A6456FD-BC62-4215-9241-02B73955A9DF}" 6 | EndProject 7 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightAPITesting", "PlaywrightAPITesting\PlaywrightAPITesting.csproj", "{DBC38AEA-0B31-494C-A8B0-D359865F3637}" 8 | EndProject 9 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightNUnitDemo", "PlaywrightNUnitDemo\PlaywrightNUnitDemo.csproj", "{064E257B-E87A-44F2-9708-442F526B08A9}" 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Any CPU = Debug|Any CPU 14 | Release|Any CPU = Release|Any CPU 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {2908FCFD-2BC9-41E6-8E0A-1FF5D3263AFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 18 | {2908FCFD-2BC9-41E6-8E0A-1FF5D3263AFF}.Debug|Any CPU.Build.0 = Debug|Any CPU 19 | {2908FCFD-2BC9-41E6-8E0A-1FF5D3263AFF}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {2908FCFD-2BC9-41E6-8E0A-1FF5D3263AFF}.Release|Any CPU.Build.0 = Release|Any CPU 21 | {8A6456FD-BC62-4215-9241-02B73955A9DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {8A6456FD-BC62-4215-9241-02B73955A9DF}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {8A6456FD-BC62-4215-9241-02B73955A9DF}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {8A6456FD-BC62-4215-9241-02B73955A9DF}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {DBC38AEA-0B31-494C-A8B0-D359865F3637}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {DBC38AEA-0B31-494C-A8B0-D359865F3637}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {DBC38AEA-0B31-494C-A8B0-D359865F3637}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {DBC38AEA-0B31-494C-A8B0-D359865F3637}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {064E257B-E87A-44F2-9708-442F526B08A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {064E257B-E87A-44F2-9708-442F526B08A9}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {064E257B-E87A-44F2-9708-442F526B08A9}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {064E257B-E87A-44F2-9708-442F526B08A9}.Release|Any CPU.Build.0 = Release|Any CPU 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /PlaywrightNUnitDemo/PlaywrightNUnitDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | false 8 | $(MSBuildProjectDirectory)\playwrightconfig.runsettings 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Always 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /PlaywrightNUnitDemo/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Playwright; 2 | using Microsoft.Playwright.NUnit; 3 | 4 | namespace PlaywrightNUnitDemo; 5 | 6 | [Parallelizable(ParallelScope.Self)] 7 | public class UnitTest1 : PageTest 8 | { 9 | [SetUp] 10 | public async Task Setup() 11 | { 12 | await Page.GotoAsync("http://eaapp.somee.com/"); 13 | } 14 | 15 | [Test] 16 | public async Task Test1() 17 | { 18 | 19 | await Page.GetByRole(AriaRole.Link, new() { Name = "Login" }).ClickAsync(); 20 | 21 | await Page.GetByLabel("UserName").ClickAsync(); 22 | 23 | await Page.GetByLabel("UserName").FillAsync("admin"); 24 | 25 | await Page.GetByLabel("UserName").PressAsync("Tab"); 26 | 27 | await Page.GetByLabel("Password").FillAsync("password"); 28 | 29 | await Page.GetByRole(AriaRole.Button, new() { Name = "Log in" }).ClickAsync(); 30 | 31 | await Page.GetByRole(AriaRole.Link, new() { Name = "Employee List" }).ClickAsync(); 32 | 33 | await Page.GetByRole(AriaRole.Link, new() { Name = "Create New" }).ClickAsync(); 34 | 35 | await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Employee" })).ToBeVisibleAsync(); 36 | 37 | } 38 | } -------------------------------------------------------------------------------- /PlaywrightNUnitDemo/UnitTest2.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Playwright; 2 | using Microsoft.Playwright.NUnit; 3 | 4 | namespace PlaywrightNUnitDemo; 5 | 6 | [Parallelizable(ParallelScope.Self)] 7 | public class UnitTest2 : PageTest 8 | { 9 | [SetUp] 10 | public async Task Setup() 11 | { 12 | await Page.GotoAsync("http://eaapp.somee.com/"); 13 | } 14 | 15 | [Test] 16 | public async Task Test1() 17 | { 18 | await Page.GetByRole(AriaRole.Link, new() { Name = "Login" }).ClickAsync(); 19 | 20 | await Page.GetByLabel("UserName").ClickAsync(); 21 | 22 | await Page.GetByLabel("UserName").FillAsync("admin"); 23 | 24 | await Page.GetByLabel("UserName").PressAsync("Tab"); 25 | 26 | await Page.GetByLabel("Password").FillAsync("password"); 27 | 28 | await Page.GetByRole(AriaRole.Button, new() { Name = "Log in" }).ClickAsync(); 29 | 30 | await Page.GetByRole(AriaRole.Link, new() { Name = "Employee List" }).ClickAsync(); 31 | 32 | await Page.GetByRole(AriaRole.Link, new() { Name = "Create New" }).ClickAsync(); 33 | 34 | await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Employee" })).ToBeVisibleAsync(); 35 | 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /PlaywrightNUnitDemo/Usings.cs: -------------------------------------------------------------------------------- 1 | global using NUnit.Framework; -------------------------------------------------------------------------------- /PlaywrightNUnitDemo/playwrightconfig.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | firefox 5 | 6 | false 7 | firefox 8 | 9 | 10 | -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpecFlowProject1", "SpecFlowProject1\SpecFlowProject1.csproj", "{4C447C27-060E-425E-A755-1BFC4ADCC2B2}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Any CPU = Debug|Any CPU 8 | Release|Any CPU = Release|Any CPU 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {4C447C27-060E-425E-A755-1BFC4ADCC2B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 12 | {4C447C27-060E-425E-A755-1BFC4ADCC2B2}.Debug|Any CPU.Build.0 = Debug|Any CPU 13 | {4C447C27-060E-425E-A755-1BFC4ADCC2B2}.Release|Any CPU.ActiveCfg = Release|Any CPU 14 | {4C447C27-060E-425E-A755-1BFC4ADCC2B2}.Release|Any CPU.Build.0 = Release|Any CPU 15 | EndGlobalSection 16 | EndGlobal 17 | -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/Drivers/Driver.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Playwright; 2 | 3 | namespace SpecFlowProject1.Drivers; 4 | 5 | public class Driver : IDisposable 6 | { 7 | private readonly Task _page; 8 | private IBrowser? _browser; 9 | 10 | public Driver() 11 | { 12 | _page = Task.Run(InitializePlaywright); 13 | } 14 | 15 | public IPage Page => _page.Result; 16 | 17 | public void Dispose() 18 | { 19 | _browser?.CloseAsync(); 20 | } 21 | 22 | private async Task InitializePlaywright() 23 | { 24 | //Playwright 25 | var playwright = await Playwright.CreateAsync(); 26 | //Browser 27 | _browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 28 | { 29 | Headless = false 30 | }); 31 | //Page 32 | return await _browser.NewPageAsync(); 33 | } 34 | } -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/Features/EALogin.feature: -------------------------------------------------------------------------------- 1 | Feature: EAEAppTest 2 | 3 | @smoke 4 | Scenario: Test Login operation of EA Application 5 | Given I navigate to appliacation 6 | And I click login link 7 | And I enter following login details 8 | | UserName | Password | 9 | | admin | password | 10 | Then I see Employee Lists -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/Features/EALogin.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (https://www.specflow.org/). 4 | // SpecFlow Version:3.9.0.0 5 | // SpecFlow Generator Version:3.9.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlowProject1.Features 14 | { 15 | using TechTalk.SpecFlow; 16 | using System; 17 | using System.Linq; 18 | 19 | 20 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.9.0.0")] 21 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 22 | [NUnit.Framework.TestFixtureAttribute()] 23 | [NUnit.Framework.DescriptionAttribute("EAEAppTest")] 24 | public partial class EAEAppTestFeature 25 | { 26 | 27 | private TechTalk.SpecFlow.ITestRunner testRunner; 28 | 29 | private static string[] featureTags = ((string[])(null)); 30 | 31 | #line 1 "EALogin.feature" 32 | #line hidden 33 | 34 | [NUnit.Framework.OneTimeSetUpAttribute()] 35 | public virtual void FeatureSetup() 36 | { 37 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 38 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Features", "EAEAppTest", null, ProgrammingLanguage.CSharp, featureTags); 39 | testRunner.OnFeatureStart(featureInfo); 40 | } 41 | 42 | [NUnit.Framework.OneTimeTearDownAttribute()] 43 | public virtual void FeatureTearDown() 44 | { 45 | testRunner.OnFeatureEnd(); 46 | testRunner = null; 47 | } 48 | 49 | [NUnit.Framework.SetUpAttribute()] 50 | public void TestInitialize() 51 | { 52 | } 53 | 54 | [NUnit.Framework.TearDownAttribute()] 55 | public void TestTearDown() 56 | { 57 | testRunner.OnScenarioEnd(); 58 | } 59 | 60 | public void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 61 | { 62 | testRunner.OnScenarioInitialize(scenarioInfo); 63 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 64 | } 65 | 66 | public void ScenarioStart() 67 | { 68 | testRunner.OnScenarioStart(); 69 | } 70 | 71 | public void ScenarioCleanup() 72 | { 73 | testRunner.CollectScenarioErrors(); 74 | } 75 | 76 | [NUnit.Framework.TestAttribute()] 77 | [NUnit.Framework.DescriptionAttribute("Test Login operation of EA Application")] 78 | [NUnit.Framework.CategoryAttribute("smoke")] 79 | public void TestLoginOperationOfEAApplication() 80 | { 81 | string[] tagsOfScenario = new string[] { 82 | "smoke"}; 83 | System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); 84 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Test Login operation of EA Application", null, tagsOfScenario, argumentsOfScenario, featureTags); 85 | #line 4 86 | this.ScenarioInitialize(scenarioInfo); 87 | #line hidden 88 | if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) 89 | { 90 | testRunner.SkipScenario(); 91 | } 92 | else 93 | { 94 | this.ScenarioStart(); 95 | #line 5 96 | testRunner.Given("I navigate to appliacation", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 97 | #line hidden 98 | #line 6 99 | testRunner.And("I click login link", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 100 | #line hidden 101 | TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] { 102 | "UserName", 103 | "Password"}); 104 | table1.AddRow(new string[] { 105 | "admin", 106 | "password"}); 107 | #line 7 108 | testRunner.And("I enter following login details", ((string)(null)), table1, "And "); 109 | #line hidden 110 | #line 10 111 | testRunner.Then("I see Employee Lists", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 112 | #line hidden 113 | } 114 | this.ScenarioCleanup(); 115 | } 116 | } 117 | } 118 | #pragma warning restore 119 | #endregion 120 | -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/Features/EALogin2.feature: -------------------------------------------------------------------------------- 1 | Feature: EAEAppTest2 2 | 3 | @smoke 4 | Scenario: Test Login operation of EA Application2 5 | Given I navigate to appliacation 6 | And I click login link 7 | And I enter following login details 8 | | UserName | Password | 9 | | admin | password | 10 | Then I see Employee Lists -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/Features/EALogin2.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (https://www.specflow.org/). 4 | // SpecFlow Version:3.9.0.0 5 | // SpecFlow Generator Version:3.9.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace SpecFlowProject1.Features 14 | { 15 | using TechTalk.SpecFlow; 16 | using System; 17 | using System.Linq; 18 | 19 | 20 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.9.0.0")] 21 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 22 | [NUnit.Framework.TestFixtureAttribute()] 23 | [NUnit.Framework.DescriptionAttribute("EAEAppTest2")] 24 | public partial class EAEAppTest2Feature 25 | { 26 | 27 | private TechTalk.SpecFlow.ITestRunner testRunner; 28 | 29 | private static string[] featureTags = ((string[])(null)); 30 | 31 | #line 1 "EALogin2.feature" 32 | #line hidden 33 | 34 | [NUnit.Framework.OneTimeSetUpAttribute()] 35 | public virtual void FeatureSetup() 36 | { 37 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 38 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Features", "EAEAppTest2", null, ProgrammingLanguage.CSharp, featureTags); 39 | testRunner.OnFeatureStart(featureInfo); 40 | } 41 | 42 | [NUnit.Framework.OneTimeTearDownAttribute()] 43 | public virtual void FeatureTearDown() 44 | { 45 | testRunner.OnFeatureEnd(); 46 | testRunner = null; 47 | } 48 | 49 | [NUnit.Framework.SetUpAttribute()] 50 | public void TestInitialize() 51 | { 52 | } 53 | 54 | [NUnit.Framework.TearDownAttribute()] 55 | public void TestTearDown() 56 | { 57 | testRunner.OnScenarioEnd(); 58 | } 59 | 60 | public void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 61 | { 62 | testRunner.OnScenarioInitialize(scenarioInfo); 63 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); 64 | } 65 | 66 | public void ScenarioStart() 67 | { 68 | testRunner.OnScenarioStart(); 69 | } 70 | 71 | public void ScenarioCleanup() 72 | { 73 | testRunner.CollectScenarioErrors(); 74 | } 75 | 76 | [NUnit.Framework.TestAttribute()] 77 | [NUnit.Framework.DescriptionAttribute("Test Login operation of EA Application2")] 78 | [NUnit.Framework.CategoryAttribute("smoke")] 79 | public void TestLoginOperationOfEAApplication2() 80 | { 81 | string[] tagsOfScenario = new string[] { 82 | "smoke"}; 83 | System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); 84 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Test Login operation of EA Application2", null, tagsOfScenario, argumentsOfScenario, featureTags); 85 | #line 4 86 | this.ScenarioInitialize(scenarioInfo); 87 | #line hidden 88 | if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) 89 | { 90 | testRunner.SkipScenario(); 91 | } 92 | else 93 | { 94 | this.ScenarioStart(); 95 | #line 5 96 | testRunner.Given("I navigate to appliacation", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 97 | #line hidden 98 | #line 6 99 | testRunner.And("I click login link", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 100 | #line hidden 101 | TechTalk.SpecFlow.Table table2 = new TechTalk.SpecFlow.Table(new string[] { 102 | "UserName", 103 | "Password"}); 104 | table2.AddRow(new string[] { 105 | "admin", 106 | "password"}); 107 | #line 7 108 | testRunner.And("I enter following login details", ((string)(null)), table2, "And "); 109 | #line hidden 110 | #line 10 111 | testRunner.Then("I see Employee Lists", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 112 | #line hidden 113 | } 114 | this.ScenarioCleanup(); 115 | } 116 | } 117 | } 118 | #pragma warning restore 119 | #endregion 120 | -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/Hooks/Hook.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [assembly: Parallelizable(ParallelScope.Fixtures)] 4 | 5 | 6 | namespace SpecFlowProject1.Hooks; 7 | 8 | [Binding] 9 | public class Hooks 10 | { 11 | } -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/Pages/LoginPage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Playwright; 2 | 3 | namespace SpecFlowProject1.Pages; 4 | 5 | public class LoginPage 6 | { 7 | private readonly ILocator _btnLogin; 8 | private readonly ILocator _lnkEmployeeDetails; 9 | private readonly ILocator _lnkLogin; 10 | private readonly ILocator _txtPassword; 11 | private readonly ILocator _txtUserName; 12 | private readonly IPage _page; 13 | 14 | public LoginPage(IPage page) 15 | { 16 | _page = page; 17 | _lnkLogin = _page.Locator("text=Login"); 18 | _txtUserName = _page.Locator("#UserName"); 19 | _txtPassword = _page.Locator("#Password"); 20 | _btnLogin = _page.Locator("text=Log in"); 21 | _lnkEmployeeDetails = _page.Locator("text='Employee Details'"); 22 | } 23 | 24 | public async Task ClickLogin() 25 | { 26 | await _lnkLogin.ClickAsync(); 27 | } 28 | 29 | public async Task Login(string userName, string password) 30 | { 31 | await _txtUserName.FillAsync(userName); 32 | await _txtPassword.FillAsync(password); 33 | await _btnLogin.ClickAsync(); 34 | } 35 | 36 | public async Task IsEmployeeDetailsExists() 37 | { 38 | return await _lnkEmployeeDetails.IsVisibleAsync(); 39 | } 40 | } -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/SpecFlowProject1.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /PlaywrightSpecflow/SpecFlowProject1/Steps/EALoginSteps.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using SpecFlowProject1.Drivers; 3 | using SpecFlowProject1.Pages; 4 | using TechTalk.SpecFlow.Assist; 5 | 6 | namespace SpecFlowProject1.Steps; 7 | 8 | [Binding] 9 | public sealed class EALoginSteps 10 | { 11 | private readonly Driver _driver; 12 | private readonly LoginPage _loginPage; 13 | 14 | public EALoginSteps(Driver driver) 15 | { 16 | _driver = driver; 17 | _loginPage = new LoginPage(_driver.Page); 18 | } 19 | 20 | [Given(@"I navigate to appliacation")] 21 | public async Task GivenINavigateToAppliacation() 22 | { 23 | await _driver.Page.GotoAsync("http://www.eaapp.somee.com"); 24 | } 25 | 26 | [Given(@"I enter following login details")] 27 | public async Task GivenIEnterFollowingLoginDetails(Table table) 28 | { 29 | dynamic data = table.CreateDynamicInstance(); 30 | await _loginPage.Login((string)data.UserName, (string)data.Password); 31 | } 32 | 33 | [Then(@"I see Employee Lists")] 34 | public async Task ThenISeeEmployeeLists() 35 | { 36 | var isExist = await _loginPage.IsEmployeeDetailsExists(); 37 | Assert.IsTrue(isExist); 38 | } 39 | 40 | [Given(@"I click login link")] 41 | public async Task GivenIClickLoginLink() 42 | { 43 | await _loginPage.ClickLogin(); 44 | } 45 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Playwrightdotnet 2 | Contains a repository for `Playwright` with .NET language binding 3 | 4 | 5 | ## Updates 6 | The complete code is updated to the latest version of Playwright with the latest version of .NET which is .NET 7 7 | 8 | 9 | # Complete the Video series on this repo on YouTube 10 | 11 | https://www.youtube.com/playlist?list=PL6tu16kXT9PoUv6HwexX5LPBzzv7QkI9W 12 | 13 | # Udemy Course For Building an Advanced framework beyond the basics 🚀 14 | 15 | https://www.udemy.com/course/framework-development-with-playwright-dotnet/ 🎉🦾 16 | 17 | # Playwright Architecture 18 | 19 | ```mermaid 20 | graph TB 21 | U["C#/Java/Python/TS SDK"] -- "Write Test" --> PT["Playwright Test"] 22 | PT -- "Uses" --> P["Playwright Driver"] 23 | P -- "Uses" --> C["Chromium"] 24 | P -- "Uses" --> F["Firefox"] 25 | P -- "Uses" --> S["Safari"] 26 | C -- "Controls" --> B["Browser"] 27 | B -- "Opens" --> Pc["Page Context"] 28 | B -- "Opens" --> Bc["Browser Context"] 29 | Pc -- "Interacts with" --> W["Web Page"] 30 | Bc -- "Opens" --> Ic["Incognito Web Page"] 31 | 32 | F -- "Controls" --> B["Browser"] 33 | B -- "Opens" --> Pc["Page Context"] 34 | B -- "Opens" --> Bc["Browser Context"] 35 | Pc -- "Interacts with" --> W["Web Page"] 36 | Bc -- "Opens" --> Ic["Incognito Web Page"] 37 | 38 | S -- "Controls" --> B["Browser"] 39 | B -- "Opens" --> Pc["Page Context"] 40 | B -- "Opens" --> Bc["Browser Context"] 41 | Pc -- "Interacts with" --> W["Web Page"] 42 | Bc -- "Opens" --> Ic["Incognito Web Page"] 43 | linkStyle 0 stroke:#2ecd71,stroke-width:2px; 44 | linkStyle 1 stroke:#2ecd71,stroke-width:2px; 45 | linkStyle 2 stroke:#2ecd71,stroke-width:2px; 46 | linkStyle 3 stroke:#2ecd71,stroke-width:2px; 47 | linkStyle 4 stroke:#2ecd71,stroke-width:2px; 48 | linkStyle 5 stroke:#2ecd71,stroke-width:2px; 49 | linkStyle 6 stroke:#2ecd71,stroke-width:2px; 50 | ``` 51 | 52 | --------------------------------------------------------------------------------