Advanced Logger for UI Tests - now on NuGet Package!

Published Jul 27 2021 06:15 AM 1,345 Views

By @Edwin Hernandez 

Microsoft_Testing_Team_3-1627367136595.png

 

 

Hello everyone,

 

We published on this blog some time ago a post about an Advanced Logger for UI tests. You can follow this link if you are interested in reading that post. For an improved version of that Logger that is now on a NuGet package, please continue reading for features, how to install it and a example:

 

Features:

  • This logger can be added to a Selenium Test Project running on Visual Studio as a NuGet Package.
  • The logger is compatible with Selenium, WinAppDriver and Xamarin iOS.
  • The package makes available an AdvLogger class that can help you log messages into an integrated HTML file.
  • The messages can contain screenshots (which expand on hover) and optional messages.
  • Screenshots are embedded into single HTML for easier management.
  • You can categorize your messages in 4 levels (info, warning, passed & error) and filter in/out as needed.
  • The HTML log file is added to the TextContext as an attachment. This makes it part of the results file which you can see in Visual Studio and gets uploaded automatically to Azure DevOps if you are running your UI-test project from Azure DevOps.
  • Adding an attachment to the TestContext was initially supported only for MSTest. Starting on version 1.0.0.9, this is now supported for NUnit.

 

If you want to know more about setting up a Azure Pipeline that contains a Selenium UI test project, please follow the link posted above, it has some intro into this topic. We also have a upcoming article about this that will be publish in the coming weeks.

 

Walkthrough

Now that we have seen the features, let's do a walkthrough of how to install it and use it on a sample Selenium C# project.

We are going to use a sample project that has a single test that validates that a "User is able to create a product review". The target app is a demo website of OpenCart.

 

The following would be our starting code:

 

The code has a Test Class and a single Test Method. All libraries related to Selenium and Test Libraries have already been imported into a Visual Studio MSTest Project. This project implements a Page Object Model for the design (if you want to learn more about selenium designs, please check this article).

 

The files on the solution would look like this:

 

Microsoft_Testing_Team_0-1627364296820.png

 

The page classes contain the actual selenium code that interacts with the browser. This model allows for these classes to be reused and helps with maintenance.

 

Here is one of the page classes:

 

 

    public class StoreHome
    {
        public static void SearchItem(IWebDriver driver, string searchStr)
        {
            driver.FindElement(By.Name("search")).SendKeys(searchStr + Keys.Enter);
        }
 
        public static void LoadStoreHome(IWebDriver driver)
        {
            driver.Manage().Window.Maximize();
            driver.Url = "https://demo.opencart.com/";
        }
    }

 

 

 

The test class is as follows:

 

 

[TestClass]
    public class OpenCartTests
    {
        IWebDriver driver;
 
        [TestInitialize]
        public void Initialize()
        {
            driver = new ChromeDriver(@"C:\Users\edwinh\source\repos\BlogDemoNuget\BlogDemoNuget");
        }
 
        [TestMethod]
        public void OpenCart_ValidateReviewSubmision()
        {
            StoreHome.LoadStoreHome(driver);
 
            StoreHome.SearchItem(driver, "iphone");
 
            SearchResults.SortItemsBy(driver, 4);
 
            SearchResults.OpenItem(driver, 1);
 
            ItemPage.GotoReviews(driver);
 
            ItemPage.PostAReview(driver
                , "UITester", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eget nisi a nunc varius dictum at sit amet diam. Donec posuere gravida dui vitae elementum. In efficitur sodales erat a consectetu"
                , 4);
 
            string msg = ItemPage.GetReviewMessage(driver);
 
            Assert.AreEqual("Thank you for your review. It has been submitted to the webmaster for approval.", msg);            
        }
 
        [TestCleanup]
        public void CleanUp()
        {
            driver.Quit();
        }

 

 

 

You can get this whole project by cloning it from this public GitHub repo here, which would include all the other page classes.

 

For now, please look at the OpenCart_ValidateReviewSubmision Test Method, as you can see, since this we are implementing the Page Object model, the test is relatively easy to follow.

First load the store page > then search for an item > sort the list > open the first item > go to reviews > and post a review. We additionally have a validation.

 

The test works as it is but Selenium and MSTest do not produce any kind of report other than passed/fail.

This is where the Advance Logger for UI-tests comes into play.

 

To add it first search for it from the NuGet Package Manager:

Microsoft_Testing_Team_1-1627364296832.png

 

Install it and solve any dependency incompatibilities with your project.

Now that the library is available for your project, the following changes are needed:

 

1) Create a Test Context in your test class (but outside of your test method):

 

 

        private TestContext testContextInstance;
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

 

 

 

