白色测试-文件夹浏览器对话框
本文关键字:浏览器 对话框 文件夹 测试 白色 | 更新日期: 2023-09-27 18:26:21
我在获取白色的FolderBrowserDialog时遇到问题。我认为它应该被指定为模态窗口,但事实并非如此。
DialogService.cs:中的FolderBrowserDialog
public FolderBrowserResult ShowFolderbrowserDialog(string storageFolder)
{
var dialog = new FolderBrowserDialog
{
Description = storageFolder
};
var result = new FolderBrowserResult
{
Result = dialog.ShowDialog() != DialogResult.OK,
Path = dialog.SelectedPath
};
return result;
}
点击浏览按钮后调用的方法:
private void OnBrowseForTargetFolder(object sender, RoutedEventArgs e)
{
var result = dialogService.ShowFolderbrowserDialog(Properties.Resources.StorageFolder);
if (result.Result) return;
Project.PathToStorage = result.Path;
completePath = string.Format("{0}''{1}", result.Path, Guid.NewGuid());
Directory.CreateDirectory(completePath);
}
测试:
public class LoggerTests
{
private Application application;
private MainWindowPage mainWindowPage;
[TestInitialize]
public void TestInitialize()
{
application = Application.Launch(@"PML.exe");
StartBlankApplication();
}
[TestMethod]
public void StartExistingProject()
{
mainWindowPage.StartExistingProjectButton.Click();
var modalWindows = new List<Window>();
Retry.For(() =>
{
modalWindows = mainWindowPage.applicationWindow.ModalWindows();
}, TimeSpan.FromSeconds(5));
var mod = modalWindows;
}
private MainWindowPage StartBlankApplication()
{
var appWindow = application.GetWindow("PML");
mainWindowPage = new MainWindowPage(appWindow);
return mainWindowPage;
}
private NewProjectConfigurationPage ConfigureBlankProject()
{
Window secondAppWindow = null;
Retry.For(() =>
{
secondAppWindow = application.GetWindow("PML");
}, TimeSpan.FromSeconds(5));
var newProjectConfiguration = new NewProjectConfigurationPage(secondAppWindow);
newProjectConfiguration.VesselName.Text = "Test";
newProjectConfiguration.BrowseButton.Click();
return newProjectConfiguration;
}
}
在StartExistingProject中,方法存在变量mod为空的问题。并且没有打开FolderBrowserDialog。但当我正常运行应用程序时,一切都运行正常。
已解决-必须为模式对话框设置所有者。所以
var wrapper = new WindowWrapper(this);
dialog.ShowDialog(wrapper)
解决了我的问题。