我有一个自定义的selenium函数,它通过Ajax调用发布数据(PHP脚本打开文件)。抛弃我的是,如果我在浏览器控制台中运行代码它可以工作,但是当我通过selenium IDE运行该功能时,它并不是'发布数据。
PHP
<?php
header('Access-Control-Allow-Origin: *');
$report = $_POST['report'];
$report_file = fopen("report.txt", "w");
fwrite($report_file, $report);
fclose($report_file);
硒功能
Selenium.prototype.doSaveCopyPaste = function(locator) {
$ = _getGlobalVar('jQuery');
var text = $(locator).text();
var formData = new FormData();
formData.append('report', text);
$.ajax({
type: 'POST',
url: 'http://copypaste.test',
data: formData,
dataType: 'text',
processData: false,
contentType: false,
success: function(){
alert('Success');
},
error: function() {
alert('failed');
}
});
}
Selenium IDE
command: saveCopyPaste Target: #plain-report Value:
测试变为绿色,好像表明它已通过但文件未创建..
如果我在浏览器控制台(firefox)中执行此操作,则会创建文件
var text = $('#plain-report').text();
var formData = new FormData();
formData.append('report', text);
var ajax = $.ajax({
type: 'POST',
url: 'http://copypaste.test',
data: formData,
dataType: 'text',
processData: false,
contentType: false,
success: function(){
alert('Success');
},
error: function() {
alert('failed');
}
});
有没有理由将此作为自定义函数用于导致不通过selenium测试创建文件?
我有点难过,因为这应该有效
修改
稍微调试一下,发现POST不是&#39;甚至在尝试通过硒进行时也会发生
在控制台中触发呼叫时,在网络标签中我得到
POST http://copypaste.test/
但是当通过selenium运行时,网络标签中没有任何内容
console.log(ajax)
的输出返回
[object Object]
另一个想法是,使用prototype.js和jquery与这个调用冲突,我尝试过noConflict();虽然方法没有什么区别。
由于