刚刚接触Telerik Test Studio?下载30天免费试用

多浏览器实例支持

在整个Telerik测试框架教程中,我们一直只关注单个浏览器实例“ActiveBrowser”,因为它是web自动化中最常见的使用。但是,在Manager对象的一个会话中支持多浏览器实例自动化。还支持在同一个会话中自动使用不同类型的浏览器。例如,在一个测试用例会话中,您可以自动地同时运行两个Internet Explorer浏览器实例和一个Firefox实例。这种类型的自动化可能不是很常见,但对于某些特定的场景可能很有用。(也就是说,你可以通过从一个实例中捕获浏览器图像,并将其与从另一个实例中捕获的图像进行比较,从而在不同的浏览器类型中进行位图比较)。

工作原理

“Manager”对象是使用Manager跟踪所有活动浏览器实例的主要对象。浏览器[]收藏。用户可以使用'Manager.LaunchNewBrowser()'方法启动任意数量的实例。每当一个新的浏览器启动时,“管理器”会创建一个新的“浏览器”对象,对应于该浏览器实例,并将其添加到浏览器[]集合中。从“管理器”中暴露的“ActiveBrowser”属性实际上是最后启动的浏览器,应该是“浏览器[]”集合中的最后一个浏览器实例。

注意:Manager.LaunchNewBrowser()在不带参数的情况下被调用时,启动在传入的Settings对象中设置的浏览器类型。通过使用Manager指定浏览器类型,可以显式地设置想要启动的浏览器类型。LaunchNewBrowser(BrowserType类型)重载。

下面的示例演示了如何利用多浏览器支持来在一个测试用例中自动化一个浏览器的多个实例。在web应用程序中执行并发测试时可能需要这样的测试。

//启动IE manager的一个新实例。InternetExplorer,真正的);//将此实例设置为active浏览器ie = Manager.ActiveBrowser;//启动Firefox manager的一个新实例。FireFox,真实);//将此实例设置为活动浏览器。//注意ActiveBrowser总是设置为最近启动的实例浏览器ff = Manager.ActiveBrowser//启动Firefox manager的另一个实例。FireFox,真实);//设置此实例。注意我们也可以使用Browser[]集合而不是使用ActiveBrowser的//。//在这个浏览器中ff2 = manager .浏览器[manager .浏览器。计数- 1];//你可以使用这些实例,就像你会使用'ActiveBrowser'实例一样。 ie.NavigateTo("http://www.google.com"); ff.NavigateTo("http://www.google.com"); ie.NavigateTo("http://www.live.com"); ff2.NavigateTo("http://www.kayak.com"); // You can also use the Window property off each browser to manipulate the // actual browser window ie.Window.SetFocus(); // close the first firefox instance // Note: Although the Window class off each browser object has a .close() method, // it is recommended to use the Browser.Close() method when closing browser instances // since it will also perform the disconnect and clean-up from the manager properly. // You can also choose to set a timeout as shown below to double check that the // browser has actually closed and its handle is no longer visible. ff.Close(40);
'启动IE Manager.LaunchNewBrowser(BrowserType. browser)的新实例。InternetExplorer,正确)”将此实例设置为活动浏览器Dim ie As ArtOfTest.WebAii.Core.Browser = Manager。启动Firefox manager的一个新实例。FireFox,真的)'将此实例设置为活动浏览器。'注意ActiveBrowser总是设置为最后一个启动实例Dim ff As ArtOfTest.WebAii.Core.Browser = Manager。启动Firefox manager的另一个实例。FireFox,真的)’设置此实例。注意我们也可以使用Browser[]集合而不是' using the ActiveBrowser '。’在这个Dim ff2 As ArtOfTest.WebAii.Core.Browser = manager .浏览器(manager .浏览器。计数- 1)'你就可以像使用'ActiveBrowser'实例一样使用这些实例。ie.NavigateTo("http://www.google.com") ff.NavigateTo("http://www.google.com") ie.NavigateTo("http://www.live.com") ff2.NavigateTo("http://www.kayak.com") '你也可以在每个浏览器上使用Window属性来操作'实际的浏览器窗口ie.Window.SetFocus() ' close the first firefox instance ' Note: Although the Window class off each browser object has a .close() method, ' it is recommended to use the Browser.Close() method when closing browser instances ' since it will also perform the disconnect and clean-up from the manager properly. ' You can also choose to set a timeout as shown below to double check that the ' browser has actually closed and its handle is no longer visible. ff.Close(40)
在本文中
Baidu
map