我正在使用selenium进行端到端测试,我无法获得如何使用setup_class和teardown_class方法.
我需要在setup_class方法中设置浏览器,然后执行一系列定义为类方法的测试,最后在teardown_class方法中退出浏览器.
但从逻辑上讲,这似乎是一个糟糕的解决方案,因为实际上我的测试不是用于类,而是用于对象.我self在每个测试方法中传递param,所以我可以访问对象的变量:
class TestClass:
def setup_class(cls):
pass
def test_buttons(self, data):
# self.$attribute can be used, but not cls.$attribute?
pass
def test_buttons2(self, data):
# self.$attribute can be used, but not cls.$attribute?
pass
def teardown_class(cls):
pass
Run Code Online (Sandbox Code Playgroud)
甚至为类创建浏览器实例似乎也不正确..它应该分别为每个对象创建,对吧?
所以,我需要使用__init__和__del__方法而不是setup_class和teardown_class?
我刚刚在谷歌浏览器中打开了一个空白的HTML页面,其中包含一些基本标签(如html,body,head等),并尝试在控制台中执行以下命令:
history.pushState(null, 'my test title', '/test/url');
Run Code Online (Sandbox Code Playgroud)
历史事件工作正常,但页面标题保持不变.可以吗?我应该每次都手动更换吗?如果我应该,为什么像title这样的pushState()方法中有这样的参数?
我正在使用虚拟方法对本地api Web服务(通过LAN)执行POST请求,该方法本身非常快(少于一秒).
问题是,如果我使用php5-fpm,执行POST请求(curl post,streams)需要很长时间.
如果我使用相同代码或控制台卷曲命令的php-cli脚本 - 它的工作速度非常快,就像魅力一样.
奇怪的是:如果我使用system从php5-fpm执行console curl命令,则需要花费大量时间来执行请求.所以,没办法作弊:(
我使用直接ipv4地址来消除DNS问题(我试图定义CURLOPT_IPRESOLVE选项,但性能相同).
如果我省略curl CURLOPT_POSTFIELDS选项,请求在php5-fpm中也非常快.
我正在使用官方的PHP 5.6.9包debian jessie.
那么,为什么php5-fpm会出现这个问题呢?
我的curl php代码:
$data = json_encode([
'id' => 1,
'method' => 'test',
'sid' => session_id(),
]);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://192.168.182.22');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-type: application/json',
'Content-length: ' . strlen($data)
]);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$out = curl_exec($curl);
curl_close($curl);
Run Code Online (Sandbox Code Playgroud)
卷曲获取信息输出(显示starttransfer_time非常慢):
array(26) {
["url"]=>
string(22) "http://192.168.182.22/"
["content_type"]=>
string(24) …Run Code Online (Sandbox Code Playgroud) 我必须执行LOT查找,同时解析xmlStream如果我需要一些标签或没有.
我可以使用array.indexOf方法(我在数组中有约15项)或使用object [key]查找.
对我来说,第二种解决方案在理论上似乎更有效,但在我的代码中看起来并不好看.但如果真的更有效率,我会保持原样.
例如:
var tags = [
'tag1',
'tag2',
'tag3',
...
];
var tags2 = {
'tag1' : null,
'tag2' : null,
'tag3' : null,
}
tags.indexOf(value) // exists?
tags2[value] // exists?
Run Code Online (Sandbox Code Playgroud) 是否有可能在PHP中获得扩展版本?
get_loaded_extensions 仅返回已加载的扩展名称,但不返回版本:(
我正在写一个模块,它是一个可写的流.我想为我的用户实现管道接口.
如果发生某些错误,我需要暂停可读流并发出错误事件.然后,用户将决定 - 如果他没有错误,他应该能够恢复数据处理.
var writeable = new BackPressureStream();
writeable.on('error', function(error){
console.log(error);
writeable.resume();
});
var readable = require('fs').createReadStream('somefile.txt');
readable.pipe.(writeable);
Run Code Online (Sandbox Code Playgroud)
我看到该节点为我们提供readable.pause()了可用于暂停可读流的方法.但我无法得到如何从我的可写流模块中调用它:
var Writable = require('stream').Writable;
function BackPressureStream(options) {
Writable.call(this, options);
}
require('util').inherits(BackPressureStream, Writable);
BackPressureStream.prototype._write = function(chunk, encoding, done) {
done();
};
BackPressureStream.prototype.resume = function() {
this.emit('drain');
}
Run Code Online (Sandbox Code Playgroud)
如何在可写流中实现背压?
PS可以使用pipe/unpipe提供可读流作为参数的事件.但也有人说,对于管道流,暂停的唯一机会是从可写入中删除可读流.
我做对了吗?我必须取消管理可写流,直到用户呼叫恢复为止?用户调用恢复后,我应该管道可读流回来?
对silverlight不感兴趣.Flash/javascript/html5解决方案是可以接受的.
如果您不知道这样的解决方案,请问您是否可以这样做?
pip无法在pypi网站上找到这个模块,以及我.你能告诉我秘密,如何安装它?
我需要模块通过subprocess.call生成新的shell进程.我看过很多人们使用的例子,import subprocess但没有人展示它是如何安装的.
错误,我得到了(以防万一我失去理智,不明白发生了什么):
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Alexander\Desktop\tests-runner>python run.py
Traceback (most recent call last):
File "run.py", line 165, in <module>
main()
File "run.py", line 27, in main
subprocess.call('py.test')
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud) 是否可以使用棉花糖验证列表?
class SimpleListInput(Schema):
items = fields.List(fields.String(), required=True)
# expected invalid type error
data, errors = SimpleListInput().load({'some': 'value'})
# should be ok
data, errors = SimpleListInput().load(['some', 'value'])
Run Code Online (Sandbox Code Playgroud)
或者预计只验证对象?
当我在Kibana中看到结果时,我发现JSON中没有字段,更多message字段只包含字段"status" : "FAILED".
是否有可能从json解析字段并在Kibana中显示它们?我有以下配置:
input {
file {
type => "json"
path => "/home/logstash/test.json"
codec => json
sincedb_path => "/home/logstash/sincedb"
}
}
output {
stdout {}
elasticsearch {
protocol => "http"
codec => "json"
host => "elasticsearch.dev"
port => "9200"
}
}
Run Code Online (Sandbox Code Playgroud)
并遵循JSON文件:
[{"uid":"441d1d1dd296fe60","name":"test_buylinks","title":"Testbuylinks","time":{"start":1419621623182,"stop":1419621640491,"duration":17309},"severity":"NORMAL","status":"FAILED"},{"uid":"a88c89b377aca0c9","name":"test_buylinks","title":"Testbuylinks","time":{"start":1419621623182,"stop":1419621640634,"duration":17452},"severity":"NORMAL","status":"FAILED"},{"uid":"32c3f8b52386c85c","name":"test_buylinks","title":"Testbuylinks","time":{"start":1419621623185,"stop":1419621640826,"duration":17641},"severity":"NORMAL","status":"FAILED"}]
Run Code Online (Sandbox Code Playgroud) python ×3
object ×2
php ×2
python-2.7 ×2
arrays ×1
audio ×1
backpressure ×1
class ×1
curl ×1
flac ×1
javascript ×1
kibana ×1
logstash ×1
marshmallow ×1
node.js ×1
post ×1
pytest ×1
stream ×1
subprocess ×1