From aaffeafaab3365ae5fdbcd866e0681ceaba3277f Mon Sep 17 00:00:00 2001 From: Huaxing YUAN <37816968+huaxing-yuan@users.noreply.github.com> Date: Fri, 24 Jan 2025 10:31:03 +0100 Subject: [PATCH] Update on Resource Usage (#86) * fix error in SkiaSharp dependency in nuspec * Improve API of Resource Usage Monitoring * Update documentation for the new Resource Usage API * - Minor update of documentation - Remove actions --- .../workflows/build-and-publish-PROnly.yml | 95 ---- .github/workflows/build-develop.yml | 97 ---- .../AxaFrance.WebEngine.GlobalConstants.html | 193 +++++++ .../AxaFrance.WebEngine.JavaScriptError.html | 165 ++++++ .../AxaFrance.WebEngine.NetworkRequest.html | 507 ++++++++++++++++++ ...rance.WebEngine.Report.TestCaseReport.html | 49 +- ...aFrance.WebEngine.ResourceUsageReport.html | 239 +++++++++ ...xaFrance.WebEngine.Web.BrowserFactory.html | 85 ++- ...ngine.Web.ResourceUsageReportSelenium.html | 222 ++++++++ .../AxaFrance.WebEngine.Web.TestCaseWeb.html | 6 +- docs/api_net/AxaFrance.WebEngine.Web.html | 6 +- docs/api_net/AxaFrance.WebEngine.html | 11 + docs/api_net/toc.html | 16 +- docs/articles/env-impact.html | 17 + docs/articles/report-viewer.html | 14 +- docs/images/report-viewer.png | Bin 40256 -> 99122 bytes docs/images/resource-usage-report.png | Bin 84611 -> 279005 bytes docs/manifest.json | 142 +++-- docs/xrefmap.yml | 490 +++++++++++------ .../articles/env-impact.md | 25 + .../articles/report-viewer.md | 17 +- .../images/report-viewer.png | Bin 40256 -> 99122 bytes .../images/resource-usage-report.png | Bin 84611 -> 279005 bytes .../AxaFrance.WebEngine.ReportViewer.csproj | 4 - .../AxaFrance.WebEngine.ReportViewer.nuspec | 1 + .../MainWindow.xaml.cs | 33 +- src/AxaFrance.WebEngine.Web/BrowserFactory.cs | 28 +- src/AxaFrance.WebEngine.Web/JSErrors.cs | 7 - .../ResourceUsageReportSelenium.cs | 102 ++++ src/AxaFrance.WebEngine.Web/TestCaseWeb.cs | 71 +-- src/AxaFrance.WebEngine.sln | 4 - src/AxaFrance.WebEngine/GlobalConstants.cs | 14 +- src/AxaFrance.WebEngine/JavascriptError.cs | 13 + .../NetworkRequest.cs | 2 +- .../Report/TestCaseReport.cs | 21 +- .../ResourceUsageReport.cs | 44 ++ src/AxaFrance.WebEngine/appsettings.json | 3 + .../Properties/launchSettings.json | 2 +- .../TestData/ReportWithResourceAnalyze.xml | 168 +++--- .../UnitTests/ResoureUsageTest.cs | 42 ++ src/WebEngine.Test/WebEngine.Test.csproj | 1 + 41 files changed, 2347 insertions(+), 609 deletions(-) delete mode 100644 .github/workflows/build-and-publish-PROnly.yml delete mode 100644 .github/workflows/build-develop.yml create mode 100644 docs/api_net/AxaFrance.WebEngine.GlobalConstants.html create mode 100644 docs/api_net/AxaFrance.WebEngine.JavaScriptError.html create mode 100644 docs/api_net/AxaFrance.WebEngine.NetworkRequest.html create mode 100644 docs/api_net/AxaFrance.WebEngine.ResourceUsageReport.html create mode 100644 docs/api_net/AxaFrance.WebEngine.Web.ResourceUsageReportSelenium.html delete mode 100644 src/AxaFrance.WebEngine.Web/JSErrors.cs create mode 100644 src/AxaFrance.WebEngine.Web/ResourceUsageReportSelenium.cs create mode 100644 src/AxaFrance.WebEngine/JavascriptError.cs rename src/{AxaFrance.WebEngine.Web => AxaFrance.WebEngine}/NetworkRequest.cs (98%) create mode 100644 src/AxaFrance.WebEngine/ResourceUsageReport.cs create mode 100644 src/WebEngine.Test/UnitTests/ResoureUsageTest.cs diff --git a/.github/workflows/build-and-publish-PROnly.yml b/.github/workflows/build-and-publish-PROnly.yml deleted file mode 100644 index 3366744..0000000 --- a/.github/workflows/build-and-publish-PROnly.yml +++ /dev/null @@ -1,95 +0,0 @@ -# This workflow will build a .NET project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net - -name: Build WebEngine (Main Branch Only) - -on: - pull_request: - branches: - - main - - 'preview/**' - - preview - -jobs: - build: - runs-on: windows-latest - steps: - - # checkout - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 6.0.x - - name: Install .NET Coverage - run: | - dotnet tool install --global dotnet-coverage - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Cache SonarCloud packages - uses: actions/cache@v1 - with: - path: ~\sonar\cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache SonarCloud scanner - id: cache-sonar-scanner - uses: actions/cache@v1 - with: - path: .\.sonar\scanner - key: ${{ runner.os }}-sonar-scanner - restore-keys: ${{ runner.os }}-sonar-scanner - - name: Install SonarCloud scanner - if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' - shell: powershell - run: | - New-Item -Path .\.sonar\scanner -ItemType Directory - dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner - dotnet tool install --global dotnet-sonarscanner --version 5.2.0 - - # Restore - - name: Restore - run: dotnet restore "./src" - - - name: Build and analyze - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - shell: powershell - run: | - if("${{github.base_ref}}".Contains("main")) { $suffix = "" } else { $suffix = "-preview" } - .\.sonar\scanner\dotnet-sonarscanner begin /k:"AxaGuilDEv_webengine-dotnet" /o:"axaguildev" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml - dotnet build "./src" --no-restore --configuration Debug -p:AssemblyVersion=1.2.${{github.run_number}} -p:Version=1.2.${{github.run_number}}-$suffix - dotnet-coverage collect 'dotnet test "./src/WebEngine.Test" --filter TestCategory!=Mobile' -f xml -o 'coverage.xml' - .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" - - #Do not run dotnet pack because the project is already configured to generate nupkg during build. - #- name: Dotnet Pack - # run: dotnet pack "./src" --no-restore --no-build -p:PackageVersion=1.1.${{github.run_number}} -o "./nuget" - - - name: Copy package to artifact folder - shell: powershell - run: | - mkdir "nuget" - Get-ChildItem ./src -Recurse -File -Filter Axa*.nupkg | % {Copy-Item -Path $_.FullName -Destination "./nuget/$_"} - - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - with: - name: build-artifact - path: "./nuget" - - - name: Publish Nuget to GitHub registry - run: dotnet nuget push 'nuget/**/AxaFrance*.nupkg' -k ${{ secrets.NUGET_TOKEN }} -s 'https://api.nuget.org/v3/index.json' --skip-duplicate - - - name: Tag commit - uses: tvdias/github-tagger@v0.0.1 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" - tag: "1.1.${{github.run_number}}" diff --git a/.github/workflows/build-develop.yml b/.github/workflows/build-develop.yml deleted file mode 100644 index db4c8f0..0000000 --- a/.github/workflows/build-develop.yml +++ /dev/null @@ -1,97 +0,0 @@ -# This workflow will build a .NET project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net - -name: Build WebEngine (Develop) - -on: - push: - branches: - - develop - - main - - preview -jobs: - build: - runs-on: windows-latest - steps: - - # checkout - - uses: actions/checkout@v4.1.4 - - name: Setup .NET - uses: actions/setup-dotnet@v4.0.0 - with: - dotnet-version: 6.0.x - - - name: Install .NET Coverage - run: | - dotnet tool install --global dotnet-coverage - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - - - uses: actions/checkout@v4.1.4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: Replace tokens - uses: cschleiden/replace-tokens@v1.3 - with: - tokenPrefix: '#{' - tokenSuffix: '}#' - files: '["**/Settings.cs"]' - - - name: Cache SonarCloud packages - uses: actions/cache@v1 - with: - path: ~\sonar\cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache SonarCloud scanner - id: cache-sonar-scanner - uses: actions/cache@v4.0.2 - with: - path: .\.sonar\scanner - key: ${{ runner.os }}-sonar-scanner - restore-keys: ${{ runner.os }}-sonar-scanner - - - name: Install SonarCloud scanner - if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' - shell: powershell - run: | - New-Item -Path .\.sonar\scanner -ItemType Directory - dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner - dotnet tool install --global dotnet-sonarscanner --version 5.2.0 - - - # Restore - - name: Restore - run: dotnet restore "./src" - - - name: Build and analyze - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - shell: powershell - run: | - .\.sonar\scanner\dotnet-sonarscanner begin /k:"AxaGuilDEv_webengine-dotnet" /o:"axaguildev" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml - dotnet build "./src" --no-restore --configuration Debug -p:Version=1.1.${{github.run_number}} - dotnet-coverage collect 'dotnet test "./src/WebEngine.Test" --filter TestCategory!=Mobile' -f xml -o 'coverage.xml' - .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" - - #Do not run dotnet pack because the project is already configured to generate nupkg during build. - #- name: Dotnet Pack - # run: dotnet pack "./src" --no-restore --no-build -p:PackageVersion=1.0.${{github.run_number}} -o "./nuget" - - - name: Copy package to artifact folder - shell: powershell - run: | - mkdir "nuget" - Get-ChildItem ./src -Recurse -File -Filter Axa*.nupkg | % {Copy-Item -Path $_.FullName -Destination "./nuget/$_"} - - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - with: - name: build-artifact - path: "./nuget" diff --git a/docs/api_net/AxaFrance.WebEngine.GlobalConstants.html b/docs/api_net/AxaFrance.WebEngine.GlobalConstants.html new file mode 100644 index 0000000..ea94791 --- /dev/null +++ b/docs/api_net/AxaFrance.WebEngine.GlobalConstants.html @@ -0,0 +1,193 @@ + + + + + + + + Class GlobalConstants + | AXA WebEngine Test Framework + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api_net/AxaFrance.WebEngine.JavaScriptError.html b/docs/api_net/AxaFrance.WebEngine.JavaScriptError.html new file mode 100644 index 0000000..ba33a1d --- /dev/null +++ b/docs/api_net/AxaFrance.WebEngine.JavaScriptError.html @@ -0,0 +1,165 @@ + + + + + + + + Class JavaScriptError + | AXA WebEngine Test Framework + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api_net/AxaFrance.WebEngine.NetworkRequest.html b/docs/api_net/AxaFrance.WebEngine.NetworkRequest.html new file mode 100644 index 0000000..2f86d36 --- /dev/null +++ b/docs/api_net/AxaFrance.WebEngine.NetworkRequest.html @@ -0,0 +1,507 @@ + + + + + + + + Class NetworkRequest + | AXA WebEngine Test Framework + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api_net/AxaFrance.WebEngine.Report.TestCaseReport.html b/docs/api_net/AxaFrance.WebEngine.Report.TestCaseReport.html index 43cde70..ea5fe4e 100644 --- a/docs/api_net/AxaFrance.WebEngine.Report.TestCaseReport.html +++ b/docs/api_net/AxaFrance.WebEngine.Report.TestCaseReport.html @@ -126,11 +126,12 @@
Property Value
Improve this Doc - View Source + View Source

AttachedData

-
+

Additional data attached to the test report. for example: accessibility scan results, resource usage report, etc...

+
Declaration
@@ -494,6 +495,46 @@
Property Value

Methods

+ + | + Improve this Doc + + + View Source + + +

Attach(Object, String)

+

Attach an object to the test report

+
+
+
Declaration
+
+
public void Attach(object o, string fileType)
+
+
Parameters
+ + + + + + + + + + + + + + + + + + + + +
TypeNameDescription
System.Objecto

object to attach, the object will be serialized as json

+
System.StringfileType

the type of the file, possible values: AccessibilityReport, ResourceUsage

+
| Improve this Doc @@ -503,7 +544,7 @@

Methods

AttachFile(String, String)

-

Attach a external file to the test report.

+

Attach an external file to the test report.

Declaration
@@ -529,7 +570,7 @@
Parameters
System.String fileType -

the type of the file, possible values: AccessibilityReport

+

the type of the file, possible values: AccessibilityReport, ResourceUsage

diff --git a/docs/api_net/AxaFrance.WebEngine.ResourceUsageReport.html b/docs/api_net/AxaFrance.WebEngine.ResourceUsageReport.html new file mode 100644 index 0000000..9f2e1ef --- /dev/null +++ b/docs/api_net/AxaFrance.WebEngine.ResourceUsageReport.html @@ -0,0 +1,239 @@ + + + + + + + + Class ResourceUsageReport + | AXA WebEngine Test Framework + + + + + + + + + + + + + + + +
+
+ + + + +
+ + +
+
+ +
+
+ + + + + + diff --git a/docs/api_net/AxaFrance.WebEngine.Web.BrowserFactory.html b/docs/api_net/AxaFrance.WebEngine.Web.BrowserFactory.html index c6a44cf..09a0ffc 100644 --- a/docs/api_net/AxaFrance.WebEngine.Web.BrowserFactory.html +++ b/docs/api_net/AxaFrance.WebEngine.Web.BrowserFactory.html @@ -178,7 +178,7 @@
Exceptions
Improve this Doc - View Source + View Source

GetDriver(Platform, BrowserType, IEnumerable<String>)

@@ -263,12 +263,93 @@
Exceptions
+ + | + Improve this Doc + + + View Source + + +

StartMonitoring(WebDriver)

+

Start monitoring web traffics.

+
+
+
Declaration
+
+
public static ResourceUsageReport StartMonitoring(WebDriver driver)
+
+
Parameters
+ + + + + + + + + + + + + + + +
TypeNameDescription
OpenQA.Selenium.WebDriverdriver
+
Returns
+ + + + + + + + + + + + + +
TypeDescription
ResourceUsageReport
+ + | + Improve this Doc + + + View Source + + +

StopMonitoring(ResourceUsageReport)

+

Stop monitoring web traffics.

+
+
+
Declaration
+
+
public static void StopMonitoring(ResourceUsageReport report)
+
+
Parameters
+ + + + + + + + + + + + + + + +
TypeNameDescription
ResourceUsageReportreport
| Improve this Doc - View Source + View Source

Sync(WebDriver)

diff --git a/docs/api_net/AxaFrance.WebEngine.Web.ResourceUsageReportSelenium.html b/docs/api_net/AxaFrance.WebEngine.Web.ResourceUsageReportSelenium.html new file mode 100644 index 0000000..b6e7310 --- /dev/null +++ b/docs/api_net/AxaFrance.WebEngine.Web.ResourceUsageReportSelenium.html @@ -0,0 +1,222 @@ + + + + + + + + Class ResourceUsageReportSelenium + | AXA WebEngine Test Framework + + + + + + + + + + + + + + + +
+
+ + + + +
+ + +
+
+ +
+
+ + + + + + diff --git a/docs/api_net/AxaFrance.WebEngine.Web.TestCaseWeb.html b/docs/api_net/AxaFrance.WebEngine.Web.TestCaseWeb.html index 77f253d..e470644 100644 --- a/docs/api_net/AxaFrance.WebEngine.Web.TestCaseWeb.html +++ b/docs/api_net/AxaFrance.WebEngine.Web.TestCaseWeb.html @@ -137,7 +137,7 @@

Properties Improve this Doc - View Source + View Source

AccessibilityReportTitle

@@ -232,7 +232,7 @@

Methods Improve this Doc - View Source + View Source

Cleanup()

@@ -266,7 +266,7 @@
Overrides
Improve this Doc - View Source + View Source

Initialize()

diff --git a/docs/api_net/AxaFrance.WebEngine.Web.html b/docs/api_net/AxaFrance.WebEngine.Web.html index 430c8f3..895da83 100644 --- a/docs/api_net/AxaFrance.WebEngine.Web.html +++ b/docs/api_net/AxaFrance.WebEngine.Web.html @@ -99,13 +99,13 @@

FindsBy

HtmlAttribute

Describes an attribute of HTML tag. Use HtmlAttribute to describe a non-standand html attributes.

-
-

NetworkRequest

-

A network request record, which is used to store the information of a network request initiated by the browser.

PageModel

Page Model is the repository to store all test objets which are been used by the test script. Page Model contains one or more ElementDescription, each Element Description indicates how to identify the

+
+

ResourceUsageReportSelenium

+

represents a report that measures the resource usage of the web site during a user journey.

SharedActionWeb

SharedActionWeb implements privately the generic SharedActionBase interface and exposes new abstract methods diff --git a/docs/api_net/AxaFrance.WebEngine.html b/docs/api_net/AxaFrance.WebEngine.html index e8f9fe8..be3a664 100644 --- a/docs/api_net/AxaFrance.WebEngine.html +++ b/docs/api_net/AxaFrance.WebEngine.html @@ -91,12 +91,23 @@

Encrypter

EnvironmentVariables

This class defines the structure of environment variables

+
+

GlobalConstants

+
+

JavaScriptError

+

Represents a JavaScript error that occurred during the user journey.

MethodExtensions

The method extension to provide helper functions for List operations

+
+

NetworkRequest

+

A network request record, which is used to store the information of a network request initiated by the browser.

ReportSettings

Settings of the WebEngine privides global

+
+

ResourceUsageReport

+

represents a report that measures the resource usage of the web site during a user journey.

Settings

Settings of the WebEngine provides global testing parameters and behavior. settings can be loaded from external files, or provided via command line using WebRunner.

diff --git a/docs/api_net/toc.html b/docs/api_net/toc.html index cfe3f18..a9bdefd 100644 --- a/docs/api_net/toc.html +++ b/docs/api_net/toc.html @@ -119,15 +119,27 @@
  • EnvironmentVariables
  • +
  • + GlobalConstants +
  • +
  • + JavaScriptError +
  • MethodExtensions
  • +
  • + NetworkRequest +
  • Platform
  • ReportSettings
  • +
  • + ResourceUsageReport +
  • Result
  • @@ -265,10 +277,10 @@ HtmlAttribute
  • - NetworkRequest + PageModel
  • - PageModel + ResourceUsageReportSelenium
  • SharedActionWeb diff --git a/docs/articles/env-impact.html b/docs/articles/env-impact.html index a75a727..2e39de3 100644 --- a/docs/articles/env-impact.html +++ b/docs/articles/env-impact.html @@ -75,6 +75,20 @@

    Measure environmen communication and resource usage. However, when using the WebEngine Framework, you don't need to worry about the technical details; you just need to enable the feature and use the provided API to get the information you need.

    How to activate resource usage tracing?

    +

    Using Gherkin approach

    +

    Using Gherkin, you need to activate Traffic Monitoring before the first action on the target application and stop monitoring after the last action.

    +
    Note

    Web pages may take time to load HTML documents and resources (such as images and scripts) requested by HTML and XHR. +Please wait until all user interactions are finished before stopping the traffic monitoring, +or the monitoring report may contain missing items.

    +
    +

    To start monitoring, you�ll need to run the following code

    +
    var usageReport = BrowserFactory.StartMonitoring(driver);
    +

    After all user interactions, use following code to stop monitoring

    +
    usageReport.StopMonitoring();
    +

    Attach usage monitoring result to Test Report

    +

    Assuming you have the instance of TestCaseReport named tcReport, the following code will attach it to test report.

    +
    tcr.Attach(usageReport, GlobalConstants.ResourceUsageReport);
    +

    Using keyword driven approach

    Resource usage tracing is enabled at the test case level. The flag is defined at MeasureResourceUsage. When the flag is enabled before test execution, the framework will start a network interceptor and save information of all incoming and outgoing traffic in the report.

    @@ -120,6 +134,9 @@

    How are the results displayed?

    @@ -91,6 +94,9 @@

    View an existing Report