简体   繁体   English

使用selenium,Nunit,Selenium Grid,C#,webdriver / remote control进行自动浏览器测试

[英]Automated Browser Testing using selenium, Nunit, Selenium Grid, C#, webdriver/remote control

I have been researching on how to automate browser testing for a number of weeks now using all kind of different methods. 我一直在研究如何使用各种不同的方法自动化浏览器测试数周。 Seleniums website is very vague on which is the best route to take. Seleniums网站非常模糊,这是最好的选择。

I have installed 我安装了

  1. Selenium Webdriver Selenium Webdriver
  2. Remote Control 遥控
  3. Selenium Grid Selenium Grid
  4. Apache Ant Apache Ant
  5. Nunit (and pretty much everything else you could need to do this) Nunit(以及你可能需要做的其他一切)

I finally give up trying on my own and want to know the best way to do this. 我终于放弃了自己的尝试,并想知道最好的方法。

I want to be able to 我希望能够

  1. Load the same webpage on a number of different browsers 在许多不同的浏览器上加载相同的网页
  2. Load the same webpage on a number of virtual machines(which I have set up) 在许多虚拟机(我已设置)上加载相同的网页
  3. Be able to take snapshots comparing the different browser results. 能够拍摄比较不同浏览器结果的快照。

I have knowledge of programming in C# and would prefer to run my tests through Nunit. 我对使用C#进行编程有所了解,并希望通过Nunit运行我的测试。

Can anyone give me directions or point me to a website that already has them? 任何人都可以给我指示或指向我已经拥有它们的网站吗? Thank you. 谢谢。

I have built up a test framework using junit with Selenium WebDriver that satisfies every one of your points. 我已经使用junit和Selenium WebDriver构建了一个测试框架,它满足了你的每一个要点。 While its not exactly what you're asking for, I feel it may be beneficial to you regardless. 虽然它不完全是你所要求的,但我觉得无论如何它对你都有好处。

Load the same webpage on a number of different browsers 在许多不同的浏览器上加载相同的网页

Using Selenium's grid, this is very simple to set up. 使用Selenium的网格,设置非常简单。 Set up some virtual machines with the environments you're looking to test in. In our environment, for example, we have a grid running with four nodes (as virtual machines) with a setup like the following 设置一些虚拟机,其中包含您要测试的环境。例如,在我们的环境中,我们有一个运行四个节点(作为虚拟机)的网格,其设置如下所示

  • Windows with IE7 and FireFox Windows与IE7和FireFox
  • Windows with IE8 and FireFox Windows与IE8和FireFox
  • Windows with IE9 and Firefox Windows与IE9和Firefox
  • Linux with FireFox Linux与FireFox

Note that Selenium recommends that only one instance of IE be allowed to run on the Windows nodes. 请注意,Selenium建议只允许在Windows节点上运行一个IE实例。 On each of the aforementioned nodes, there is one instance of the specified IE and five instances of the specified FF allowed to run at any given time. 在每个上述节点上,存在指定IE的一个实例,并且允许在任何给定时间运行指定FF的五个实例。 With the grid setup and the hub configured, firing off tests is a breeze. 通过网格设置和集线器配置,启动测试是轻而易举的。 In WebDriver, use the DesiredCapabilities object to set up the desired environment and then just send the test off and wait for the result to return. 在WebDriver中,使用DesiredCapabilities对象设置所需的环境,然后关闭测试并等待结果返回。

Platform desiredPlatform;
DesiredCapabilities desiredCapabilities;
desiredPlatform = Platform.LINUX;
desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setPlatform(desiredPlatform);
desiredCapabilities.setVersion("11");

WebDriver driver = new RemoteWebDriver("http://hubURL", desiredCapabilities);

Load the same webpage on a number of virtual machines(which I have set up) 在许多虚拟机(我已设置)上加载相同的网页

I solved this one by forcing the tests to run, albeit in an unconvential way, in a threaded manner. 我通过强制测试以螺旋方式以非常规的方式运行来解决这个问题。 Each JUnit test uses a shared thread library I put together which creates all the necessary RemoteWebDrivers needed in separate threads. 每个JUnit测试都使用我放在一起的共享线程库,它创建了在不同线程中所需的所有必需的RemoteWebDrivers。 Each of these threads runs simultaneously on its node while the parent thread sits and waits for all to terminate. 这些线程中的每一个在其节点上同时运行,而父线程处于等待并终止所有线程。 Then on to the next test which is run multithreaded as well. 然后进入下一个运行多线程的测试。

