unoplatform/uno.uitest

UITest for Uno Platform

UITest repository, a framework which enables unified UI Testing of NUnit 3

UITest for Uno Platform

Uno.

Welcome to the Uno.UITest repository, a framework which enables unified UI Testing of Uno Platform apps, using NUnit 3.x.

This library provides a set of APIs to interact with an app, and assess its behavior using device simulators and browsers. The API set is based on Xamarin.UITest, which makes the migration and patterns very familiar.

The testing is available through :

  • Selenium for WebAssembly apps, using Chrome
  • Xamarin.UITest and AppCenter for iOS and Android apps.

The following target platforms are not yet supported:

  • SkiaSharp backends (GTK, WPF and Tizen )
  • Xamarin.macOS
  • Windows

Build status

Target Branch Status Recommended Nuget packages version
development master

How to use Uno.UITest with an Uno Platform app

  • Make sure Chrome is installed

  • In Visual Studio for Windows, create an application using the Uno Platform templates

  • Add the following code to each .csproj files (iOS, Android and WebAssembly), at the end before the closing </project> tag:

    PropertyGroup Condition="'$(Configuration)'=='Debug' or '$(IsUiAutomationMappingEnabled)'=='True'">
    <IsUiAutomationMappingEnabled>True</IsUiAutomationMappingEnabled>
    <DefineConstants>$(DefineConstants);USE_UITESTS</DefineConstants>
    /PropertyGroup>
    ``
    
  • In the iOS project, add a reference to the Xamarin.TestCloud.Agent nuget package (0.21.8 or later)

  • In the OnLaunched method of App.xaml.cs, add the following at the beginning:

    if __IOS__ && USE_UITESTS
    // Launches Xamarin Test Cloud Agent
    Xamarin.Calabash.Start();
    endif
    ``
    
  • Install the Uno Platform dotnet new templates:

    otnet new -i Uno.ProjectTemplates.Dotnet
    ``
    
  • Navigate to your .sln folder using a command line:

    • Create a folder named YourAppName\YourAppName.UITests
    • Then run :
    cd YourAppName.UITests
    otnet new unoapp-uitest
    ``
    The new project will be added automatically to your solution.
    
  • In the new UI Tests project, edit the Constants.cs file with values that match your project

  • In your application, add the following XAML:

    StackPanel>
    <CheckBox AutomationProperties.AutomationId="cb1" Content="Test 1"/>
    /StackPanel>
    ``
    
    
  • Then following test can be written:

    sing NUnit.Framework;
    sing Uno.UITest.Helpers.Queries;
    sing System.Linq;
    / Alias to simplify the creation of element queries
    sing Query = System.Func<Uno.UITest.IAppQuery, Uno.UITest.IAppQuery>;
    
    ublic class CheckBox_Tests : TestBase
    
    [Test]
    public void CheckBox01()
    {
    	Query checkBoxSelector = q => q.Marked("cb1");
    	App.WaitForElement(checkBoxSelector);
    
    	Query cb1 = q => q.Marked("cb1");
    	App.WaitForElement(cb1);
    
    	var value1 = App.Query(q => cb1(q).GetDependencyPropertyValue("IsChecked").Value<bool>()).First();
    	Assert.IsFalse(value1);
    
    	App.Tap(cb1);
    
    	var value2 = App.Query(q => cb1(q).GetDependencyPropertyValue("IsChecked").Value<bool>()).First();
    	Assert.IsTrue(value2);
    }
    
    ``
    
    

This sample is provided through the Sample.UITests project in this repository.

Running the tests for WebAssembly

  • To test in Chrome, first deploy the WebAssemly app using Ctrl+F5, take note of the Url of the app
  • Update the Constants.WebAssemblyDefaultUri property in Constants.cs
  • Change the Constants.CurrentPlatform to Platform.Browser
  • Launch a test by right clicking on the test in the Test Explorer, or in the test code itself.
  • A Chrome browser window will open in automated mode, and the test will execute.

Running the tests for Android

  • Build and deploy the app on a simulator
  • Update the Constants.AndroidAppName property in Constants.cs to the value set in your app manifest
  • Change the Constants.CurrentPlatform to Platform.Android
  • Launch a test by right clicking on the test in the Test Explorer, or in the test code itself.
  • The application will start on the emulator, and the test will execute

Running the tests for iOS

testing for iOS is only available through Visual Studio for Mac, where the simulators can run.

  • Open your solution in Visual Studio for mac
  • Build and deploy the app on an iOS simulator
  • Update the Constants.iOSAppName property in Constants.cs to the value specified in your info.plist file
  • Change the Constants.CurrentPlatform to Platform.iOS
  • Launch a test
  • The application will start on the emulator, and the test will execute

