# Spawning a window and widget in SIMPLE\_AUTOMATION\_TEST

**URL:** <https://forums.unrealengine.com/t/spawning-a-window-and-widget-in-simple-automation-test/791753>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [March 16, 2023, 1:24am UTC](https://forums.unrealengine.com/t/spawning-a-window-and-widget-in-simple-automation-test/791753 "2023-03-16T01:24:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgoncharriot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sgoncharriot/32/88714_2.png) [@sgoncharriot](https://forums.unrealengine.com/u/sgoncharriot)\
**Post date:** [March 16, 2023, 1:24am UTC](https://forums.unrealengine.com/t/spawning-a-window-and-widget-in-simple-automation-test/791753/1 "2023-03-16T01:24:47Z")

</div>

Hello,  
I’m wondering if I can pick your brains a bit …

Context:

- I’m working on some automated testing, ultimate goal is to run the game/app (as if you pressed play in editor or ran .exe) and pipe some input into it, then take some screenshots.

Progress:

- Used a tutorial and got as far as IMPLEMENT\_SIMPLE\_AUTOMATION\_TEST and RunTest getting called.
- I’m pretty sure FDriverSequenceRef will let me add button sequences and FScreenshotRequest will let me make screenshots … but that’s further then I am now.
- I got as far as creating a new window and spawning a widget I’m trying to test.

Problem 1: new window shows up but it is blank/black, regardless of widget being loaded or not.

- Even GEngine-\>AddOnScreenDebugMessage does not show up … telling me something very core is missing.  
– I’m wondering if you can think of what that might be?  
– My current guess is that .AddWindow(…) accepts a [] content … which is empty for me.  
— can also be done with Window-\>SetContent( );  
— this does not explain why GEngine-\>AddOnScreenDebugMessage would not work and I’m trying to fix that first.

Problem 2: likely quite specific to our widget, but when our widget tries to run it fails on GameInstance-\>GetSubsystem internally in the engine well inside GameInstance::SubsystemCollection.h::SubsystemMap

- but this could also mean something early/core is missing like a general subsystem handler or the like …

Init code used (with some fluff edited)

```auto
IAutomationDriverModule::Get().Enable();
Window = FSlateApplication::Get().AddWindow( SNew(SWindow) ... .ClientSize(FVector2D(1920, 1080) ... /*[]*/ )
Window->ShowWindow();
Window->BringToFront(true);
FSlateApplication::Get().SetKeyboardFocus(Window ..)

Driver = IAutomationDriverModule::Get().CreateDriver();
EKeys::Initialize();
UGameInstance* GameInstance = NewObject<UGameInstance>(GEngine);
GameInstance->InitializeStandalone(); // creates WorldContext, UWorld?

const auto& WorldContext = GEngine->GetWorldContexts()[0];
auto Camera = WorldContext.World()->SpawnActor<ACameraActor>();
Camera->GetCameraComponent()->Activate(); // likely needed for visuals 
PlayerController = UGameplayStatics::GetPlayerController(WorldContext.World(), 0); // maybe needed for input?

GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("HERE 1 2 3")); // does now show up

```

---

<div class="post-metadata">

**Author:** ![sgoncharriot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sgoncharriot/32/88714_2.png) [@sgoncharriot](https://forums.unrealengine.com/u/sgoncharriot)\
**Post date:** [March 17, 2023, 4:13pm UTC](https://forums.unrealengine.com/t/spawning-a-window-and-widget-in-simple-automation-test/791753/2 "2023-03-17T16:13:07Z")

</div>

Update: got the stuff loading via `AutomationOpenMap` skipping all the window creation and anything to do with slate.

Unfortunately I now hit automation driver locking up the editor like here:

> [@Automation driver sequence played in an automation test freezes the engine when garbage collecting](https://forums.unrealengine.com/t/automation-driver-sequence-played-in-an-automation-test-freezes-the-engine-when-garbage-collecting/787858):
>
> I’m struggling with setting up an automation test using the automation framework with latent commands that uses the automation driver to simulate input. The test is supposed to go like this Spawn in enemy actor X Shoot with weapon and check if damage has been dealt Repeat with next enemy actor until all are checked This works fine for around 30 seconds, but then the engine will completely freeze with no error or nothing, I have to quit it manually. I know it probably has something do with ga…

---

<div class="post-metadata">

**Author:** ![sgoncharriot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sgoncharriot/32/88714_2.png) [@sgoncharriot](https://forums.unrealengine.com/u/sgoncharriot)\
**Post date:** [March 30, 2023, 7:05pm UTC](https://forums.unrealengine.com/t/spawning-a-window-and-widget-in-simple-automation-test/791753/3 "2023-03-30T19:05:13Z")

</div>

I ended up not using automation driver at all … just couldn’t figure out why it locked up in execute sequence.

Ended up using this:

```auto
DEFINE_LATENT_AUTOMATION_COMMAND_ONE_PARAMETER(TExecuteSequenceTypeButton, TArray<FKey>, Keys);
bool TExecuteSequenceTypeButton::Update()
{
	//
	// Input through Slate
	//
	FSlateApplication::Get().SetUserFocusToGameViewport(0);
	for (int i = 0; i < Keys.Num(); i++)
	{
		const FKey Key = Keys[i];
		uint32 KeyCode, CharCode;
		{
			const uint32* KeyCodePtr;
			const uint32* CharCodePtr;
			FInputKeyManager::Get().GetCodesFromKey(Key, KeyCodePtr, CharCodePtr);

			KeyCode = KeyCodePtr ? *KeyCodePtr : 0;
			CharCode = CharCodePtr ? *CharCodePtr : 0;
		}

		FModifierKeysState ModifierKeys(false, false, false, false, false, false, false, false, false);
		FKeyEvent KeyEvent(Key, ModifierKeys, 0, false, KeyCode, CharCode);

		FSlateApplication::Get().ProcessKeyDownEvent(KeyEvent);
		FSlateApplication::Get().ProcessKeyUpEvent(KeyEvent);
	}
	return true;
}

```
