NCS.Globals 0.0.8

dotnet add package NCS.Globals --version 0.0.8                
NuGet\Install-Package NCS.Globals -Version 0.0.8                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NCS.Globals" Version="0.0.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NCS.Globals --version 0.0.8                
#r "nuget: NCS.Globals, 0.0.8"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NCS.Globals as a Cake Addin
#addin nuget:?package=NCS.Globals&version=0.0.8

// Install NCS.Globals as a Cake Tool
#tool nuget:?package=NCS.Globals&version=0.0.8                

Globals

Description

Will have the base logic of using Playwright and Selenium. Will be hosted on a Nuget feed for the other projects to use.

Installing Nuget

In the package manager console Install-Package NCS.Globals

Project Setup

Playwright

NUnit
  • Add Package Microsoft.Playwright.NUnit
  • Add the following usings
    using Microsoft.Playwright.NUnit;
    using NCS.Globals.Playwright;
    using NCS.Globals.Configuration;
    
  • Make your Test Class/s inherit from the type PageTest from playwright
        public class PlaywrightTests: PageTest
        {
        }
    
  • Create a locators.json file in a directory. Example can be found here
  • Load file in test setup. Can be fixture or one time setup.
    [SetUp]
    public async Task Setup()
    {
        Locators.ReadConfigFile(@"../../../Resources/playwright-locators.json");
        BrowserContextConfiguration.ReadConfigFile(@"../../../Resources/playwright-runsettings.json");
        await BrowserContext.CreatePage();
    }
    
MS Test
  • Add Package Microsoft.Playwright.MSTest
  • Add the following usings
    using Microsoft.Playwright.MSTest;
    using NCS.Globals.Playwright;
    using NCS.Globals.Configuration;
    
  • Make your Test Class/s inherit from the type PageTest from playwright
        public class PlaywrightTests: PageTest
        {
        }
    
  • Create a locators.json file in a directory. Example can be found here
  • Load file in test setup. Can be fixture or one time setup
    WIP
    

Selenium

NUnit
  • Add the following usings
        using OpenQA.Selenium.Chrome; //this can be any Selenium browser driver
        using NCS.Globals.Selenium;
        using NCS.Globals.Configuration;
    
  • Create a locators.json file in a directory. Example can be found here
  • Load file in test setup. Can be fixture or one time setup.
        [SetUp]
        public void Setup()
        {
            BasePage._driver = new ChromeDriver(); // uses the NCS.Globals.Selenium.BasePage class to set the IWebDriver.
            Locators.ReadConfigFile(@"../../../Resources/selenium-locators.json");
        }
    
XUnit

Coming Soon

MSTest

Coming Soon

How to Use

Once the project is setup users can interact with locators declared in the json file by calling classes from globals. The selenium web element and Playwright locators are built under the hood depending on which BasePage class is being called.

Playwright Examples

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NCS.Globals.Playwright;
using NCS.Globals.Configuration;

namespace NCS.UnitTests.Tests
{
    public class PlaywrightTests: PageTest
    {
        [SetUp]
        public async Task Setup()
        {
            Locators.ReadConfigFile(@"../../../Resources/playwright-locators.json");
            BrowserContextConfiguration.ReadConfigFile(@"../../../Resources/playwright-runsettings.json");
            await BrowserContext.CreatePage();
        }

        [Test]
        public async Task ClickOnElement()
        {
            await BasePage.GoTo("https://playwright.dev/dotnet/");
            await BasePage.ClickElement("Example Name 1", "Home Page");
        }

        [TearDown]
        public void TearDown()
        {

        }
    }
}

Selenium Examples

using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NCS.Globals.Selenium;
using NCS.Globals.Configuration;

namespace NCS.UnitTests.Tests
{
    public class SeleniumTests
    {

        [SetUp]
        public void Setup()
        {
            BasePage._driver = new ChromeDriver();
            Locators.ReadConfigFile(@"../../../Resources/selenium-locators.json");
        }

        [Test]
        public async Task ClickOnElement()
        {
            await BasePage.GoTo("https://www.selenium.dev/");
            await BasePage.ClickElement("Example Name 1");
        }

        [Test]
        public async Task DragAndDrop()
        {
            await BasePage.GoTo("https://the-internet.herokuapp.com/?ref=hackernoon.com");
            await BasePage.ClickElement("Drag and Drop Link");
            await BasePage.DragAndDrop("Drag and Drop A", "Drag and Drop B");
        }

        [Test]
        public async Task DropdownList()
        {
            await BasePage.GoTo("https://the-internet.herokuapp.com/dropdown");
            await BasePage.SelectFromDropdownText("Dropdown List", "Option 1");
            await BasePage.SelectFromDropdownIndex("Dropdown List", 2);
        }

        [Test]
        public async Task FillFieldsIn()
        {
            await BasePage.GoTo("https://the-internet.herokuapp.com/login");
            await BasePage.FillInField("Username field", "tomsmith");
            await BasePage.FillInField("Password field", "SuperSecretPassword!");
            await BasePage.ClickElement("Login button");
        }

        [TearDown]
        public void TearDown()
        {
            BasePage.Close();
        }
    }
}

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.8 163 2/19/2024
0.0.7 258 11/29/2023
0.0.6 119 11/21/2023
0.0.5 112 11/14/2023
0.0.4 126 10/12/2023
0.0.3 150 10/11/2023
0.0.2 154 10/10/2023
0.0.1 151 10/9/2023