How do I correctly use the Automation Driver and Automation Spec for UI testing?

Hi all,

I writing a UI test. It’s purpose is to test that all elements of my ability bar are clickable. To give the context:
I have an ability bar widget which is just a container for Ability item widgets.

Having looked at the documentation for Automation Driver and Automation Spec I set up my tests to find those elements and also test if they can be focused. These tests are succesfull.

However, when I try to MoveToElement and Click, it locates the element however, I get an error saying that the element is not under the cursor. It seems that the game never receives focus (cursor texture stays as the default Windows texture) and because of that, the cursor never moves to my element. IsHovered also fails the test

Code snippet:

FDriverElementRef a = Driver->FindElement(By::Id(Tag));
FDriverSequenceRef Sequence = Driver->CreateSequence();
Sequence->Actions()
.Wait(Until::ElementExists(a, FWaitTimeout::InSeconds(3)))
.MoveToElement(a)
.Click(a);

TEST_TRUE(Sequence->Perform());

And here is another point to take into consideration. I am then manually checking the cursor position through the Driver, and my widget’s position and they match, which to me doesnt make sense. Here is the code for that too:

int32 x = Driver->GetCursorPosition().X;
int32 y = Driver->GetCursorPosition().Y;
FText FX = FText::AsNumber(x);
FText FY = FText::AsNumber(y);

int32 ax = SAbilityItem->GetAbsolutePosition().X;
int32 ay = SAbilityItem->GetAbsolutePosition().Y;
FText AX = FText::AsNumber(x);
FText AY = FText::AsNumber(y);

UE_LOG(MyLog, Log, TEXT("Cursor position is %s x, %s y and ability item absolute position is %s x, %s y"), *FX.ToString(), *FY.ToString(), *AX.ToString(), *AY.ToString());

Any help or suggestions will be greatly appreciated.

Thank you in advance,

Kind regards,
Paris

Update: On 4.25 the main issue is fixed and now the Automation Driver successfully takes control and simulates the input. There is still an issue, where the tests fail the first time. The error is the following:

Failed to load cursor ‘…/…/…/Hannibal/Content/Slate/Cursor/DefaultCursor’ [C:\gamedev\hannibal\main\ue4\Engine\Source\Runtime\Engine\Private\GameViewportClient.cpp(3776)]

It seems the first time it’s trying to load a Hardware cursor through the AutomatedApplication::CreateCursorFromRGBABuffer which is not implemented and returns a null which then gives the above error.

It appears to be an issue of loading the test level/game after the test has started whereas to my understanding it should be the other way around.

So to bypass this issue as a temp solution, run the test once, keep the PIE window open (should stay open on its own), run the test again and it works.

Hi, I’m a novice on Automation Driver and ue4. I am confused on how to create a c++ file to write the test case. I create use the engine editor but it build failed and shows could not found the include file. I just write these lines:

#include “AutomationDriverCommon.h”
#include “AutomationDriverTypeDefs.h”

BEGIN_DEFINE_SPEC(FAutomationDriver2Spec,
“System.Automation.Driver2”,
EAutomationTestFlags::ProductFilter | EAutomationTestFlags::ApplicationContextMask)
FAutomationDriverPtr Driver;
END_DEFINE_SPEC(FAutomationDriver2Spec)
void FAutomationDriver2Spec::Define()
{
IAutomationDriverModule::Get().Enable();
IAutomationDriverModule::Get().Disable();
}

Could you give me some suggestions? Thank you!

Check your ini config.
/Script/Engine.UserInterfaceSettings
HardwareCursors=((Default, (… problem should be here