Ejemplo n.º 1
0
bool FLandscapeEditorTest::RunTest(const FString& Parameters)
{
	//New level
	UWorld* NewMap = AutomationEditorCommonUtils::CreateNewMap();
	if (NewMap)
	{
		UE_LOG(LogLandscapeAutomationTests, Display, TEXT("Created an empty level"));
	}
	else
	{
		UE_LOG(LogLandscapeAutomationTests, Error, TEXT("Failed to create an empty level"));
		return false;
	}

	ADD_LATENT_AUTOMATION_COMMAND(FCreateLandscapeCommand());

	//For some reason the heightmap component takes a few ticks to register with the nav system.  We crash if we try to modify the heightmap before then.
	ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(1.0f));
	ADD_LATENT_AUTOMATION_COMMAND(FBeginModifyLandscapeCommand());
	ADD_LATENT_AUTOMATION_COMMAND(FEndModifyLandscapeCommand());

	//Wait for the landscape to update before the screenshot
	ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(1.0f));

	//Update the screenshot name, then take a screenshot.
	if (FAutomationTestFramework::GetInstance().IsScreenshotAllowed())
	{
		WindowScreenshotParameters ScreenshotParameters;

		//Find the main editor window
		TArray<TSharedRef<SWindow> > AllWindows;
		FSlateApplication::Get().GetAllVisibleWindowsOrdered(AllWindows);
		if (AllWindows.Num() == 0)
		{
			UE_LOG(LogLandscapeAutomationTests, Error, TEXT("ERROR: Could not find the main editor window."));
			return true;
		}

		//Create the path
		ScreenshotParameters.CurrentWindow = AllWindows[0];
		const FString TestName = TEXT("NewLandscapeTest");
		FString PathName = FPaths::AutomationDir() + TestName / FPlatformProperties::PlatformName();
		FPaths::MakePathRelativeTo(PathName, *FPaths::RootDir());
		ScreenshotParameters.ScreenshotName = FString::Printf(TEXT("%s/%d.png"), *PathName, GEngineVersion.GetChangelist());

		//Take a screenshot
		ADD_LATENT_AUTOMATION_COMMAND(FTakeEditorScreenshotCommand(ScreenshotParameters));
	}
	return true;
}
/**
 * Take screenshots of the SME window with each of the toolbar buttons toggled separately
 */
bool FStaticMeshEditorTest::RunTest(const FString& Parameters)
{
	TArray<FString> ButtonNamesToTestFor;
	FString LoadedObjectType = TEXT("EditorCylinder");
	FString MeshName;
	EditorViewButtonHelper::PerformStaticMeshFlagParameters AutomationParameters;
	WindowScreenshotParameters WindowParameters;

	//Pull from .ini the names of the buttons we want to test for
	GConfig->GetString( TEXT("AutomationTesting"), TEXT("EditorViewButtonsObject"), LoadedObjectType, GEngineIni);

	//Open static mesh in the editor and save out the window for the screenshots
	UObject* EditorMesh = (UStaticMesh*)StaticLoadObject(UStaticMesh::StaticClass(),
		NULL,
		*FString::Printf(TEXT("/Engine/EditorMeshes/%s.%s"), *LoadedObjectType, *LoadedObjectType),
		NULL,
		LOAD_None,
		NULL);
	FAssetEditorManager::Get().OpenEditorForAsset(EditorMesh);

	{
		TArray<TSharedRef<SWindow>> AllWindows;
		FSlateApplication::Get().GetAllVisibleWindowsOrdered(AllWindows);

		const FText ExpectedTitle = FText::FromString(LoadedObjectType);
		if (auto* Window = AllWindows.FindByPredicate([&](const TSharedRef<SWindow>& In) { return In->GetTitle().EqualTo(ExpectedTitle); }))
		{
			WindowParameters.CurrentWindow = *Window;
		}
	}

	if (!WindowParameters.CurrentWindow.IsValid())
	{
		AddError(TEXT("Could not find static mesh editor window"));
		return false;
	}

	//Grab the last opened Viewport (aka the asset manager)
	AutomationParameters.ViewportClient = static_cast<FStaticMeshEditorViewportClient*>(GEditor->AllViewportClients[GEditor->AllViewportClients.Num() - 1]);
	AutomationParameters.CommandType = EditorViewButtonHelper::EStaticMeshFlag::Wireframe; //Start it off at Wireframe because that is the first button we are attempting to press

	if (AutomationParameters.ViewportClient)
	{
		const FString BaseFileName = TEXT("StaticMeshEditorTest");
		FString TestName = FString::Printf(TEXT("%s/Base"), *BaseFileName);

		//Wait for the window to load and then take the initial screen shot		
		ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.5f));
		if( FAutomationTestFramework::GetInstance().IsScreenshotAllowed() )
		{
			AutomationCommon::GetScreenshotPath(TestName, WindowParameters.ScreenshotName, false);
			ADD_LATENT_AUTOMATION_COMMAND(FTakeEditorScreenshotCommand(WindowParameters));
			ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));
		}

		for(auto CurrentCommandType = 0; CurrentCommandType < EditorViewButtonHelper::EStaticMeshFlag::Max; ++CurrentCommandType)
		{
			TestName = FString::Printf(TEXT("%s/%s"), *BaseFileName, EditorViewButtonHelper::GetStaticMeshFlagName(AutomationParameters.CommandType));
			
			//Toggle the command for the button, take a screenshot, and then re-toggle the command for the button
			ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FPerformStaticMeshFlagToggle(AutomationParameters));
			ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));

			if( FAutomationTestFramework::GetInstance().IsScreenshotAllowed() )
			{
				//Take the screenshot
				AutomationCommon::GetScreenshotPath(TestName, WindowParameters.ScreenshotName, false);
				ADD_LATENT_AUTOMATION_COMMAND(FTakeEditorScreenshotCommand(WindowParameters));

				//Wait so the screenshots have a chance to save
				ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));
			}

			//Toggle the flag back off
			ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FPerformStaticMeshFlagToggle(AutomationParameters));
			
			//Increment to the next enum, so we can loop through all the types
			AutomationParameters.CommandType = (EditorViewButtonHelper::EStaticMeshFlag::Type)((int)AutomationParameters.CommandType + 1);
		}

		ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FCloseAllAssetEditorsCommand());
	}

	return true;
}
Ejemplo n.º 3
0
/**
 * Take screenshots of the SME window with each of the toolbar buttons toggled separately
 */