There were a couple problems I encountered such as retrieving the Junit stack traces in all of the child threads. 我遇到了一些问题,例如在所有子线程中检索Junit堆栈跟踪。 I solved this by redirecting Std.err to a bytestream on the parent thread. 我通过将Std.err重定向到父线程上的字节流来解决这个问题。 All errors get routed to that stream which I then convert to a string and print out to Std.out at the end of each test. 所有错误都被路由到该流,然后我转换为字符串并在每次测试结束时打印到Std.out The html pages generated at the end of the tests include Std.out which worked out perfectly. 在测试结束时生成的html页面包括完美的Std.out

Be able to take snapshots comparing the different browser results 能够拍摄比较不同浏览器结果的快照

While I have gotten this to work, there are some inherent problems with grabbing screenshots remotely. 虽然我已经开始使用它,但是远程抓取屏幕截图存在一些固有的问题。 IE will return black screenshots if the process is running as a service. 如果进程作为服务运行,IE将返回黑屏幕截图。 The workaround was to just run the jar from the command line and keep the user logged in, in which case the screenshots return correctly. 解决方法是从命令行运行jar并保持用户登录,在这种情况下屏幕截图正确返回。 This is a known issue in the browser and there really is no nice solution to the problem. 这是浏览器中的一个已知问题,并且确实没有很好的解决方案。 Taking screenshots works roughly like this 截图大致类似于此

WebDriver augmentedDriver = new Augmenter().augment(driver);
TakesScreenshot ss = (TakesScreenshot) augmentedDriver;
String base64Screenshot = ss.getScreenshotAs(OutputType.BASE64);
byte[] decodedScreenshot = Base64.decodeBase64(base64Screenshot.getBytes());
FileOutputStream fos = new FileOutputStream(new File(imageName));
fos.write(decodedScreenshot);
fos.close();

which saves the captured screenshot from the remote machine's running browser onto the local machine. 它将捕获的屏幕截图从远程计算机的运行浏览器保存到本地计算机上。

In reality, browser automation is still struggling to stabilize itself. 实际上,浏览器自动化仍在努力稳定自身。 There are a number of important features, such as the ones you're asking about, that just aren't implemented solidly that I know of in any framework. 有许多重要的功能,例如您所询问的功能,我在任何框架中都没有牢固地实现这些功能。 With time, though, I'm sure a lot of this will settle down and QA developers everywhere will rejoice. 但是,随着时间的推移,我相信很多这样的事情会得到解决,各地的QA开发人员都会欢欣鼓舞。

As for the 2nd point: instead of using Grid you can let your continuous integration server do the job. 至于第二点:您可以让持续集成服务器完成工作,而不是使用Grid。 In my company we use Jenkins and so called Configuration Matrix - it let's you run the same job on multiple Jenkins nodes. 在我的公司,我们使用Jenkins和所谓的配置矩阵 - 它让你在多个Jenkins节点上运行相同的工作。

As for the 1st one, I think Jenkins could be helpful here too. 至于第一个,我认为詹金斯在这里也会有所帮助。 You can run multiple jobs on the same node. 您可以在同一节点上运行多个作业。 Although I've never tried that so I am not perfectly sure. 虽然我从未尝试过,所以我并不十分确定。 And this is just an idea, I wouldn't really recommend such solution. 这只是一个想法,我不会真的推荐这样的解决方案。 You may also want to read this blog post describing how to run test in parallel using Selenium Grid. 您可能还想阅读此博客文章,描述如何使用Selenium Grid并行运行测试。 For people using Java I would recommend reading about parallel tests with TestNG . 对于使用Java的人,我建议阅读有关TestNG的并行测试

Your third point is a little bit vague. 你的第三点有点模糊。 What do you mean by snapshot? 快照是什么意思? And what kind of result you want to compare? 你想要比较什么样的结果?

Selenium RC is outdated and webdriver is more reliable way of creating selenium tests. Selenium RC已过时,webdriver是创建硒测试的更可靠方式。 I see the responses above cater more on java side. 我看到上面的回答更多地关注java方面。 Below mentioned is more information on how to achieve the questions asked here using C# and selenium webdriver 下面提到了有关如何使用C#和selenium webdriver实现此处提出的问题的更多信息