2) Initialize the AdvLogger

 

 

        AdvLogger.imageSize = 400;                                  
                  //In Pixels. Default is 300
        AdvLogger.includeSnapshootsForPassAndError = true;          
                  //Only Pass and Error levels include snapshots. Default is true.
        AdvLogger.onHoverImageSizeAsPercentageOfWindow = 50;        
                  //How big you want your screenshots to expand to. Default is 100% of browser screen width.
        AdvLogger.Current.LOGLEVEL = 1;                             
                  //Logger will include only messages at specified level or above. E.g. Level=1 means no filters
                  //levels: 1=info, 2-passed, 3-warning, 4-error

 

 

 

3) Add some Log Messages in your test method and page object classes

One of the Page Object classes:

 

 

    public class StoreHome
    {
        public static void SearchItem(IWebDriver driver, string searchStr)
        {
            driver.FindElement(By.Name("search")).SendKeys(searchStr + Keys.Enter);
            AdvLogger.Current.LogMessage("Passed", driver);
        }
 
        public static void LoadStoreHome(IWebDriver driver)
        {
            driver.Manage().Window.Maximize();
            driver.Url = "https://demo.opencart.com/";
            AdvLogger.Current.LogMessage("Passed", driver);
        }
    }

 

 

 

For a better report, you will need to add a LogMessage to each Page Object method, so that there is a sequence of screenshots or messages in your HTML report. LogMessage uses reflection to get the class and method name and uses this to build the report.

Test Method:

 

 

        [TestMethod]
        public void OpenCart_ValidateReviewSubmision()
        {
            AdvLogger.Current.InsertDividerForNewTest();
 
            StoreHome.LoadStoreHome(driver);
 
            StoreHome.SearchItem(driver, "iphone");
 
            SearchResults.SortItemsBy(driver, 4);
 
            SearchResults.OpenItem(driver, 1);
 
            ItemPage.GotoReviews(driver);
 
            ItemPage.PostAReview(driver
                , "UITester", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eget nisi a nunc varius dictum at sit amet diam. Donec posuere gravida dui vitae elementum. In efficitur sodales erat a consectetu"
                , 4);
 
            string msg = ItemPage.GetReviewMessage(driver);
 
            Assert.AreEqual("Thank you for your review. It has been submitted to the webmaster for approval.", msg);
            
            AdvLogger.Current.LogMessage("Info", driver, "Validation passed");
 
            AdvLogger.Current.LogMessage("Info", driver, "REACHED END OF TEST CASE");
        }

 

 

 

You need to insert a New Test Divider at the start of your test method. The other two "Info" messages are optional but I think it gives the report a nice wrap up.

 

4) EndLogging to generate html

 

 

        [TestCleanup]
        public void CleanUp()
        {
            driver.Quit();
            var fileName = AdvLogger.Current.EndLogging(TestContext);
            System.Diagnostics.Process.Start("explorer.exe", fileName);
        }

 

 

 

EndLogging processes all the messages and screenshots into an HTML report and attaches it to the TestContext. Once it's in the TestContext it's part of the Results File in Visual Studio and it gets uploaded into Azure DevOps if you run this project as part of an Azure Pipeline.

Process.Start just opens up the report at the end of each test, this is optional.

 

The end result is an HTML report that would look like this:

Microsoft_Testing_Team_2-1627364296834.png

 

 

I hope this Logger continues to help anyone that needs it. You can find these resources in the following locations:

NuGet Package URL: https://www.nuget.org/packages/AdvUITestLogger

GitHub Repository of the Project described above: https://github.com/edwin-hernandez-maynez/BlogDemoNuget

 

Please leave any questions in the comment are below. Thanks for reading!

 

 

 

