AAF ― Applicita LTD
  • Getting Started
  • Development
    • Key Objectives
    • Development Environment & OS
    • Architecture
    • Visual Studio Solution
    • Setup for Local Development
      • Docker & Kubernates
      • Visual Studio Host Builder
  • Web
    • Feature
      • Authentication and Authorization
        • Sign up
        • Sign In
        • Sign out
        • Remember me
        • Recovering password
      • Tenant management
        • Create tenant
        • Search tenant
        • Tenant page
          • Change basic information
          • Change administrator
          • Change branding
          • Change style
          • Change status
          • Assets
        • Delete tenant
      • User management
        • Create user
        • Search user
        • Send email
        • User page
          • Editing page sections
          • Change basic information
          • Change profile picture
          • Change role
          • Change status
        • Delete user
        • Reset users password
      • Role management
        • Create role
        • Search role
        • Role page
          • Change basic information
          • Change status
          • Revoke role
          • Change permissions
          • Interactive permissions button
        • Delete role
      • Bug reporting
  • Testing
    • Testing Environment
    • Atata
    • Architecture
      • Feature structure
      • Common
        • Attributes
        • Components
        • Controls
        • Fixtures
        • Generators
    • Example
Powered by GitBook
On this page
  • Where to write code?
  • Control description
  • Create custom control and page object
  • Test

Was this helpful?

  1. Testing

Example

PreviousGenerators

Last updated 5 years ago

Was this helpful?

Below is an example demonstrating how to create a custom control for the following component, create a page object containing that custom control, create a test and execute it using powershell.

Where to write code?

You need to figure out where your classes will fit in the AT project architecture. If the test you are writing is part of an , then place the custom page object in Components folder, and place your custom control in Components/Controls subfolder of that feature. Place the test in Tests folder of that feature. Depending on test execution you can put your test in Tests/Parallelizable or Tests/NonParallelizable subfolder. In this example, we are working on a component on role page, so it should be part of Roles feature.

If you are working on a completely new section of the system, then you should create a new feature folder .

Control description

Role status component is a Hoverable , so you have to hover over it to make pen icon visible, and use the pen button to unlock field for editing. Once you finish editing you can use save or cancel buttons to save or cancel changes, as shown in .

We can see that toggle button has two states: enabled and disabled. By default status text is visible, displaying status text ("enabled" or "disabled"). Editing the component, will make the toggle button visible, and text will become hidden.

Here is the html code for this component:

Create custom control and page object

We define a new control with definition "role-edit-status", and inherit from Hoverablecontrol to have access to generic buttons for edit, save and cancel. We also define two custom subcontrols:

We can locate both elements using Xpath, and ideally you want to move all selectors into Constants file under Components for this feature, but to keep this example short we are inputting strings directly

public enum RoleStatus
{
    Enabled = 1,
    Disabled
}

[ControlDefinition("role-edit-status")]
public class RoleStatusControl<TOwner> : Hoverable<TOwner> where TOwner : PageObject<TOwner>
{
    [FindByXPath("role-status/span")]
    public Content<RoleStatus, TOwner> Text { get; private set; }

    [FindByXPath("ui-switch[contains(@name, 'role.enabled')]", Visibility = Visibility.Any)]
    public Clickable<TOwner> Toggle { get; private set; }
}

Then you can implement this RoleStatusControl and use it in a RolePage page object:

namespace Applicita.AAF.WebApp.Tests.Roles.Components
{
    using _ = RolePage;

    public class RolePage : PageWithNavigation<_>
    {
        public RoleStatusControl<_> Status { get; private set; }
    }
}

Test

After defining control on page object, test the control as shown in the following snippet. We are inheriting from AutoLoginTestFixture because we need to login first before we can access the role page. To navigate to the role page we are using Pages.TestRolePage().

namespace Applicita.AAF.WebApp.Tests.Roles.Tests.Parallelizable
{
    [Parallelizable]
    public class RolePageTests : AutoLoginTestFixture
    {
        [Test]
        public void RolePage_Status_Edit()
        {
            Pages.TestRolePage()
                .Status.Text.Should.Equal(RoleStatus.Enabled)
                .Status.Edit.Click()
                .Status.Toggle.Click()
                .Status.Save()
                .Status.Text.Should.Equal(RoleStatus.Disabled);
        }
    }
}

Pages.TestRolePage() simply wraps the page navigation:

public static RolePage TestRolePage()
{
    return Go.To<RolePage>(
        url: "insert-your-role-page-url-here");
}

If you want to run tests locally, you need to fulfill following prerequisites:

  1. Navigate to src\WebApps\Applicita.AAF.WebApp\ClientApp, open powershell and run npm run local (you might need to run npm install first)

  2. Start all services by opening the solution and executing ctrl + f5

  3. Have settings.json properly configured with "baseUrl": "http://aaf.local.aaf.com"

  4. Have settings.json properly configured with account credentials (ask your project manager / team leader to provide you with administrator credentials), then add this line with those credentials underneath "baseUrl"

    "account": {
     "email": "[administrator-email]",
     "password": "[administrator-password]"
    }

If you want to run tests on dev server you need to change baseUrl and account in settings.json appropriately:

Since test is in RolePageTests class, to run tests from this fixture we can open powershell in test project folder (in this example, AT project is located in C:\Projects\AAF\src\Applicita.AAF.WebApp.Tests) and run the following command:

dotnet test --filter RolePageTests

This will run all tests from this class and prompt back the results.

You can also run tests using test runner from Visual Studio.

Text which is of and can have two values: enabled and disabled defined as enum.

Toggle button which we can define as a

Have up and running

Content type
Clickable control
Azure Storage Emulator
existing feature
following the principles we discussed previously
component
this example
Role status control
Html for role status when text is visible
Html for role status when pen button is used for editing
Dev environment settings file
Run tests using native dotnet test command