On how to setup the IDE (VS express), nUnit and selenium refer How to setup C#,nUnit and selenium client drivers on VSExpress for Automated tests 关于如何设置IDE(VS express),nUnit和selenium参考如何在VSExpress上设置C#,nUnit和selenium客户端驱动程序以进行自动化测试

On Creating simple script that launches a browser does few steps refer Creating Basic Selenium web driver test case using Nunit and C# 在创建启动浏览器的简单脚本时,请参考使用Nunit和C#创建基本Selenium Web驱动程序测试用例。

On how to Load the same webpage on a number of different browsers suggest referring How to invoke locally different types of browser driver using selenium and c# 关于如何在许多不同的浏览器上加载相同的网页建议参考如何使用selenium和c#本地调用不同类型的浏览器驱动程序

On Load the same webpage on a number of virtual machines(which I have set up) for this, you need to use Remote webdriver instead of normal webdriver. 在为此启用多个虚拟机(我已设置)上的相同网页时,您需要使用远程webdriver而不是普通的webdriver。 Also with remote webdriver, you can launch different types of browser. 使用远程webdriver,您可以启动不同类型的浏览器。 Refer this webpage How to invoke/run different type of web driver browser using remote webdriver in C# 请参阅此网页如何使用C#中的远程webdriver调用/运行不同类型的Web驱动程序浏览器

To take snapshot on different browser you can refer the link Capturing screen shots using remote/local webdriver in C#/Selenium webdriver 要在不同的浏览器上拍摄快照,您可以参考链接使用C#/ Selenium webdriver中的远程/本地webdriver捕获屏幕截图

You might also consider the free Telerik Testing Framework . 您可能还会考虑免费的Telerik测试框架 This is the underpinning for Telerik's commercial Test Studio product. 这是Telerik商业测试工作室产品的基础。 The Testing Framework provides cross-browser support, does a great job with dynamic content situations (AJAX), and also lets you handle OS-level dialogs like file upload/download dialogs. 测试框架提供跨浏览器支持,在动态内容情境(AJAX)方面做得很好,还可以处理操作系统级别的对话框,如文件上载/下载对话框。 You can also take snapshots of the browser at any point. 您也可以随时拍摄浏览器的快照。

You can wrap the framework inside whatever runner you prefer. 您可以将框架包装在您喜欢的任何跑步者中。 I've used NUnit and MbUnit without trouble. 我已经毫无困难地使用了NUnit和MbUnit。

There's also an option for a support package if you need help with your automation. 如果您需要有关自动化的帮助,还可以选择支持包。

(Disclosure: I work for Telerik as their Test Studio evangelist) (披露:我为Telerik工作,作为他们的Test Studio传道者)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium Grid使用C#/ NUnit进行并行测试 - Selenium Grid with parallel testing using C#/NUnit 在C#中使用Selenium WebDriver在每次测试后如何防止Nunit关闭浏览器 - How to prevent from Nunit closing browser after each test using Selenium WebDriver in C# 使用Selenium WebDriver和NUnit C#在Parallel中运行测试后,如何关闭多个浏览器窗口 - How to close down multiple browser windows after running tests in Parallel using Selenium WebDriver and NUnit C# 使用C#与Selenium WebDriver和NUnit一起调试Visual Studio 2013 - Debug Visual Studio 2013 Using C# with Selenium WebDriver and NUnit C#Selenium WebDriver测试 - c# selenium webdriver testing 如何使用 C# 在 Selenium WebDriver (Selenium 2) 中最大化浏览器窗口? - How to maximize the browser window in Selenium WebDriver (Selenium 2) using C#? 使用Selenium C#进行Internet Explorer自动化测试 - Internet Explorer automated testing using Selenium C# 使用Nunit在C#并行执行中的Selenium Grid - Selenium Grid in C# Parallel execution with Nunit 使用 selenium、specflow、nunit 进行并行本地测试,无需 selenium 网格 - Parallel local testing using selenium, specflow, nunit without selenium grid 在 C# 中离线时使用 Selenium-WebDriver 测试 Chrome - Testing Chrome using Selenium-WebDriver while offline in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM