using Xunit; using BlazorTestAutomation.Pages; using BlazorTestAutomation.Utilities; using Xunit.Abstractions; using System.IO; namespace BlazorTestAutomation.Tests { public class BlazorTests : BaseTest { public BlazorTests(ITestOutputHelper output) : base(output) { } [Fact] public void Regression_Blazor_Folder() { Random random = new Random(); int randomNumber = random.Next(1000, 10000); // Generates a number from 1000 to 9999 ///Step 1. Able to access the landing page of TesterBlazorApp: var blazorPage = new BlazorPages(Driver); /// Step1. Navigate to site Access https://testerblazorapp-csdfadhfczhee0cv.westus-01.azurewebsites.net/ Driver.Navigate().GoToUrl(BaseUrl); System.Threading.Thread.Sleep(9000); // 5 second delay to wait the page be loaded ///Step 2. Click on New Folder button. Type in unique parent-folder name. string folderName = "New Folder"; folderName = folderName + "_" + randomNumber.ToString(); blazorPage.ClickFolderButton(); blazorPage.TypeUniqueParentFolder(folderName); ///Verified that able to create a new folder Assert.True(blazorPage.HandleTemporalMessage("Created Folder. Successfully"), "New folder was not created successfully."); System.Threading.Thread.Sleep(5000); // 5 second delay ///Step 3. Able to double click on that newly created folder and clicked on New Folder button again. Typed in unique subfolder name. string subFolderName = "New SubFolder"; randomNumber = random.Next(1000, 10000); // Generates a number from 1000 to 9999 subFolderName = subFolderName + "_" + randomNumber.ToString(); blazorPage.DoubleClick_OverFolder(folderName); System.Threading.Thread.Sleep(2000); // 5 second delay blazorPage.ClickFolderButton(); blazorPage.TypeUniqueParentFolder(subFolderName); ///Verified that able to create a new subfolder Assert.True(blazorPage.HandleTemporalMessage("Created Folder. Successfully"), "New Subfolder was not created successfully."); ///Step 4. Able to select the parent folder then right-clicked. Selected Rename option from the context menu and typed in a new unique name. blazorPage.Go_Home("Home"); blazorPage.RightClick_OverFolder(folderName); blazorPage.Click_Over_RightMenuItem("Rename"); folderName = "Updated Folder" + "_" + randomNumber.ToString(); blazorPage.TypeUniqueParentFolder(folderName); ///Verified that able to change the folder name without issues Assert.True(blazorPage.HandleTemporalMessage("Renamed Folder. Successfully"), "Folder was not renamed successfully."); System.Threading.Thread.Sleep(5000); // 5 second delay blazorPage.DoubleClick_OverFolder(folderName); System.Threading.Thread.Sleep(5000); // 5 second delay blazorPage.DoubleClick_OverFolder(folderName); ///Step 5. Able to select the subfolder then right-clicked. Selected Rename option from the context menu and typed in an existing folder name. blazorPage.RightClick_OverFolder(subFolderName); blazorPage.Click_Over_RightMenuItem("Rename"); string subFolderTempName = subFolderName.ToLower(); blazorPage.TypeUniqueParentFolder(subFolderTempName); ///Verified that there’s a warning message: Folder name already exists. Assert.True(blazorPage.HandleTemporalMessage("Item(s) already exists in selected folder."), "Folder was not renamed successfully."); System.Threading.Thread.Sleep(5000); // 5 second delay ///Step 6. Able to select on the subfolder then right-clicked. Selected Delete option from the context menu. blazorPage.RightClick_OverFolder(subFolderName); blazorPage.Click_Over_RightMenuItem("Delete"); blazorPage.Click_Over_Popup_Button("Cancel"); /// Verified that the delete modal is correct. Selected on Cancel button. Assert.True(blazorPage.Verify_Element_Exists(subFolderName), "Folder does not exists."); ///Step 7. Able to select on the subfolder again then right-clicked. Selected Delete option from the toolbar. System.Threading.Thread.Sleep(5000); // 5 second delay blazorPage.RightClick_OverFolder(folderName); blazorPage.Click_Over_RightMenuItem("Delete"); blazorPage.Click_Over_Popup_Button("Delete Item"); blazorPage.Go_Home("Home"); ///Verified if the delete modal is correct. Selected on Delete Item button. Verified the modal disappears and the sub-folder is deleted Assert.True(blazorPage.HandleTemporalMessage("Deleted Successfully"), "Folder was not deleted successfully."); } [Fact] public void Regression_Blazor_File() { Random random = new Random(); int randomNumber = random.Next(1000, 10000); // Generates a number from 1000 to 9999 var blazorPage = new BlazorPages(Driver); ///Step 1. Able to access the landing page of TesterBlazorApp: Driver.Navigate().GoToUrl(BaseUrl); System.Threading.Thread.Sleep(9000); // 5 second delay to wait the page be loaded string folderName = "New Folder"; folderName = folderName + "_" + randomNumber.ToString(); blazorPage.ClickFolderButton(); blazorPage.TypeUniqueParentFolder(folderName); System.Threading.Thread.Sleep(5000); // 5 second delay blazorPage.DoubleClick_OverFolder(folderName); System.Threading.Thread.Sleep(2000); // 5 second delay //Step 3. Able to click on Upload button that is within the component. Verified that Upload File modal is displayed blazorPage.ClickUploadButton(); //Step 4. Able to select a single file in any of these supported format (.png,.svg,.gif,.jpg,.jpeg,.md,.txt,.xml). Verified that able to successfully upload the file blazorPage.ClickSelectAlertButton(); //// Upload file - NEW APPROACH //string filePath = @"C:\Users\ssalomecespe\Downloads\deletefolder.txt"; //blazorPage.UploadFileDirectly(filePath); //Thread.Sleep(3000); //// Verify upload //if (!blazorPage.IsFileUploaded(Path.GetFileName(filePath))) //{ // throw new Exception("File upload verification failed"); //} // Works with both single and multiple files //string singleFilePath = @"C:\Users\ssalomecespe\Downloads\testfile.txt"; //blazorPage.UploadFilesDirectly(new List { singleFilePath }); //// Verification (using either method) //bool isUploaded = blazorPage.IsFileUploaded("testfile.txt"); var files = new List { @"C:\Users\ssalomecespe\Downloads\deletefolder.txt", @"C:\Users\ssalomecespe\Downloads\deletefolder2.txt", @"C:\Users\ssalomecespe\Downloads\deletefolder3.txt" }; blazorPage.UploadFilesDirectly(files); bool allUploaded = blazorPage.AreFilesUploaded(files.Select(Path.GetFileName)); } } }