This sample is provided through the Sample.UITests project in this repository.

Validating the currently running environment

if(AppInitializer.GetLocalPlatform() == Platform.Android)
{
    Assert.Ignore();
}

UI Testing in a CI environment

One of the design goal of the Uno.UITest library is to enable UI Testing in Pull Request builds, so that the UI testing is not an afterthought, and is part of the development flow.

You can find some scripts examples to enable such testing, using Azure Devops hosted agents:

  • Android UI Testing in a Simulator using Linux
  • WebAssembly UI Testing using Linux
  • iOS UI Testing in an simulator using macOS
Issues

Quick list of the latest Issues we found

kazo0

kazo0

enhancement
Icon For Comments2

I'm submitting a

Feature Request

Current behavior

Currently we would need to something like the following for our test methods and classes.

Desired behavior

What would be nice and cleaner is some sort of ActivePlatforms attribute for test methods and classes. So we can mark classes and methods by doing something like:

Or maybe even an IgnoredPlatforms?

Tree55Topz

Tree55Topz

Icon For Comments5

I'm submitting a...

Sample app request Documentation issue or request

Current behavior

Uno.UiTest has documentation regarding how to create tests inside of the same solution where host code lies, but in a lot of cases, UI Automation developers are a part of QA and create their test code elsewhere in a solution outside of development

Expected behavior

If this is possible, have examples of how you could have a standalone Uno.UiTest solution to execute browser based tests

Sorry if this is not allowed, I tried asking a question on the Stackoverflow forum but no response and my team has invested a lot of time in using Selenium to create tests against our uno brower version.

The original SO post --> https://stackoverflow.com/questions/69976830/running-browser-tests-using-uno-uitest-outside-of-development-code

mrlacey

mrlacey

Icon For Comments3

I'm submitting a...

  • Documentation issue or request

Current behavior

