Skip to content

Commit

Permalink
update session conection timeout for AppiumDrivers
Browse files Browse the repository at this point in the history
  • Loading branch information
huaxing-yuan committed Aug 2, 2024
1 parent c62d1a4 commit bdd8bfa
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/AxaFrance.AxeExtended.HtmlReport/OverallReportBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,18 @@ public string Export(string fileName = null)

//Add tags
ruleResults.AppendLine($"<td>");
var additionalTags = options.AdditionalTags?.GetTagsByRule(ruleId);
/*
var additionalTags = options.AdditionalTags?.GetTagsByRule(rule.Key);
if (additionalTags != null)
{
foreach (var tag in additionalTags)
{
ruleResults.AppendLine($"<span class='tag'>{tag}</span>");
}
}
*/
ruleResults.AppendLine($"</td>");

foreach (var page in Result.PageResults)
{
if (Array.Find(page.Violations, x => x.Item.Id == ruleId) != null)
Expand Down
2 changes: 1 addition & 1 deletion src/AxaFrance.AxeExtended.HtmlReport/PageReportBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private string GenerateRuleSection(AxeResultEnhancedItem[] items, string path)
);
}
string tags = string.Join(" ", item.Item.Tags.Select(x => $"<div class='regularition'>{x}</div>"));
var additinalTags = Options.AdditionalTags?.GetTagsByRule(item.Item.Id);
var additinalTags = Options.AdditionalTags?.GetTagsByRule(item.Item);
if (additinalTags != null)
{
tags += string.Join(" ", additinalTags.Select(x => $"<div class='regularition'>{x}</div>"));
Expand Down
4 changes: 2 additions & 2 deletions src/AxaFrance.AxeExtended.HtmlReport/PageReportOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public sealed class PageReportOptions
public Language ReportLanguage { get; set; } = Language.English;

/// <summary>
/// In the report, show the RGAA tags (equivalent RGAA Test Methdologie) for each rule. Default is true.
/// In the report, show additional tags
/// Default value: will use additional tags provider to get equivalent RGAA test tags.
/// </summary>
public AdditionalTagsProvider AdditionalTags { get; set; } = new RgaaTagsProvider();
public TagsProvider AdditionalTags { get; set; } = new WcagTagsProvider();

/// <summary>
/// Gets or sets the value indicating if advanced screenshot should be used. Default is true.
Expand Down
9 changes: 5 additions & 4 deletions src/AxaFrance.AxeExtended.HtmlReport/RgaaTagsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Deque.AxeCore.Commons;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -11,7 +12,7 @@ namespace AxaFrance.AxeExtended.HtmlReport
/// A mapping of Axe rules to RGAA rules, for future use
/// refers to the Mapping Rules Excel file
/// </summary>
internal class RgaaTagsProvider : AdditionalTagsProvider
internal class RgaaTagsProvider : TagsProvider
{

private static Dictionary<string, IEnumerable<string>> Mapping { get; } = new Dictionary<string, IEnumerable<string>>()
Expand Down Expand Up @@ -73,9 +74,9 @@ internal class RgaaTagsProvider : AdditionalTagsProvider
{"table-fake-caption", new string[] {"RGAA 5.1.1"}},
};

public override IEnumerable<string> GetTagsByRule(string ruleId)
public override IEnumerable<string> GetTagsByRule(AxeResultItem rule)
{

var ruleId = rule.Id;
if (Mapping.ContainsKey(ruleId))
{
return Mapping[ruleId];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Deque.AxeCore.Commons;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -9,13 +10,19 @@ namespace AxaFrance.AxeExtended.HtmlReport
/// <summary>
/// The provider to get additional tags for a rule.
/// </summary>
public abstract class AdditionalTagsProvider
public abstract class TagsProvider
{
/// <summary>
/// return a list of additional tags for a rule. if the rule is not found, return an empty list.
/// </summary>
/// <param name="ruleId">the identifier of the rule</param>
/// <returns>a list of additional tags for a given rule.</returns>
public abstract IEnumerable<string> GetTagsByRule(string ruleId);
public abstract IEnumerable<string> GetTagsByRule(AxeResultItem rule);

/// <summary>
/// If additional tags should be shown only on overall report.
/// The value is determined by tags provider
/// </summary>
public bool ShowOnOverallReportOnly { get; internal set; }
}
}
23 changes: 23 additions & 0 deletions src/AxaFrance.AxeExtended.HtmlReport/WcagTagsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Deque.AxeCore.Commons;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AxaFrance.AxeExtended.HtmlReport
{
internal class WcagTagsProvider : TagsProvider
{
public override IEnumerable<string> GetTagsByRule(AxeResultItem rule)
{
foreach (var tag in rule.Tags)
{
if(tag.StartsWith("wcag"))
{
yield return tag;
}
}
}
}
}
10 changes: 7 additions & 3 deletions src/AxaFrance.WebEngine.MobileApp/AppFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -230,10 +231,11 @@ private static AppiumDriver ConnectToDevice()

options.AddAdditionalAppiumOption("newCommandTimeout", 90);
options.AddAdditionalAppiumOption("nativeWebScreenshot", true);
options.AcceptInsecureCertificates = s.AllowAnyCertificate;

if (!string.IsNullOrEmpty(s.OsVersion))
{
options.AddAdditionalAppiumOption("os_version", s.OsVersion);
options.PlatformVersion = s.OsVersion;
}


Expand All @@ -258,12 +260,14 @@ private static AppiumDriver ConnectToDevice()
if (s.Platform == Platform.Android)
{
options.AutomationName = "UiAutomator2";
driver = new AndroidDriver(new Uri(appiumServerAddress), options);
driver = new AndroidDriver(new Uri(appiumServerAddress), options, TimeSpan.FromSeconds(180));
}
else if (s.Platform == Platform.iOS)
{
options.AutomationName = "XCUITest";
driver = new IOSDriver(new Uri(appiumServerAddress), options);
options.AddAdditionalAppiumOption("includeSafariInWebviews", true);
options.AddAdditionalAppiumOption("connectHardwareKeyboard", true);
driver = new IOSDriver(new Uri(appiumServerAddress), options, TimeSpan.FromSeconds(180));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="5.0.0-rc.7" />
<PackageReference Include="Appium.WebDriver" Version="5.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Selenium.WebDriver" Version="4.20.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.23.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/AxaFrance.WebEngine.Web/AxaFrance.WebEngine.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@


<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="5.0.0-rc.7" />
<PackageReference Include="Appium.WebDriver" Version="5.1.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Selenium.WebDriver" Version="4.20.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.23.0" />
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="WebDriverManager" Version="2.17.2" />
<PackageReference Include="WebDriverManager" Version="2.17.4" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/Samples.DataDriven/TestCases/TC_InsuranceQuote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace Samples.DataDriven.TestCases
//Test case: Insurance Quote
public class TC_InsuranceQuote : TestCaseWeb
{
public TC_InsuranceQuote() {

public TC_InsuranceQuote() {
//Define Test steps
TestSteps = new TestStep[] {
new TestStep{ Action = nameof(Login)},
Expand Down
4 changes: 2 additions & 2 deletions src/Samples.LinearScripting/Samples.LinearScripting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="5.0.0-rc.7" />
<PackageReference Include="Appium.WebDriver" Version="5.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Selenium.WebDriver" Version="4.20.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.23.0" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 17 additions & 0 deletions src/WebEngine.Test/UnitTests/AppMobileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ public void IntegrationTest()
System.IO.File.Delete(junitReport);
}

[TestMethod]
public void BrowserstackTest()
{
var settings = Settings.Instance;
settings.Username = "cugnetpascal1";
settings.Password = "qTJD3xCzAxsuU3xykyQt";
settings.GridServerUrl = "https://hub-cloud.browserstack.com/wd/hub";
settings.AppId = "bs://6448e8709276b8c8c179bcb1d7ec6b1b2414e7c2";
settings.Device = "IPhone 13";
settings.OsVersion = "17";
using (var driver = AppFactory.GetDriver(Platform.iOS))
{
driver.Quit();
}

}

[TestMethod]
public void UnitTest()
{
Expand Down
26 changes: 26 additions & 0 deletions src/WebEngine.Test/UnitTests/TrafficMesure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class TrafficMesure
public static void Cleanup()
{
networkIntercepter?.StopMonitoring();
jsEngine?.StopEventMonitoring();
Thread.Sleep(10000);
long totalRequestSize = 0;
long totalResponseSize = 0;
Expand Down Expand Up @@ -66,6 +67,18 @@ public static void Cleanup()
Console.WriteLine($"Total Request Size: {totalRequestSize}");
Console.WriteLine($"Total Response Size: {totalResponseSize}");
Console.WriteLine($"Total Network I/O: {totalRequestSize + totalResponseSize}");

Console.WriteLine("============ CONSOLE MESSAGES =============");
foreach (var msg in jsConsoleMessages)
{
Console.WriteLine($"{msg.MessageType}: {msg.MessageContent}");
}

Console.WriteLine("============ JAVASCRIPT EXCEPTIONS =============");
foreach (var ex in jsExceptions)
{
Console.WriteLine($"{ex.Message}");
}
}
try
{
Expand All @@ -85,6 +98,9 @@ public static void Cleanup()
}
static INetwork networkIntercepter;
static Dictionary<string, NetworkTraffic> networkTraffics = new Dictionary<string, NetworkTraffic>();
static List<JavaScriptConsoleApiCalledEventArgs> jsConsoleMessages = new List<JavaScriptConsoleApiCalledEventArgs>();
static List<JavaScriptExceptionThrownEventArgs> jsExceptions = new List<JavaScriptExceptionThrownEventArgs>();
static IJavaScriptEngine jsEngine;

[ClassInitialize]
public static void Initialize(TestContext context)
Expand All @@ -94,6 +110,16 @@ public static void Initialize(TestContext context)
driver = BrowserFactory.GetDriver(AxaFrance.WebEngine.Platform.Windows, BrowserType.Chrome);
}
ws.Start();
jsEngine = new JavaScriptEngine(driver);
jsEngine.JavaScriptExceptionThrown += (_, e) =>
{
jsExceptions.Add(e);
};
jsEngine.JavaScriptConsoleApiCalled += (_, e) =>
{
jsConsoleMessages.Add(e);
};
jsEngine.StartEventMonitoring().ConfigureAwait(false);
networkIntercepter = driver.Manage().Network;
networkIntercepter.NetworkRequestSent += (_, e) =>
{
Expand Down
3 changes: 2 additions & 1 deletion src/WebEngine.Test/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"Capabilities": {
"additionalCapability1": "value1",
"bstack:options": {
"local": true
"appiumVersion": "2.4.1",
"resignApp": "false"
},
"other:capability": {
"key": "value",
Expand Down

0 comments on commit bdd8bfa

Please sign in to comment.