Skip to content

Commit d1f0223

Browse files
committed
Merge branch 'main' of https://github.com/quantori/Behavioral.Automation into bap-126-playwright-basic-structure
2 parents 17bd59a + d9f501f commit d1f0223

File tree

10 files changed

+56
-132
lines changed

10 files changed

+56
-132
lines changed

Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
</PropertyGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
33-
<PackageReference Include="Microsoft.Playwright" Version="1.22.0"/>
34-
<PackageReference Include="NUnit" Version="3.13.2"/>
35-
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/>
36-
<PackageReference Include="coverlet.collector" Version="3.1.0"/>
37-
<PackageReference Include="SpecFlow" Version="3.9.74"/>
32+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
33+
<PackageReference Include="Microsoft.Playwright" Version="1.22.0" />
34+
<PackageReference Include="NUnit" Version="3.13.2" />
35+
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
36+
<PackageReference Include="coverlet.collector" Version="3.1.0" />
37+
<PackageReference Include="SpecFlow" Version="3.9.74" />
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<Folder Include="Bindings"/>
42-
<Folder Include="ElementStorage"/>
41+
<Folder Include="Bindings" />
42+
<Folder Include="ElementStorage" />
4343
</ItemGroup>
4444

4545
</Project>

Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Services/BrowserRunner.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public async Task<IPage> LaunchBrowser()
1010
using var playwright = await Microsoft.Playwright.Playwright.CreateAsync();
1111
await using var browser = await playwright.Chromium.LaunchAsync();
1212
var page = await browser.NewPageAsync();
13-
await page.GotoAsync("https://playwright.dev/dotnet");
1413

1514
return page;
1615
}

Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Services/ComplexBindingBuilder.cs renamed to Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Services/ComplexBindingBuilder/ComplexBindingBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using TechTalk.SpecFlow;
77
using TechTalk.SpecFlow.Bindings;
88

9-
namespace Behavioral.Automation.Playwright.Services
9+
namespace Behavioral.Automation.Playwright.Services.ComplexBindingBuilder
1010
{
1111
/// <summary>
1212
/// Contains BuildAction methods which should be used to call other bindings inside the code (multiple clicks, value selections, etc.)

Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Services/IComplexBindingBuilder.cs renamed to Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Services/ComplexBindingBuilder/IComplexBindingBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace Behavioral.Automation.Playwright.Services
3+
namespace Behavioral.Automation.Playwright.Services.ComplexBindingBuilder
44
{
55
/// <summary>
66
/// This interface contain methods which are used to call other bindings inside test methods, so their actions appear in the logs

Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Services/IStepParametersProcessor.cs renamed to Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Services/ComplexBindingBuilder/IStepParametersProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text.RegularExpressions;
22

3-
namespace Behavioral.Automation.Playwright.Services
3+
namespace Behavioral.Automation.Playwright.Services.ComplexBindingBuilder
44
{
55
/// <summary>
66
/// This interface contains methods which convert objects passed to ComplexBindingBuilder into step expression to use in Runner

Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Services/StringExtensions.cs

Lines changed: 0 additions & 114 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace Behavioral.Automation.Playwright.Utils
4+
{
5+
/// <summary>
6+
/// Perform various operations with strings
7+
/// </summary>
8+
public static class StringExtensions
9+
{
10+
/// <summary>
11+
/// Convert string into int
12+
/// </summary>
13+
/// <param name="s">String to get number from</param>
14+
/// <returns>int converted from string</returns>
15+
public static int ParseNumberFromString(string s)
16+
{
17+
return int.Parse(Regex.Match(s, @"\d+").Value);
18+
}
19+
}
20+
}

Behavioral.Automation.Selenium/Behavioral.Automation/Services/AutomationIDProvider.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Behavioral.Automation.Services.Mapping;
1+
using System;
2+
using System.Threading;
3+
using Behavioral.Automation.Services.Mapping;
4+
using Behavioral.Automation.Services.Mapping.Contract;
25
using JetBrains.Annotations;
36

47
namespace Behavioral.Automation.Services
@@ -10,9 +13,16 @@ namespace Behavioral.Automation.Services
1013
public sealed class AutomationIdProvider : IAutomationIdProvider
1114
{
1215
private readonly IScopeContextRuntime _scopeContextRuntime;
16+
private readonly IDriverService _driverService;
17+
private readonly IScopeContextManager _scopeContextManager;
1318

14-
public AutomationIdProvider([NotNull] IScopeContextRuntime scopeContextRuntime)
19+
public AutomationIdProvider(
20+
[NotNull] IScopeContextRuntime scopeContextRuntime,
21+
[NotNull] IDriverService driverService,
22+
[NotNull] IScopeContextManager scopeContextManager)
1523
{
24+
_scopeContextManager = scopeContextManager;
25+
_driverService = driverService;
1626
_scopeContextRuntime = scopeContextRuntime;
1727
}
1828

@@ -25,7 +35,18 @@ public AutomationIdProvider([NotNull] IScopeContextRuntime scopeContextRuntime)
2535
public ControlDescription Get(string caption)
2636
{
2737
ParseCaption(caption, out var name, out var type);
28-
return _scopeContextRuntime.FindControlDescription(type, name);
38+
39+
var controlDescription = _scopeContextRuntime.FindControlDescription(type, name);
40+
41+
if (controlDescription != null)
42+
return controlDescription;
43+
44+
Thread.Sleep(500);
45+
_scopeContextManager.SwitchToCurrentUrl(new Uri(_driverService.CurrentUrl));
46+
47+
var scopeId = ((PageScopeContext)((ScopeContextRuntime)_scopeContextRuntime).CurrentContext).ScopeId;
48+
return _scopeContextRuntime.FindControlDescription(type, name) ??
49+
throw new ArgumentException($"Control with alias=\"{type}\" and caption=\"{name}\" not found in PageContext with urlWildcard=\"{scopeId.UrlWildCard}\"");
2950
}
3051

3152
public void ParseCaption(string caption, out string name, out string type)

Behavioral.Automation.Selenium/Behavioral.Automation/Services/Mapping/PageScopeContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public ControlReference FindControlReference(string type,
4444
}
4545
}
4646

47-
throw new ArgumentException(
48-
$"Control with alias=\"{type}\" and caption=\"{name}\" not found in PageContext with urlWildcard=\"{ScopeId.UrlWildCard}\"");
47+
return null;
4948
}
5049

5150
public IControlScopeContext GetNestedControlScopeContext(ControlScopeId controlScopeId)

Behavioral.Automation.Selenium/Behavioral.Automation/Services/StepParametersProcessor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public bool TryParseStepExpressionArguments(Regex regex, string stepExpression,
4141
return true;
4242
}
4343

44-
4544
arguments = new string[] { };
4645
return false;
4746
}

0 commit comments

Comments
 (0)