UI Testing on a Mac is difficult and poorly documented or supported. I have previously gotten it to work but updates (that I'm not entirely sure about) mean it no longer does ­čśó.

It seems that there are many factors that can influence how/if this works and having the right combination of library versions to match the versions of OS X, XCode, VS4Mac, & more(?) are required.

There is also a lack of resources to help debug related issues.

Expected behavior

Documentation of how to run UI tests on a mac would be really helpful. Ideally, these will include:

  • A guide to UI testing on a mac (how to get started, what settings are needed, etc.)
  • Known good configurations of libraries, tooling, and OS versions.
  • Debugging guide for when things don't work as desired/expected.
  • Documentation of the scripts used for UI testing in the main Uno project.

Minimal reproduction of the problem with instructions

n/a

Environment

chingucoding

chingucoding

Icon For Comments6

I'm submitting a...

  • Bug report (I searched for similar issues and did not find one) -->

Current behavior

Using the following test and XAML, the IAppResult returns null instead of the text of the control.

Expected behavior

Text should report the actual text of the control if its a TextBlock.

Minimal reproduction of the problem with instructions

See code above.

Environment

chingucoding

chingucoding

Icon For Comments1

I'm submitting a...

  • Bug report (I searched for similar issues and did not find one) -->

Current behavior

(at least on my machine): When creating a new app that contains a TextBox and trying to use EnterText on it does not actually enter text when using the emulator. When running the app on a real device, EnterText works though.

Expected behavior

EnterText should enter text regardless if using emulator or not.

Minimal reproduction of the problem with instructions

Environment

chingucoding

chingucoding

Icon For Comments7

I'm submitting a...

  • Bug report (I searched for similar issues and did not find one) -->

Current behavior

When creating a new App and adding the Uno.UITest projects, I would expect to be able to run a test against the WASM head. However Chrome never gets started. Updating the Uno.UITest.* dependencies to the latest pre-release does not fix this.

For some reason. cloning this repository and running tests agains the SampleApp work fine though, are the packages and the source code that different?

Expected behavior

Running against WASM should work.

Minimal reproduction of the problem with instructions

  1. Create a new project
  2. Add Uno.UITest project
  3. Deploy app
  4. Update Constants.cs
  5. Try to run tests against WASM -> Chrome does not start
  6. Update to 1.1.0-dev24 versions
  7. Try to run tests again -> Chrome does not start

Environment

dr1rrb

dr1rrb

Icon For Comments0

Feature request

Improve performance of screenshot which highly impacts the duration of the build on CI

Current behavior

App.TakeScreenshot takes at least 3 sec

Expected behavior

... much faster ­čÜÇ!

Minimal reproduction of the problem with instructions

Wait for a build of Uno

XiaotianNetlift

XiaotianNetlift

Icon For Comments0

I'm submitting a...

  • Feature request

Current behavior

XamarinAppRect does not implement value comparison, only the object's default referential comparison.

Expected behavior

XamarinAppRect should implement value comparison.

Minimal reproduction of the problem with instructions

dr1rrb

dr1rrb

Icon For Comments0

Bug report

IAppRect does not have the same behavior on WASM and Xamarin

Current behavior

On WASM the IAppRect is updated when you move the element, while on Xamarin it's an immutable object captured only once.

Expected behavior

IAppRect should be immutable on all platforms

Minimal reproduction of the problem with instructions

  1. Get the rect of an element
  2. Move it using a RenderTransform

Environment

Package Version(s): latest Visual Studio: irrelevant

dr1rrb

dr1rrb

Icon For Comments0

Bug report

[WASM] IAppRect might be offseted by one pixel

Current behavior

On WASM when we get the Rect of an element in the UI tests, the actual content might by offseted by 1 pixel.

Expected behavior

When rect is X=100 an Y=100 the pixel at 100,100 should be the colored by the background of the control!

Minimal reproduction of the problem with instructions

Remove .WithPixelTolerance(x: 1, y: 1) in DoubleAnimation_Tests.TransformGroup.cs

Environment

Package Version(s): latest Visual Studio: irrelevant

dr1rrb

dr1rrb

Icon For Comments1

Feature request

We should be able to emulate advance pointer gestures, with multiple pointers at once, and also have to ability to run check while pointer are pressed.

Current behavior

We only have some pre-baked gesture / pointer manipulations like "Drag and drop", "pinch", etc.

Expected behavior

We should be able to:

  • Select the pointer type
  • Control each pointer individually, including its location and its pressed state
  • Be able to take a screenshot or run some checks while a pointer is pressed

Minimal reproduction of the problem with instructions

https://github.com/unoplatform/uno/pull/2496/files/8d9e491df98abf9d8420c145918d7d10fdffec61#diff-0d9db92fc7555ca8b9e81df6d0cf3ac3

Environment

dr1rrb

dr1rrb

Icon For Comments0

Feature request

Add support of PinchToZoomInCoordinates for WASM

Current behavior

PinchToZoomInCoordinates throws NotImplemented on WASM

Expected behavior

PinchToZoomInCoordinates does a "pinch to zoom" gesture

Minimal reproduction of the problem with instructions

https://github.com/unoplatform/uno/pull/2445/files/f85d235b368ecfd6a2042f9773e85b48ccfa6899#diff-76289c95a7b3ef52727fd43e7f498de2

Environment

Package Version(s): current Visual Studio: irrelevant

davidjohnoliver

davidjohnoliver

Icon For Comments0

I'm submitting a...

  • Bug report (I searched for similar issues and did not find one)

Minimal reproduction of the problem with instructions

Set element TargetView to Visibility = Collapsed.

Call _app.WaitForNoElement("TargetView"); in test.

Current behavior

Call will time out on WASM.

Expected behavior

When view is collapsed it will be considered 'not there', matching iOS and Android.

Environment

Library Stats (Sep 21, 2022)

Subscribers: 17
Stars: 10
Forks: 5
Issues: 19

csharp-data-visualization

I've always wanted to learn how to visualize data in C#

csharp-data-visualization

C Sharp Helper Methods

Bu bir Windows Form uygulamas─▒d─▒r ve i├žerisinde genel olarak ERP projelerinde s─▒k├ža kullan─▒labilecek baz─▒ metotlar─▒ ve kullan─▒mlar─▒n─▒ i├žermektedir

C Sharp Helper Methods

CSharp-Collection

Challenges, projects, educational files

CSharp-Collection

CSharp_Veri_Tipleri

byte, sbyte, short, ushort, int, uint, long, ulong, decimal, bool, char, string, var, object veri tipleri incelenmistir

CSharp_Veri_Tipleri

CSharp-CodeSnippet

Wide variety of sample code snippets from the topics related in C#

CSharp-CodeSnippet

csharp-aspnet-microservices

Course on building microservices on

csharp-aspnet-microservices

CSharp &quot;C#&quot; WAVE &quot;

Parses the audio data and the format chunk info from a WAVE-Format audio file &quot;

CSharp &quot;C#&quot; WAVE &quot;

CSharp_ChromaStreamApp

C# Chroma Stream App for Chroma RGB streaming

CSharp_ChromaStreamApp

CSharp-SMTP-Server

Simple (receive only) SMTP server library for C#

CSharp-SMTP-Server

CSharp To Mindustry Logic

This is a code transpiler that will transpile C# code to mlog

CSharp To Mindustry Logic