有没有办法避免空手道中chromedriver的硬编码路径 [英] is there a way to avoid the hardcoded path for chromedriver in karate

查看:90
本文介绍了有没有办法避免空手道中chromedriver的硬编码路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我想在空手道中使用chromedriver

不想不想提供硬编码路径C:\ Software \ chromedriver_win32 \ chromedriver.exe

原因:-其他团队成员可能在同一路径上没有chromedriver.

 功能:选中以打开两个浏览器场景:使用chromeDriver打开chrome*配置驱动程序= {type:'chromedriver',可执行文件:'C:\\ Software \\ chromedriver_win32 \\ chromedriver.exe'}*驱动程序"https://www.google.com" 

有任何自动处理此问题的方法吗?以便通过 maven 下载并由 Karate 进行下载.

我们无需手动下载(chromedriver/geckodriver),而是将其放入相对文件夹(在项目中)或系统文件夹中

我已阅读文档,其中说它会在Windows或我们提供的系统PATH中搜索系统路径.

我可能会丢失的任何东西,请纠正我.

解决方案

大多数团队都使用 PATH 默认值,因为它更易于在每台计算机上自定义.

但是,如果您希望空手道通过Maven或类似的方式自动下载驱动程序,那么抱歉,不支持,也从未计划过.

也许您应该看一下 WebDriverManager -只需将其添加到依赖项中并使用它,简单.

此外,您还应该花一些时间来了解空手道的配置系统: https://github.com/intuit/空手道#configuration

因此,假设您具有以下 karate-config.js :

  function fn(){返回{可执行文件:'C:/some/dir/chromedriver.exe'}} 

现在,在任何功能文件中,变量 executable 都将被设置并可以使用.

  *配置驱动程序= {类型:'chromedriver',可执行文件:'#(executable)'} 

也请查看此答案: https://stackoverflow.com/a/60581024/143475

您可以研究Karate用于CI的项目,它具有一些高级技巧:

In the below code i would like to use chromedriver in Karate

but do not want to give the hardcoded path C:\Software\chromedriver_win32\chromedriver.exe

Reason :- Other team members might not have the chromedriver at the same path.

Feature: Check to open both browser

 Scenario: open chrome with chromeDriver
* configure driver = {type:'chromedriver' , executable:'C:\\Software\\chromedriver_win32\\chromedriver.exe'}
* driver 'https://www.google.com'

Any ways of handling this automatically? so that it's downloaded via maven and Karate picks it up.

Instead of we downloading it(chromedriver/geckodriver) manually and putting in a relative folder(in project) or system folder

I have read the documentation which says it search in system PATH in windows or the one we give.

Anything which i might be missing please correct me.

解决方案

Most teams use the PATH default because it is easier to customize per machine.

But if you are expecting Karate to automatically download a driver via Maven or something like that, sorry that's not supported nor is it ever planned.

Maybe you should look at WebDriverManager - just add it to your dependencies and use it, should be simple.

Also you should spend some time understanding Karate's config system: https://github.com/intuit/karate#configuration

So assuming that you have the following karate-config.js:

function fn() {
  return { executable: 'C:/some/dir/chromedriver.exe' }
}

Now in any feature file the variable executable will be set and available to use.

* configure driver = { type:'chromedriver', executable: '#(executable)' }

Take a look at this answer also: https://stackoverflow.com/a/60581024/143475

And you can study the project that Karate uses for CI, it does some advanced tricks: https://github.com/intuit/karate/tree/master/karate-e2e-tests/src/test/java/driver - and is also an example of how with Docker, you don't need to rely on a locally installed "webdriver" executable.

这篇关于有没有办法避免空手道中chromedriver的硬编码路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