void FOpenAllAssetTests(OpenAssetParameters& AssetList)
{
	ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.5f));
	ADD_LATENT_AUTOMATION_COMMAND(FOpenAllofAssetTypeCommand(AssetList));
	ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.5f));
	ADD_LATENT_AUTOMATION_COMMAND(FCloseAllAssetEditorsCommand());
}
Exemplo n.º 2
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;
}
bool FOpenActualAssetEditors(const FString& Parameters)
{
	//start with all editors closed
	FAssetEditorManager::Get().CloseAllAssetEditors();

	// below is all latent action, so before sending there, verify the asset exists
	UObject* Object = StaticLoadObject(UObject::StaticClass(), NULL, *Parameters);
	if (!Object)
	{
		UE_LOG(LogEditorAutomationTests, Error, TEXT("Failed to find object: %s."), *Parameters);
		return false;
	}

	ADD_LATENT_AUTOMATION_COMMAND(FOpenEditorForAssetCommand(*Parameters));
	ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.5f));
	ADD_LATENT_AUTOMATION_COMMAND(FCloseAllAssetEditorsCommand());

	return true;
}
bool FMapPerformanceInEditor::RunTest(const FString& Parameters)
{
	//This is used to hold the data that is being captured.
	EditorPerfCaptureParameters EditorPerformanceData;

	//Get the map name from the parameters.
	FString MapName = Parameters;
	
	//Gets the main frame module to get the name of our current level.
	const IMainFrameModule& MainFrameModule = FModuleManager::GetModuleChecked< IMainFrameModule >("MainFrame");
	EditorPerformanceData.MapName = MainFrameModule.GetLoadedLevelName();

	//Duration variable will be used to indicate how long the test will run for.  Defaults to a minute.
	EditorPerformanceData.TestDuration = 60;

	if (!MapName.Equals(TEXT("CurrentLevel"), ESearchCase::IgnoreCase))
	{
		//Get the base filename for the map that will be used.
		EditorPerformanceData.MapName = FPaths::GetBaseFilename(MapName);

		//Load Map and get the time it took to take to load the map.
		ADD_LATENT_AUTOMATION_COMMAND(FEditorLoadMap(MapName));
	}

	//This gets the info we need from the automation test settings in the engine.ini.
	UAutomationTestSettings const* AutomationTestSettings = GetDefault<UAutomationTestSettings>();
	check(AutomationTestSettings);

	//Now we find the test timer(aka duration) for our test.
	for (auto Iter = AutomationTestSettings->EditorPerformanceTestMaps.CreateConstIterator(); Iter; ++Iter)
	{
		FString IterMapName = FPaths::GetBaseFilename(Iter->PerformanceTestmap.FilePath);
		if ((IterMapName == EditorPerformanceData.MapName || (IterMapName == TEXT("CurrentLevel"))))
		{
			EditorPerformanceData.TestDuration = ((Iter->TestTimer));
			//If the duration is equal to 0 then we simply warn the user that they need to set the test timer option for the performance test.
			//If the duration is less than 0 then we fail this test.
			if (EditorPerformanceData.TestDuration == 0)
			{
				UE_LOG(LogEditorAutomationTests, Warning, TEXT("Please set the test timer for '%s' in the automation preferences or engine.ini."), *EditorPerformanceData.MapName);
			}
			else
			if (EditorPerformanceData.TestDuration < 0)
			{
				UE_LOG(LogEditorAutomationTests, Error, TEXT("Test timer preference option for '%s' is less than 0."), *EditorPerformanceData.MapName);
				return false;
			}
		}
	}

	UE_LOG(LogEditorAutomationTests, Log, TEXT("Running the performance capture test for %.0i seconds on %s"), EditorPerformanceData.TestDuration, *EditorPerformanceData.MapName);
	
	//Move the viewport views to the first bookmark
	ADD_LATENT_AUTOMATION_COMMAND(FChangeViewportToFirstAvailableBookmarkCommand);
	ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.5f));

	//Wait for shaders to finish compile.
	ADD_LATENT_AUTOMATION_COMMAND(FWaitForShadersToFinishCompiling);
	
	//Grab the performance numbers based on the duration.
	ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(0.5f));
	ADD_LATENT_AUTOMATION_COMMAND(FEditorPerfCaptureCommand(EditorPerformanceData));

	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;
}
/**
 * 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;
}