所以我创建了一个看起来像这样的滚动功能
Feature: Dynamic page scrolling
Scenario: Scrolling function
* def ScrollHeight = function(){return script("document.body.scrollHeight")
* def ScrollFunction = function(){ script("window.scrollTo(0,document.body.scrollHeight)")
* def ScrollingFunction =
"""
function(){
var height = ScrollHeight()
while(true)
{ ScrollFunction()
var newHeight = ScrollHeight()
if(height === newHeight )
break;
height = newHeight
}
}
"""
因此,我在测试场景所在的同一功能文件中创建了该文件,但我希望将其作为集中功能放入另一个功能文件中,也可以在其他功能文件中使用它。但是我将无法从其他功能文件调用ScrollHeight和ScrollFunction吗?
这就是我尝试在新功能文件Scrolling.feature中创建它的方式
Feature: Dynamic page scrolling Function
Scenario: Scrolling function
*def obj = read('classpath:Testing.feature')
* def ScrollingFunction =
"""
function(){
var height = obj.ScrollHeight()
while(true)
{ obj.ScrollFunction()
var newHeight = obj.ScrollHeight()
if(height === newHeight )
break;
height = newHeight
}
}
"""
我的Testing.feature文件看起来像
Feature: Testing
Background:
* def ScrollHeight = function(){return script("document.body.scrollHeight")
* def ScrollFunction = function(){
script("window.scrollTo(0,document.body.scrollHeight)")}
Scenario: Test-1
* def fun = call read('classpath:Scrolling.feature')
* call fun.ScrollingFunction
但这对我不起作用
所有方法(例如)script()
仅在driver
默认情况下实例化a之后才可用。因此,请确保在该driver <url>
步骤之后声明任何可重用的函数。
否则,您必须执行以下操作才能重新使用:
* def getScrollHeight =
"""
function() {
var driver = karate.get('driver');
return driver.script("document.body.scrollHeight");
}
"""
如果这不起作用,请创建一个快速入门示例,以便我们进行调查:https : //github.com/intuit/karate/tree/develop/examples/ui-test
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句