简体   繁体   English

使用Selenium 2 / Web驱动程序与C#

[英]using Selenium 2 / Web Driver with C#

I have recently been looking at using Selenium 2 / webdriver for some automated web tests. 我最近一直在寻找使用Selenium 2 / webdriver进行一些自动化网络测试。 The API looks great. API看起来很棒。 However is it possible to record a test through the selenium-IDE and generate C# code for webdriver. 但是可以通过selenium-IDE记录测试并为webdriver生成C#代码。 I have found some Java formatters, but can't find anyway to do this for C#. 我找到了一些Java格式化程序,但无论如何都找不到为C#做这个。

Whilst the IDE's Export Test Case As/C# works, the code it generates is for the previous Selenium 1/RC not the new Selenium2/WebDriver API. 虽然IDE的导出测试用例As / C#可以工作,但它生成的代码是针对之前的Selenium 1 / RC而不是新的Selenium2 / WebDriver API。

In the newer versions of Selenium IDE this option now exists under File > Export Test Case As... 在较新版本的Selenium IDE中,此选项现在位于File> Export Test Case As ...

The option is called C# (NUnit) - WebDriver Backed . 该选项称为C#(NUnit) - WebDriver Backed

导出测试用例为...子菜单

If you're comfortable using the API i would suggest leaving the IDE behind you. 如果您对使用API​​感到满意,我建议您将IDE留在身后。 Whatever generator you will find, at some point it will generate an unmanageable mess. 无论你会发现什么样的发生器,在某些时候它都会产生无法控制的混乱。 I would suggest to take a look at the selenium design pattern at http://code.google.com/p/selenium/wiki/DesignPatterns . 我建议您在http://code.google.com/p/selenium/wiki/DesignPatterns上查看selenium设计模式。 For instance the pagefactory makes it pretty easy to quickly make pages accesible through properties and you will be doing so in a maintainable manner. 例如,pagefactory使得通过属性快速访问页面非常容易,并且您将以可维护的方式进行访问。

testcode is far more easy to refactor into maintainable code, whereas this is far more difficult for recorded testcases in selenium IDE testcode更容易重构为可维护的代码,而对于selenium IDE中记录的测试用例来说则要困难得多

也许我误解了一些东西,但是选项/格式下的Selenium IDE 1.0.10有一个C#条目,它将IDE测试转换为C#格式。

1.There is a plugin that can convert selinium 1 scripts to webdrive java. 1.有一个插件可以将selinium 1脚本转换为webdrive java。 Unfortuantely it is claimed that the current implementation of C# is incomplete. 不幸的是,据称目前C#的实施还不完整。 I think I will just use Java instead. 我想我只会用Java代替。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM