如何在自动化Selenium测试用例中传递命令给开发者控制台

huangapple 未分类评论83阅读模式
英文:

How to pass a command to dev console while automating selenium testcase

问题

我正在编写一个自动化测试用例,其中我需要在Chrome开发者控制台中传递一个特定的命令,以激活我测试用例所需的插件。
我正在使用Selenium测试框架进行我的测试。

测试流程如下:

  1. 打开主页
  2. 在开发者控制台上运行命令
  3. 继续执行其余的测试步骤

命令为:
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:

  1. Open the homepage
  2. Run the command on dev console
  3. 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.

huangapple
  • 本文由 发表于 2020年8月15日 03:48:11
  • 转载请务必保留本文链接:https://java.coder-hub.com/63419211.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定