如何将 selenium IDE 中记录的命令转换为 Java?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19358183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert commands recorded in selenium IDE to Java?
提问by Amith
Is there any application or simple way to convert all the commands recorded by Selenium IDE
to Java (Selenium WebDriver)
?
It would be a lot more easier and would save a lot of time.
是否有任何应用程序或简单的方法可以将记录的所有命令转换Selenium IDE
为Java (Selenium WebDriver)
?这会容易得多,并且会节省很多时间。
Any suggestions will be appreciated. Thanks!
任何建议将不胜感激。谢谢!
采纳答案by Pavel Janicek
In my Selenium IDE version 2.4.0 it is easy as pie:
在我的 Selenium IDE 版本 2.4.0 中,它很简单:
- Record testcase in Selenium IDE
- Click File - Export Test Case As - Java / JUnit4 / WebDriver
- Save File as .java
- 在 Selenium IDE 中记录测试用例
- 单击文件 - 将测试用例导出为 - Java / JUnit4 / WebDriver
- 将文件另存为 .java
And here you go! Your testcase is converted to WebDriver ;)
给你!您的测试用例已转换为 WebDriver ;)
回答by Ankit jain
In my Selenium IDE version 2.4.0
在我的 Selenium IDE 2.4.0 版中
Record a new test case with the help of Selenium IDE
1) Click on File a primary nav bar
2) check drop down is displayed
3) select on Export test case as
4) Check you can convert selenium test case in any language EG: Java / JUnit4 / WebDriver
Save File as .java
Your testcase is converted to WebDriver
check image
检查图像
回答by Ripon Al Wasim
There are 2 ways to convert a recorded tests(HTML format) into Java code in Selenium IDE:
在 Selenium IDE 中,有两种方法可以将录制的测试(HTML 格式)转换为 Java 代码:
1st way:To see the Java code directly in Selenium IDE
第一种方式:直接在 Selenium IDE 中查看 Java 代码
- Go to Options -> Options...
- At "Selenium IDE Options" window: Check the check box for "Enable experimental features" and click OK button
- Options -> Format -> Java / JUnit4 / WebDriver
- Click OK button from "JavaScript Application" pop up -> You will see the desired Java source code for your recorded tests
- 转到选项 -> 选项...
- 在“Selenium IDE 选项”窗口中:选中“启用实验功能”复选框,然后单击“确定”按钮
- 选项 -> 格式 -> Java / JUnit4 / WebDriver
- 单击“JavaScript 应用程序”弹出窗口中的“确定”按钮 -> 您将看到记录测试所需的 Java 源代码
2nd way:By exporting recorded test case(HTML format) into java file:
第二种方式:通过将记录的测试用例(HTML格式)导出到java文件中:
- Record your tests in HTML format by using Selenium IDE
- File -> Export Test Case As -> Java / JUnit4/ WebDriver
- Save the file (it would be saved as .java)
- Open the java file you saved in any text editor or IDE such as, Notepad++, Notepad, Wordpad, Eclipse, IntelliJ IDEA etc. (You can see the expected Java Selenium source code)
- 使用 Selenium IDE 以 HTML 格式记录您的测试
- 文件 -> 将测试用例导出为 -> Java/JUnit4/WebDriver
- 保存文件(它将被保存为 .java)
- 打开您在任何文本编辑器或 IDE 中保存的 java 文件,例如 Notepad++、Notepad、Wordpad、Eclipse、IntelliJ IDEA 等(您可以看到预期的 Java Selenium 源代码)
There is another way to convert Selenium IDE command individually to any language. The following steps for java:
还有另一种方法可以将 Selenium IDE 命令单独转换为任何语言。java的步骤如下:
- Open Firefox -> Open Selenium IDE
- Record some steps of your test
- In Selenium IDE: Go to Options | Clipboard Format and select Java / TestNG / WebDriver
- Right click any command in Selenium IDE you recorded -> Click Copy
- Paste in any editor (such as NotePad, Wordpad etc. OR any IDE you are using such as eclipse, IntelliJ IDEA)
- The command will be pasted as Java format
- 打开 Firefox -> 打开 Selenium IDE
- 记录一些测试步骤
- 在 Selenium IDE 中:转到选项 | 剪贴板格式并选择 Java / TestNG / WebDriver
- 右键单击您录制的 Selenium IDE 中的任何命令 -> 单击复制
- 粘贴到任何编辑器中(例如 NotePad、Wordpad 等。或者您正在使用的任何 IDE,例如 eclipse、IntelliJ IDEA)
- 该命令将粘贴为 Java 格式
Note: In similar way you can convert individual Selenium IDE command to C#, Python and many more you want.
注意:以类似的方式,您可以将单独的 Selenium IDE 命令转换为 C#、Python 以及更多您想要的命令。
回答by Harry G.
Update: Starting from SeleniumIDE 3.x unfortunately both functions mentioned in previous answers "Export" and "Options->Format" were removed (reason is the porting to the new WebExtensions format of Firefox and Chrome).
更新:不幸的是,从 SeleniumIDE 3.x 开始,前面的答案“导出”和“选项->格式”中提到的两个功能都被删除了(原因是移植到 Firefox 和 Chrome 的新 WebExtensions 格式)。
But a current alternative is Katalon Recorderwhich is available for Chromeand Firefox.
但是当前的替代方案是Katalon Recorder,它可用于Chrome和Firefox。
Katalon Recorder has an "Export" button and can export 3 Selenium formats, with TestNG, with JUnit and even with Thoughtworks WebDriverBackedSelenium and JUnit.
Katalon Recorder 有一个“导出”按钮,可以导出 3 种 Selenium 格式,使用 TestNG,使用 JUnit,甚至使用 Thoughtworks WebDriverBackedSelenium 和 JUnit。
Just press "Export", choose your format, than "Copy to Clipboard" or "Save as file...".
只需按“导出”,选择您的格式,而不是“复制到剪贴板”或“另存为文件...”。
回答by imaginabit
Im using selenium ide firefox extension and find this looking for how to export tests to javascript
我使用 selenium ide firefox 扩展并找到这个寻找如何将测试导出到 javascript
I found you can export to C# NUnit, C# xUnit, Java JUnit, JavaScript Mocha, Python ,pytest, Ruby RSpec just right click on the test and a menu with export options appears
我发现你可以导出到 C# NUnit、C# xUnit、Java JUnit、JavaScript Mocha、Python、pytest、Ruby RSpec 只需右键单击测试,就会出现一个带有导出选项的菜单
some times you can't find the easy way
有时你找不到简单的方法