편집 :이 질문을 구성 할 때 대상 창은 모달 창 이었으므로 시도하려는 방식이 잘못되었음을 알리지 못했습니다. 나는 GetWindow가 아니라 GetModal을 사용 했어야했다. 미래의 여행자를위한 잠재적 참고 자료로 여기에 남겨주세요TestStack.White 왜 Application.GetWindows가 있지만 .GetWindow가없는 창을 찾을 수 있습니까?
나는 상속 한 거대한 WPF 응용 프로그램을위한 TestStack.White로 몇 가지 테스트를 작성하려고합니다. 자식 창을 만든 사례가 하나 있는데 여기에 대한 참조가 필요합니다. Application.GetWindows에 대한 호출 결과를 반복해서 찾을 수는 있지만 상상할 수있는 Application.GetWindow의 어떤 구체화로도 찾을 수 없습니다.
다음 예에서 설명합니다 (name은 문자열 임). 이 윈도우는 foreach 루프에서 찾을 수 있습니다. (내가 다른 것을 클릭 한 후에 윈도우 시간을주기 위해 반복하기 전에 잠깐 잠을 자면됩니다.) 솔직히 말해서이 연습의 전체적인 점은 이 Thread.Sleep 코드 - 냄새 제거, 그래서 GetWindow 및 내장 된 대기 사용하고 싶습니다.
Thread.Sleep(1000);
foreach (Window window in app.GetWindows())
{
if (window.AutomationElement.Current.Name == name)
{
Assert.AreEqual(window.Title, name); // passes.. they match
Assert.AreEqual(window.AutomationElement.Current.Name, name); // passes.. they match
var aIdCheck = window.AutomationElement.Current.AutomationId; // empty string
}
}
try // this fails.. (after 30s)
{
var testGetWindow = app.GetWindow(name);
}
catch (Exception ex) { }
try // this fails too... (after 5s)
{
var testGetWindow = app.GetWindow(SearchCriteria.ByNativeProperty(AutomationElement.NameProperty, name), InitializeOption.NoCache);
}
catch (Exception ex) {}
try // you guessed it.. fail..
{
var testGetWindow = app.GetWindow(SearchCriteria.ByText(name), InitializeOption.NoCache);
}
catch (Exception ex) {}
내 문제가 나왔다. 내가 쫓아 가고있는 것이 모달 창 이었기 때문에 GetModal을 사용해야하고 GetWindow를 사용해서는 안된다는 것이었다. 내가 화이트와 같이 학습을 위해 얻은 것입니다. :) 대답으로 표시하기. 문제를 오해하지 않았다면 사용하기에 좋은 접근 방법이 될 수 있기 때문입니다. –
@RookieRick Thanks. 그것은 흥미로운 해결책이기도합니다. 나는 그것을 생각하지 않았을 것이다. – Rescis