P.S. We added support for NUnit:

NUnit Example

Starting with NuGet Package 1.0.0.9, the Logger supports NUnit (in addition to MSTest). The dependency on a test framework is only used when calling the EndLogging method to generate the report and attach it to the TestContext. 

 

You can find in this branch of the repo, an example implementing NUnit and the AdvUITestLogger:

https://github.com/edwin-hernandez-maynez/BlogDemoNuget/tree/UsingNUnit

3 Comments
Senior Member

7/28/2021: Added support for NUnit

Occasional Visitor

Your solution works great, but I am experiencing a issue when running tests in parallel. I'm running into System.IO Exceptions on the first tests getting queued up. Any chance you can show an example with parallel tests? 

 

Update: I found solution to the issue after posting this. If anyone runs into a similar issue try creating a read-only object in your base test class and then in the test class under your initialize method add a Monitor.Enter(your object name), and then add Monitor.Exit in your clean up method as well. Seems to be working well. 

Senior Member

Thanks @patrick_higgins, I don't do a lot of parallel testing with UI-tests. Are you running them on different VMs? or using a head-less browser? I normally use Azure DevOps when I need to run large numbers of tests. 

%3CLINGO-SUB%20id%3D%22lingo-sub-2589589%22%20slang%3D%22en-US%22%3EAdvanced%20Logger%20for%20UI%20Tests%20-%20now%20on%20NuGet%20Package!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2589589%22%20slang%3D%22en-US%22%3E%3CP%3EBy%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F130536%22%20target%3D%22_blank%22%3E%40Edwin%20Hernandez%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Microsoft_Testing_Team_3-1627367136595.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F298562i65A8D6934D5B90EC%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Microsoft_Testing_Team_3-1627367136595.png%22%20alt%3D%22Microsoft_Testing_Team_3-1627367136595.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHello%20everyone%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20published%20on%20this%20blog%20some%20time%20ago%20a%20post%20about%20an%20Advanced%20Logger%20for%20UI%20tests.%20You%20can%20follow%20this%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Ftestingspot-blog%2Fadvanced-logger-for-ui-test-automation-using-azure-devops%2Fba-p%2F1579436%22%20target%3D%22_blank%22%3Elink%3C%2FA%3E%20if%20you%20are%20interested%20in%20reading%20that%20post.%20For%20an%20improved%20version%20of%20that%20Logger%20that%20is%20now%20on%20a%20NuGet%20package%2C%20please%20continue%20reading%20for%20features%2C%20how%20to%20install%20it%20and%20a%20example%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-2091890302%22%20id%3D%22toc-hId-2091890302%22%20id%3D%22toc-hId-2091890302%22%20id%3D%22toc-hId-2091890302%22%20id%3D%22toc-hId-2091890302%22%20id%3D%22toc-hId-2091890302%22%3EFeatures%3A%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3EThis%20logger%20can%20be%20added%20to%20a%20Selenium%20Test%20Project%20running%20on%20Visual%20Studio%20as%20a%20NuGet%20Package.%3C%2FLI%3E%0A%3CLI%3EThe%20logger%20is%20compatible%20with%20Selenium%2C%20WinAppDriver%20and%20Xamarin%20iOS.%3C%2FLI%3E%0A%3CLI%3EThe%20package%20makes%20available%20an%20AdvLogger%20class%20that%20can%20help%20you%20log%20messages%20into%20an%20integrated%20HTML%20file.%3C%2FLI%3E%0A%3CLI%3EThe%20messages%20can%20contain%20screenshots%20(which%20expand%20on%20hover)%20and%20optional%20messages.%3C%2FLI%3E%0A%3CLI%3EScreenshots%20are%20embedded%20into%20single%20HTML%20for%20easier%20management.%3C%2FLI%3E%0A%3CLI%3EYou%20can%20categorize%20your%20messages%20in%204%20levels%20(info%2C%20warning%2C%20passed%20%26amp%3B%20error)%20and%20filter%20in%2Fout%20as%20needed.%3C%2FLI%3E%0A%3CLI%3EThe%20HTML%20log%20file%20is%20added%20to%20the%20TextContext%20as%20an%20attachment.%20This%20makes%20it%20part%20of%20the%20results%20file%20which%20you%20can%20see%20in%20Visual%20Studio%20and%20gets%20uploaded%20automatically%20to%20Azure%20DevOps%20if%20you%20are%20running%20your%20UI-test%20project%20from%20Azure%20DevOps.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20know%20more%20about%20setting%20up%20a%20Azure%20Pipeline%20that%20contains%20a%20Selenium%20UI%20test%20project%2C%20please%20follow%20the%20link%20posted%20above%2C%20it%20has%20some%20intro%20into%20this%20topic.%20We%20also%20have%20a%20upcoming%20article%20about%20this%20that%20will%20be%20publish%20in%20the%20coming%20weeks.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-284435839%22%20id%3D%22toc-hId-284435839%22%20id%3D%22toc-hId-284435839%22%20id%3D%22toc-hId-284435839%22%20id%3D%22toc-hId-284435839%22%20id%3D%22toc-hId-284435839%22%3EWalkthrough%3C%2FH3%3E%0A%3CP%3ENow%20that%20we%20have%20seen%20the%20features%2C%20let's%20do%20a%20walkthrough%20of%20how%20to%20install%20it%20and%20use%20it%20on%20a%20sample%20Selenium%20C%23%20project.%3C%2FP%3E%0A%3CP%3EWe%20are%20going%20to%20use%20a%20sample%20project%20that%20has%20a%20single%20test%20that%20validates%20that%20a%20%22User%20is%20able%20to%20create%20a%20product%20review%22.%20The%20target%20app%20is%20a%20demo%20website%20of%20OpenCart.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20following%20would%20be%20our%20starting%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20code%20has%20a%20Test%20Class%20and%20a%20single%20Test%20Method.%20All%20libraries%20related%20to%20Selenium%20and%20Test%20Libraries%20have%20already%20been%20imported%20into%20a%20Visual%20Studio%20MSTest%20Project.%20This%20project%20implements%20a%20Page%20Object%20Model%20for%20the%20design%20(if%20you%20want%20to%20learn%20more%20about%20selenium%20designs%2C%20please%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Ftestingspot-blog%2Fui-automation-page-object-model-and-other-design-patterns%2Fba-p%2F992242%22%20target%3D%22_blank%22%3Echeck%20this%20article%3C%2FA%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20files%20on%20the%20solution%20would%20look%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-center%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Microsoft_Testing_Team_0-1627364296820.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F298553iE8AB439A87FC2D5C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Microsoft_Testing_Team_0-1627364296820.png%22%20alt%3D%22Microsoft_Testing_Team_0-1627364296820.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20page%20classes%20contain%20the%20actual%20selenium%20code%20that%20interacts%20with%20the%20browser.%20This%20model%20allows%20for%20these%20classes%20to%20be%20reused%20and%20helps%20with%20maintenance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20one%20of%20the%20page%20classes%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20public%20class%20StoreHome%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20public%20static%20void%20SearchItem(IWebDriver%20driver%2C%20string%20searchStr)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver.FindElement(By.Name(%22search%22)).SendKeys(searchStr%20%2B%20Keys.Enter)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%0A%20%20%20%20%20%20%20%20public%20static%20void%20LoadStoreHome(IWebDriver%20driver)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver.Manage().Window.Maximize()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver.Url%20%3D%20%22https%3A%2F%2Fdemo.opencart.com%2F%22%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20test%20class%20is%20as%20follows%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%5BTestClass%5D%0A%20%20%20%20public%20class%20OpenCartTests%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20IWebDriver%20driver%3B%0A%20%0A%20%20%20%20%20%20%20%20%5BTestInitialize%5D%0A%20%20%20%20%20%20%20%20public%20void%20Initialize()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver%20%3D%20new%20ChromeDriver(%40%22C%3A%5CUsers%5Cedwinh%5Csource%5Crepos%5CBlogDemoNuget%5CBlogDemoNuget%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%0A%20%20%20%20%20%20%20%20%5BTestMethod%5D%0A%20%20%20%20%20%20%20%20public%20void%20OpenCart_ValidateReviewSubmision()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20StoreHome.LoadStoreHome(driver)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20StoreHome.SearchItem(driver%2C%20%22iphone%22)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20SearchResults.SortItemsBy(driver%2C%204)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20SearchResults.OpenItem(driver%2C%201)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20ItemPage.GotoReviews(driver)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20ItemPage.PostAReview(driver%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2C%20%22UITester%22%2C%20%22Lorem%20ipsum%20dolor%20sit%20amet%2C%20consectetur%20adipiscing%20elit.%20Nam%20eget%20nisi%20a%20nunc%20varius%20dictum%20at%20sit%20amet%20diam.%20Donec%20posuere%20gravida%20dui%20vitae%20elementum.%20In%20efficitur%20sodales%20erat%20a%20consectetu%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2C%204)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20string%20msg%20%3D%20ItemPage.GetReviewMessage(driver)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20Assert.AreEqual(%22Thank%20you%20for%20your%20review.%20It%20has%20been%20submitted%20to%20the%20webmaster%20for%20approval.%22%2C%20msg)%3B%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%7D%0A%20%0A%20%20%20%20%20%20%20%20%5BTestCleanup%5D%0A%20%20%20%20%20%20%20%20public%20void%20CleanUp()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver.Quit()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20get%20this%20whole%20project%20by%20cloning%20it%20from%20this%20public%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fedwin-hernandez-maynez%2FBlogDemoNuget.git%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGitHub%20repo%20here%3C%2FA%3E%2C%20which%20would%20include%20all%20the%20other%20page%20classes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20now%2C%20please%20look%20at%20the%20%3CSTRONG%3EOpenCart_ValidateReviewSubmision%20%3C%2FSTRONG%3ETest%20Method%3CSTRONG%3E%2C%20%3C%2FSTRONG%3Eas%20you%20can%20see%2C%20since%20this%20we%20are%20implementing%20the%20Page%20Object%20model%2C%20the%20test%20is%20relatively%20easy%20to%20follow.%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-60px%22%3EFirst%20load%20the%20store%20page%20%26gt%3B%20then%20search%20for%20an%20item%20%26gt%3B%20sort%20the%20list%20%26gt%3B%20open%20the%20first%20item%20%26gt%3B%20go%20to%20reviews%20%26gt%3B%20and%20post%20a%20review.%20We%20additionally%20have%20a%20validation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20test%20works%20as%20it%20is%20but%20Selenium%20and%20MSTest%20do%20not%20produce%20any%20kind%20of%20report%20other%20than%20passed%2Ffail.%3C%2FP%3E%0A%3CP%3EThis%20is%20where%20the%20Advance%20Logger%20for%20UI-tests%20comes%20into%20play.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20add%20it%20first%20search%20for%20it%20from%20the%20NuGet%20Package%20Manager%3A%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-60px%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Microsoft_Testing_Team_1-1627364296832.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F298554iC7AEEE8B68BE0BA0%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Microsoft_Testing_Team_1-1627364296832.png%22%20alt%3D%22Microsoft_Testing_Team_1-1627364296832.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EInstall%20it%20and%20solve%20any%20dependency%20incompatibilities%20with%20your%20project.%3C%2FP%3E%0A%3CP%3ENow%20that%20the%20library%20is%20available%20for%20your%20project%2C%20the%20following%20changes%20are%20needed%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E1)%20Create%20a%20Test%20Context%20in%20your%20test%20class%20(but%20outside%20of%20your%20test%20method)%3A%3C%2FU%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20private%20TestContext%20testContextInstance%3B%0A%20%20%20%20%20%20%20%20public%20TestContext%20TestContext%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20get%20%7B%20return%20testContextInstance%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20set%20%7B%20testContextInstance%20%3D%20value%3B%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E2)%26nbsp%3BInitialize%20the%20AdvLogger%3C%2FU%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20AdvLogger.imageSize%20%3D%20400%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2FIn%20Pixels.%20Default%20is%20300%0A%20%20%20%20%20%20%20%20AdvLogger.includeSnapshootsForPassAndError%20%3D%20true%3B%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2FOnly%20Pass%20and%20Error%20levels%20include%20snapshots.%20Default%20is%20true.%0A%20%20%20%20%20%20%20%20AdvLogger.onHoverImageSizeAsPercentageOfWindow%20%3D%2050%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2FHow%20big%20you%20want%20your%20screenshots%20to%20expand%20to.%20Default%20is%20100%25%20of%20browser%20screen%20width.%0A%20%20%20%20%20%20%20%20AdvLogger.Current.LOGLEVEL%20%3D%201%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2FLogger%20will%20include%20only%20messages%20at%20specified%20level%20or%20above.%20E.g.%20Level%3D1%20means%20no%20filters%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2Flevels%3A%201%3Dinfo%2C%202-passed%2C%203-warning%2C%204-error%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E3)%20Add%20some%20Log%20Messages%20in%20your%20test%20method%20and%20page%20object%20classes%3C%2FU%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EOne%20of%20the%20Page%20Object%20classes%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20public%20class%20StoreHome%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20public%20static%20void%20SearchItem(IWebDriver%20driver%2C%20string%20searchStr)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver.FindElement(By.Name(%22search%22)).SendKeys(searchStr%20%2B%20Keys.Enter)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20AdvLogger.Current.LogMessage(%22Passed%22%2C%20driver)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%0A%20%20%20%20%20%20%20%20public%20static%20void%20LoadStoreHome(IWebDriver%20driver)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver.Manage().Window.Maximize()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver.Url%20%3D%20%22https%3A%2F%2Fdemo.opencart.com%2F%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20AdvLogger.Current.LogMessage(%22Passed%22%2C%20driver)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EFor%20a%20better%20report%2C%20you%20will%20need%20to%20add%20a%20LogMessage%20to%20each%20Page%20Object%20method%2C%20so%20that%20there%20is%20a%20sequence%20of%20screenshots%20or%20messages%20in%20your%20HTML%20report.%20LogMessage%20uses%20reflection%20to%20get%20the%20class%20and%20method%20name%20and%20uses%20this%20to%20build%20the%20report.%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3ETest%20Method%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20%5BTestMethod%5D%0A%20%20%20%20%20%20%20%20public%20void%20OpenCart_ValidateReviewSubmision()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20AdvLogger.Current.InsertDividerForNewTest()%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20StoreHome.LoadStoreHome(driver)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20StoreHome.SearchItem(driver%2C%20%22iphone%22)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20SearchResults.SortItemsBy(driver%2C%204)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20SearchResults.OpenItem(driver%2C%201)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20ItemPage.GotoReviews(driver)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20ItemPage.PostAReview(driver%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2C%20%22UITester%22%2C%20%22Lorem%20ipsum%20dolor%20sit%20amet%2C%20consectetur%20adipiscing%20elit.%20Nam%20eget%20nisi%20a%20nunc%20varius%20dictum%20at%20sit%20amet%20diam.%20Donec%20posuere%20gravida%20dui%20vitae%20elementum.%20In%20efficitur%20sodales%20erat%20a%20consectetu%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2C%204)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20string%20msg%20%3D%20ItemPage.GetReviewMessage(driver)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20Assert.AreEqual(%22Thank%20you%20for%20your%20review.%20It%20has%20been%20submitted%20to%20the%20webmaster%20for%20approval.%22%2C%20msg)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20AdvLogger.Current.LogMessage(%22Info%22%2C%20driver%2C%20%22Validation%20passed%22)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20AdvLogger.Current.LogMessage(%22Info%22%2C%20driver%2C%20%22REACHED%20END%20OF%20TEST%20CASE%22)%3B%0A%20%20%20%20%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EYou%20need%20to%20insert%20a%20New%20Test%20Divider%20at%20the%20start%20of%20your%20test%20method.%20The%20other%20two%20%22Info%22%20messages%20are%20optional%20but%20I%20think%20it%20gives%20the%20report%20a%20nice%20wrap%20up.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E4)%20EndLogging%20to%20generate%20html%3C%2FU%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20%5BTestCleanup%5D%0A%20%20%20%20%20%20%20%20public%20void%20CleanUp()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20driver.Quit()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20fileName%20%3D%20AdvLogger.Current.EndLogging(TestContext)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.Diagnostics.Process.Start(%22explorer.exe%22%2C%20fileName)%3B%0A%20%20%20%20%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EEndLogging%20processes%20all%20the%20messages%20and%20screenshots%20into%20an%20HTML%20report%20and%20attaches%20it%20to%20the%20TestContext.%20Once%20it's%20in%20the%20TestContext%20it's%20part%20of%20the%20Results%20File%20in%20Visual%20Studio%20and%20it%20gets%20uploaded%20into%20Azure%20DevOps%20if%20you%20run%20this%20project%20as%20part%20of%20an%20Azure%20Pipeline.%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EProcess.Start%20just%20opens%20up%20the%20report%20at%20the%20end%20of%20each%20test%2C%20this%20is%20optional.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20end%20result%20is%20an%20HTML%20report%20that%20would%20look%20like%20this%3A%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-60px%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Microsoft_Testing_Team_2-1627364296834.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F298555i38B4E786F246D26E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Microsoft_Testing_Team_2-1627364296834.png%22%20alt%3D%22Microsoft_Testing_Team_2-1627364296834.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20hope%20this%20Logger%20continues%20to%20help%20anyone%20that%20needs%20it.%20You%20can%20find%20these%20resources%20in%20the%20following%20locations%3A%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3ENuGet%20Package%20URL%3A%20%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fpackages%2FAdvUITestLogger%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fwww.nuget.org%2Fpackages%2FAdvUITestLogger%3C%2FA%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EGitHub%20Repository%20of%20the%20Project%20described%20above%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fedwin-hernandez-maynez%2FBlogDemoNuget%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fedwin-hernandez-maynez%2FBlogDemoNuget%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20leave%20any%20questions%20in%20the%20comment%20are%20below.%20Thanks%20for%20reading!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2589589%22%20slang%3D%22en-US%22%3E%3CP%3ENeed%20a%20way%20to%20create%20reports%20for%20your%20Selenium%2C%20WinAppDriver%20or%20Xamarin%20UI%20TESTS%3F%20Use%20this%20NuGet%20package%20to%20create%20HTML%20reports%20with%20embedded%20screenshots%20and%20step%20descriptions%20for%20your%20tests%20flows.%20Inside%20is%20code%20and%20git%20repo%20example.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Microsoft_Testing_Team_3-1627367136595.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F298562i65A8D6934D5B90EC%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Microsoft_Testing_Team_3-1627367136595.png%22%20alt%3D%22Microsoft_Testing_Team_3-1627367136595.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2589589%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELogger%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EQA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EQuality%20Assurance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESelenium%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETest%20Automation%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETesting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EUI%20Testing%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWinAppDriver%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2594165%22%20slang%3D%22en-US%22%3ERe%3A%20Advanced%20Logger%20for%20UI%20Tests%20-%20now%20on%20NuGet%20Package!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2594165%22%20slang%3D%22en-US%22%3E%3CP%3E7%2F28%2F2021%3A%20Added%20support%20for%20NUnit%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2613223%22%20slang%3D%22en-US%22%3ERe%3A%20Advanced%20Logger%20for%20UI%20Tests%20-%20now%20on%20NuGet%20Package!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2613223%22%20slang%3D%22en-US%22%3E%3CP%3EYour%20solution%20works%20great%2C%20but%20I%20am%20experiencing%20a%20issue%20when%20running%20tests%20in%20parallel.%20I'm%20running%20into%20System.IO%20Exceptions%20on%20the%20first%20tests%20getting%20queued%20up.%20Any%20chance%20you%20can%20show%20an%20example%20with%20parallel%20tests%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUpdate%3A%20I%20found%20solution%20to%20the%20issue%20after%20posting%20this.%20If%20anyone%20runs%20into%20a%20similar%20issue%20try%20creating%20a%20read-only%20object%20in%20your%20base%20test%20class%20and%20then%20in%20the%20test%20class%20under%20your%20initialize%20method%20add%20a%20Monitor.Enter(your%20object%20name)%2C%20and%20then%20add%20Monitor.Exit%20in%20your%20clean%20up%20method%20as%20well.%20Seems%20to%20be%20working%20well.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Version history
Last update:
‎Sep 21 2021 07:48 AM