2017-02-15 23 views
1

好吧,所以我使用累计规则在userextension和由于某种原因Selenium将继续说我的标签为我的gotoIF不存在。有没有人有任何想法为什么或如何解决这个问题?语言是JS(JavaScript)的硒IDE汇总规则与gotoIf和标签

var manager = new RollupManager(); 

manager.addRollupRule({ 
name: 'FRLanguageCheck' 
, description: 'Check the language to make sure its in french' 
, args: [ 
], commandMatchers: [ 
] 
, getExpandedCommands: function(args) { 
var commands = []; 

commands.push({ 
command: 'storeTextPresent' 
, target: 'English' 
, value: 'LanguageCheck' 
}); 
commands.push({ 
command: 'gotoIf' 
, target: '${LanguageCheck}==false' 
, value: 'StepWithWrongLanguage' 
}); 
commands.push({ 
command: 'gotoIf' 
, target: '${LanguageCheck}==true' 
, value: 'StepWithRightLanguage' 
}); 
commands.push({ 
command: 'label' 
, target: 'StepWithWrongLanguage' 
, value: '' 
}); 
commands.push({ 
command: 'click' 
, target: 'TestLanguageChangeToFrench failed. The site was not in French.' 
, value: '' 
}); 
commands.push({ 
command: 'label' 
, target: 'StepWithRightLanguage' 
, value: '' 
}); 
return commands; 
} 
}); 

这是错误信息,我从硒

[error] [selblocks] Error @1: [rollup|FRLanguageCheck] Target label 'StepWithRightLanguage' is not found. 
[warn] [selblocks] __Stack Trace__ 
[error] Unexpected Exception: Error: @1: [rollup|FRLanguageCheck] Target label 'StepWithRightLanguage' is not found.. 

回答

0

好得到,所以我没有用硒与任何其他语言比XML这样的道歉任何错误。欢迎编辑。 (这是java吗?)

你不需要指定true和false,但我确实理解你的雇主可能是在某些特定的事情之后。你将要分开gotoIf陈述,因为有人会隐瞒另一个。

var manager = new RollupManager(); 

manager.addRollupRule({ 
name: 'FRLanguageCheck' 
, description: 'Check the language to make sure its in french' 
, args: [ 
], commandMatchers: [ 
] 
, getExpandedCommands: function(args) { 
var commands = []; 

commands.push({ 
command: 'storeTextPresent' 
, target: 'English' 
, value: 'LanguageCheck' 
}); 
commands.push({ 
command: 'gotoIf' 
, target: '${LanguageCheck}==false' 
, value: 'StepWithWrongLanguage' 
}); 
commands.push({ 
command: 'label' 
, target: 'StepWithWrongLanguage' 
, value: '' 
}); 
commands.push({ 
command: 'storeTextPresent' 
, target: 'English' 
, value: 'LanguageCheck' 
}); 
commands.push({ 
command: 'gotoIf' 
, target: '${LanguageCheck}==true' 
, value: 'StepWithRightLanguage' 
}); 
commands.push({ 
command: 'click' 
, target: 'TestLanguageChangeToFrench failed. The site was not in English.' 
, value: '' 
}); 
commands.push({ 
command: 'label' 
, target: 'StepWithRightLanguage' 
, value: '' 
}); 
return commands; 
} 
}); 

我会建议只有一个gotoIf语句,因为目前你只有一个命令。如果你确实用了两个,那么你可能需要添加一串命令到StepWithWrongLanguage,以便它改变语言,如果它的法语,然后第二个gotoIf语句可以验证它实际上已经改变。

+0

你的脚本似乎是正确的,虽然你似乎插入});命令.push({在一个straith行中,并忘记它在另一个bug中,我将通过该校正来测试它 编辑:新命令也返回相同的错误宣布标签不存在。标签到Selenium脚本运行它的过程,但相反,忽略标签完全去我的Click错误行straith。可能是汇总不能使用标签命令? –

+0

注意:我尝试了你的想法再次与一个标签和gotoIf但汇总不要说标签不存在,如果我在Selenium脚本中添加了标签,它会忽略它并跳到点击错误行,尽管产生了'true'结果 –

+0

谢谢你指出,我只用了xml的selenium我仍然在学习,我已经调整了我的代码,所以它的格式更好,我的歉意,所以你得到了你以前得到的完全相同的错误? – Brainles71

0

寻找解决这个问题,我也有,我降落在这个博客条目:

http://lance.bio/2017/04/18/selenium-ide-rollups-with-arguments/

和它的作者(兰斯克利夫兰)亲切地回答了我关于汇总使用标签的问题(见评论部分)。简而言之,用兰斯的话说,问题是这样的:

You cannot use some of the custom commands in the rollups. It has to do with how the JavaScript is loaded for the custom commands (those are JavaScript as well) and the scope of the variables commands like labels/goto have set.

However, since rollups are JavaScript anonymous functions you can use any JavaScript trickery you’d like to build the rollup. You can simulate your own gotoIf commands using standard JavaScript if commands. Any stored values are in the storedVars array.

我希望这可以帮助你。