Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/AxaFrance.WebEngine.MobileApp/AppFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2016-2022 AXA France IARD / AXA France VIE. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Modified By: YUAN Huaxing, at: 2022-5-13 18:26
using AngleSharp.Common;
using Newtonsoft.Json.Linq;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
Expand Down Expand Up @@ -281,7 +282,10 @@ private static AppiumDriver ConnectToDevice()
//session not created (maybe a bug while there should be an exception)
//convert driver.Capabilities of type ICapabilities to a string
var cap = driver.Capabilities;
throw new WebEngineGeneralException("The driver has no session id. returning capabilities from grid:" + cap.ToString());
string error = null;
if (cap.HasCapability("error")) error = cap.GetCapability("error").ToString();
else if(cap.HasCapability("message")) error = cap.GetCapability("message").ToString();
throw new WebEngineGeneralException("The driver has no session id. returning capabilities from grid:" + error?? cap.ToString());
}

return driver;
Expand Down
6 changes: 5 additions & 1 deletion src/AxaFrance.WebEngine.Web/BrowserFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -443,7 +444,10 @@ private static WebDriver GetChromeDriver(IEnumerable<string> browserOptions)
{
AcceptInsecureCertificates = true,
};
options.AddArgument($"user-data-dir={GetEnvironmentVariable("LOCALAPPDATA")}\\Google\\Chrome\\User Data");

string datadir = $"{GetEnvironmentVariable("LOCALAPPDATA")}\\Google\\Chrome\\TestData";
Directory.CreateDirectory(datadir);
options.AddArgument($"user-data-dir={datadir}");
options.AddArgument("dns-prefetch-disable");
options.AddArgument("homepage=about:blank");
options.AddArgument("disable-popup-blocking");
Expand Down
10 changes: 10 additions & 0 deletions src/AxaFrance.WebEngine/Report/TestCaseReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ namespace AxaFrance.WebEngine.Report
public class TestCaseReport
{

/// <summary>
/// Initializes a new instance of the <see cref="TestCaseReport"/> class.
/// </summary>
public TestCaseReport()
{
StartTime = DateTime.Now;
EndTime = DateTime.Now;
Result = Result.None;
}

/// <summary>
/// The unique identifier of the report item, generated automaticaly and used for showing report
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/AxaFrance.WebEngine/Report/TestSuiteReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public TestSuiteReport()
{
TestResult = new List<TestCaseReport>();
EnvironmentVariables = new EnvironmentVariables();
StartTime = DateTime.Now;
EndTime = DateTime.Now;
}

/// <summary>
Expand Down
84 changes: 70 additions & 14 deletions src/Samples.LinearScripting/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using AxaFrance.WebEngine;
using AxaFrance.WebEngine.Report;
using AxaFrance.WebEngine.Web;
using OpenQA.Selenium;


namespace Samples.LinearScripting
Expand All @@ -8,42 +10,96 @@ namespace Samples.LinearScripting
public class UnitTest1
{
//WebDriver object will be used for each test case.
OpenQA.Selenium.WebDriver? driver = null;
WebDriver? driver = null;
TestCaseReport testCaseReport;
static TestSuiteReport? testSuiteReport = null;

[TestInitialize]
public void Setup()
public TestContext? TestContext { get; set; }

[ClassInitialize]
public static void ClassInitialize(TestContext testContext)
{
//Initialize the driver by platform and browser type
driver = AxaFrance.WebEngine.Web.BrowserFactory.GetDriver(
AxaFrance.WebEngine.Platform.Windows,
AxaFrance.WebEngine.BrowserType.Chrome);
driver.Navigate().GoToUrl("https://axafrance.github.io/webengine-dotnet/demo/Step1.html");
testSuiteReport = new TestSuiteReport();
}

[TestInitialize]
public void TestInitialize()
{
//Initialize the test case report and add it to the test suite report.
testCaseReport = new TestCaseReport
{
TestName = TestContext!.TestName,
StartTime = DateTime.Now
};
testSuiteReport!.TestResult.Add(testCaseReport);

//Initialize the driver by platform and browser type
driver = BrowserFactory.GetDriver(AxaFrance.WebEngine.Platform.Windows, BrowserType.Chrome);
}

[TestCleanup]
public void Teardown()
public void TestCleanup()
{
//After each test case, we will save the test case report.
testCaseReport.Result = TestContext!.CurrentTestOutcome switch
{
UnitTestOutcome.Passed => Result.Passed,
UnitTestOutcome.Failed => Result.Failed,
UnitTestOutcome.Inconclusive => Result.Ignored,
UnitTestOutcome.Error => Result.CriticalError,
_ => Result.None
};
testCaseReport.EndTime = DateTime.Now;
//Close the driver (and browser) after each test case.
driver?.Close();
driver?.Dispose();
}

[ClassCleanup]
public static void ClassTearDown()
{
//After all test cases, we will save the test suite report.
testSuiteReport!.EndTime = DateTime.Now;
var reportPath = testSuiteReport.SaveAs("TestReport", "MyTestReport", false);

//you can check the test report in folder bin\Debug\net8.0\TestReport of your test project.
DebugLogger.WriteLine($"Test Suite Report saved at: {reportPath}");
}

/// <summary>
/// Example test method to select a drink and check the next page title.
/// </summary>
[TestMethod]
public void TestMethod1()
public void SelectDrinkTest()
{
driver = BrowserFactory.GetDriver(Platform.Windows, BrowserType.Chrome);
driver.Navigate().GoToUrl("https://axafrance.github.io/webengine-dotnet/demo/Step1.html");
DrinkSelectionPageModel page = new DrinkSelectionPageModel(driver);
driver!.Navigate().GoToUrl("https://axafrance.github.io/webengine-dotnet/demo/Step1.html");


//during the test execution, we can add some action reports to the test case report.
testCaseReport.ActionReports.Add(new ActionReport
{
Name = "Navigate to Step 1 page",
Result = Result.Passed,
Log = "Navigated to Step 1 page successfully."
});

//Create a page model for the Drink Selection page.
DrinkSelectionPageModel page = new DrinkSelectionPageModel(driver);
page.SelectLanguage.SelectByValue("fr");
page.RadioChooseToBuy.CheckByValue("Coffee");
page.NextButton.Click();

Assert.IsTrue(page.Page2Title.Exists());
testCaseReport.ActionReports.Add(new ActionReport
{
Name = "Select language and drink",
Result = Result.Passed,
Log = "Selected French language and Coffee drink."
});

testCaseReport.Log = "This is the log of curren test case.";

//Check if the next page is loaded correctly.
Assert.IsTrue(page.Page2Title.Exists());
}
}
}
1 change: 1 addition & 0 deletions src/WebEngine.Test/UnitTests/AppMobileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void IntegrationTest()
System.IO.File.Delete(junitReport);
}


[TestMethod]
public void UnitTest()
{
Expand Down