英文:
How to pass a command to dev console while automating selenium testcase
问题
我正在编写一个自动化测试用例,其中我需要在Chrome开发者控制台中传递一个特定的命令,以激活我测试用例所需的插件。
我正在使用Selenium测试框架进行我的测试。
测试流程如下:
- 打开主页
- 在开发者控制台上运行命令
- 继续执行其余的测试步骤
命令为:
top.startTour("123", 0)
英文:
I am writing an automation test case wherein i need to pass a specific command on chrome dev console to activate a plugin required for my test case.
I am using selenium framework for my tests.
This is the flow:
- Open the homepage
- Run the command on dev console
- Continue with rest of the test steps
top.startTour("123", 0) is the command
答案1
得分: 0
我猜你想执行一些Javascript代码?
如果是这种情况,你可以通过在你的测试中使用JavascriptExecutor
来实现。
在你的情况下,你的代码应该类似于这样:
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) webdriver;
javascriptExecutor.executeScript("top.startTour('123', 0);");
这里有一篇关于如何更详细地使用JavascriptExecutor
的文章。
英文:
I assume you want to execute some Javascript?
If that is the case you can do so by using the JavascriptExecutor
in you test.
In your case your code should look something like this
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) webdriver;
javascriptExecutor.executeScript("top.startTour('123', 0)");
Here is a nice article on how to use the JavascriptExecutor
in more detail.
专注分享java语言的经验与见解,让所有开发者获益!
评论