bool FStaticMeshEditorTest::RunTest(const FString& Parameters)
{
	TArray<FString> ButtonNamesToTestFor;
	FString LoadedObjectType = TEXT("EditorCylinder");
	FString MeshName;
	EditorViewButtonHelper::PerformStaticMeshFlagParameters AutomationParameters;
	WindowScreenshotParameters WindowParameters;

	//Pull from .ini the names of the buttons we want to test for
	GConfig->GetString( TEXT("AutomationTesting"), TEXT("EditorViewButtonsObject"), LoadedObjectType, GEngineIni);

	//Open static mesh in the editor and save out the window for the screenshots
	UObject* EditorMesh = (UStaticMesh*)StaticLoadObject(UStaticMesh::StaticClass(),
		NULL,
		*FString::Printf(TEXT("/Engine/EditorMeshes/%s.%s"), *LoadedObjectType, *LoadedObjectType),
		NULL,
		LOAD_None,
		NULL);
	FAssetEditorManager::Get().OpenEditorForAsset(EditorMesh);
	WindowParameters.CurrentWindow = FSlateApplication::Get().GetActiveTopLevelWindow();

	//Check that we have the right window (Tutorial may have opened on top of the editor)
	if( WindowParameters.CurrentWindow->GetTitle().ToString() != LoadedObjectType )
	{
		//Close the tutorial
		WindowParameters.CurrentWindow->RequestDestroyWindow();

		//Bring the asset editor to the front
		FAssetEditorManager::Get().FindEditorForAsset(EditorMesh,false);
		WindowParameters.CurrentWindow = FSlateApplication::Get().GetActiveTopLevelWindow();
	}

	//Grab the last opened Viewport (aka the asset manager)
	AutomationParameters.ViewportClient = static_cast<FStaticMeshEditorViewportClient*>(GEditor->AllViewportClients[GEditor->AllViewportClients.Num() - 1]);
	AutomationParameters.CommandType = EditorViewButtonHelper::EStaticMeshFlag::Wireframe; //Start it off at Wireframe because that is the first button we are attempting to press

	if (AutomationParameters.ViewportClient)
	{
		const FString BaseFileName = TEXT("StaticMeshEditorTest");
		FString TestName = FString::Printf(TEXT("%s/Base"), *BaseFileName);

		//Wait for the window to load and then take the initial screen shot		
		ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.5f));
		if( FAutomationTestFramework::GetInstance().IsScreenshotAllowed() )
		{
			AutomationCommon::GetScreenshotPath(TestName, WindowParameters.ScreenshotName, false);
			ADD_LATENT_AUTOMATION_COMMAND(FTakeEditorScreenshotCommand(WindowParameters));
			ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));
		}

		for(auto CurrentCommandType = 0; CurrentCommandType < EditorViewButtonHelper::EStaticMeshFlag::Max; ++CurrentCommandType)
		{
			TestName = FString::Printf(TEXT("%s/%s"), *BaseFileName, EditorViewButtonHelper::GetStaticMeshFlagName(AutomationParameters.CommandType));
			
			//Toggle the command for the button, take a screenshot, and then re-toggle the command for the button
			ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FPerformStaticMeshFlagToggle(AutomationParameters));
			ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));

			if( FAutomationTestFramework::GetInstance().IsScreenshotAllowed() )
			{
				//Take the screenshot
				AutomationCommon::GetScreenshotPath(TestName, WindowParameters.ScreenshotName, false);
				ADD_LATENT_AUTOMATION_COMMAND(FTakeEditorScreenshotCommand(WindowParameters));

				//Wait so the screenshots have a chance to save
				ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.1f));
			}

			//Toggle the flag back off
			ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FPerformStaticMeshFlagToggle(AutomationParameters));
			
			//Increment to the next enum, so we can loop through all the types
			AutomationParameters.CommandType = (EditorViewButtonHelper::EStaticMeshFlag::Type)((int)AutomationParameters.CommandType + 1);
		}

		ADD_LATENT_AUTOMATION_COMMAND(EditorViewButtonHelper::FCloseAllAssetEditorsCommand());
	}

	return true;
}