You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Login.feature后执行waitForEnabled报错:ReferenceError未定义

问题解决:Karate调用Login.feature后无法使用waitForEnabled

问题原因

你错误地将read('Login.feature@login-chrome')的返回值赋值给test变量,并试图通过这个变量调用UI操作方法。实际上,带场景标签的read调用返回的是feature执行后的结果(若有return语句),而非Karate的驱动实例。Karate的UI操作关键字(如waitForEnabled)是全局上下文可用的,不需要通过变量访问。

修复步骤

  1. 修正Login.feature的调用方式
    在Background中,不要用def接收返回值,直接用call关键字执行Login.feature,这样会共享驱动上下文:

    Background:
        # Transaction Admin Page
        * def parameters = read('configs.json')
        * call Login.feature@login-chrome
    
  2. 移除多余的变量前缀
    Scenario中直接使用全局UI关键字,不需要test.前缀:

    @transactionadmin-workflow-updatename
    @test
    Scenario: Search
        # Open Transaction Admin Page
        * waitForEnabled(administrationButtonXpath).click()
        And delay(2000).screenshot()
    

额外说明

确保Login.feature中正确初始化并保留了驱动实例,比如包含configure driver的配置步骤,且没有在Login.feature结尾关闭驱动。当你通过call执行Login.feature后,当前feature会继承驱动上下文,所有UI操作可以直接使用全局关键字完成。

内容的提问来源于stack exchange,提问作者joshKDev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 10:22:13