Hi,
Is there any possibility to attach to just opened new WPF window in the main WPF application?
I would be really grateful if you could provide me with some C# examples.
Thank you in advance.
Stas.
Is there any possibility to attach to just opened new WPF window in the main WPF application?
Manager manager =
new
Manager(
false
);
manager.Start();
WpfApplication wpfApplication = manager.LaunchNewApplication(@
"Wpf.Application1.exe"
);
WpfWindow wpfWindow = wpfApplication.GetWindow(
"MainWindow"
);
wpfWindow.Find.ByName<Button>(
"button2"
).User.Click();
//The new WPF window is shown, how can I attach to it?
I would be really grateful if you could provide me with some C# examples.
Thank you in advance.
Stas.
4 Answers, 1 is accepted
0
Hello Stanislav,
If your window title has a dynamic portion, you can also use the tilde (~) character to indicate a partial match:
Kind regards,
Anthony
the Telerik team
You can connect to any window in the WPF application by its title, provided it's unique (different from other window titles):
WpfApplication app = Manager.LaunchNewApplication(@
"C:\WPFHelloWorld.exe"
);
ArtOfTest.WebAii.Wpf.WpfWindow newWin = app.GetWindow(
"TestStudio WPF Example"
);
TextBox tb = newWin.Find.ByName<TextBox>(
"txtName"
);
tb.SetText(
true
,
"TELERIK"
, 10, 100,
false
);
If your window title has a dynamic portion, you can also use the tilde (~) character to indicate a partial match:
ArtOfTest.WebAii.Wpf.WpfWindow newWin = app.GetWindow(
"~WPF Example"
);
Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
Stanislav
Top achievements
Rank 1
answered on 06 Jul 2012, 10:50 PM
Hello Anthony,
Unfortunately, provided code doesn't work. I tried it several times but all in vain. I tried to modified my application and show two wpf windows simultaneously after starting the application. In this case, GetWindow works perfectly and in manager two windows are tracked. I can't understand the source of issue.
The code is just simple in test application. After clicking on the button, new window is displayed:
When I added this code to the MainWindow() constructor of the first window, everything works fine.
I look forward to hearing from you. Thank you in advance.
Unfortunately, provided code doesn't work. I tried it several times but all in vain. I tried to modified my application and show two wpf windows simultaneously after starting the application. In this case, GetWindow works perfectly and in manager two windows are tracked. I can't understand the source of issue.
The code is just simple in test application. After clicking on the button, new window is displayed:
About about =
new
About();
about.show();
When I added this code to the MainWindow() constructor of the first window, everything works fine.
I look forward to hearing from you. Thank you in advance.
0
Stanislav
Top achievements
Rank 1
answered on 06 Jul 2012, 10:58 PM
I have just checked the same code but added Thread.Sleep(5000); after clicking on the button of the first form to wait for another window. And it works. The question is why there is no appropriate method to wait for another window?
Like:
Like:
WpfWindow about = app.GetWindow(
"About"
, 15);
//Wait about 15 seconds the window is displayed or throw an exception
0
Accepted
Hello Stanislav,
Note that the int timeout is in milliseconds.
Kind regards,
Anthony
the Telerik team
You can use WaitForWindow instead to achieve that scenario:
WpfWindow newWin = app.WaitForWindow(
"TestStudio WPF Example"
, 15000);
Note that the int timeout is in milliseconds.
Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings