除了sleep()在我的测试中使用之外,我想知道是否有人知道在继续我的断言之前明确等待表单提交(POST)完成的更好策略.这是我的测试看起来非常精简的版本,使用phpunit和php的 web -webdriver).
function test_form_submission()
{
// setup
$web_driver = new WebDriver();
$session = $web_driver->session();
$session->open('http://example.com/login');
// enter data
$session->element('css selector', 'input[name=email]')->value(array('value' => str_split('test@example.com')));
$session->element('css selector', 'input[name=password]')->value(array('value' => str_split('testpassword')));
// click button to submit form
$session->element('css selector', 'button[name=submit]')->click();
// How do I wait here until the click() above submits the form
// so I can check that we correctly arrives at the destination below
// without resorting to sleep()?
// Confirm that login was successful because …Run Code Online (Sandbox Code Playgroud) 当我运行以下代码(使用最新的Guzzle,v6)时,请求的URL正在从请求中http://example.com/foobar?foo=bar删除boo=far.
$guzzle_http_client = new GuzzleHttp\Client([
'base_uri' => 'http://example.com/',
'query' => [
'foo' => 'bar'
],
]);
$request = new \GuzzleHttp\Psr7\Request('GET', 'foobar?boo=far');
$response = $guzzle_http_client->send($request);
Run Code Online (Sandbox Code Playgroud)
当我运行以下代码时,boo=far作为Client::send()方法的一部分传递,获取请求的URL是http://example.com/foobar?boo=far
$guzzle_http_client = new GuzzleHttp\Client([
'base_uri' => 'http://example.com/',
'query' => [
'foo' => 'bar'
],
]);
$request = new \GuzzleHttp\Psr7\Request('GET', 'foobar');
$response = $guzzle_http_client->send($request, ['query' => ['boo' => 'far']]);
Run Code Online (Sandbox Code Playgroud)
当然,我想要的URL是:
http://example.com/foobar?foo=bar&bar=foo
Run Code Online (Sandbox Code Playgroud)
如何使Guzzle将默认客户端查询字符串参数与特定于请求的参数组合在一起?
我无法弄清楚为什么traceback.format_exc()在以下示例中返回"None":
#!/usr/bin/env python
import sys
import traceback
def my_excepthook(type, value, tb):
print type.__name__
print value
# the problem: why does this return "None"?
print traceback.format_exc(tb) # see http://docs.python.org/library/traceback.html#traceback.format_exc
sys.excepthook = my_excepthook # see http://docs.python.org/library/sys.html#sys.excepthook
# some code to generate a naturalistic exception
a = "text"
b = 5
error = a + b
Run Code Online (Sandbox Code Playgroud)
使用Python 2.7.1,我得到以下输出:
TypeError
cannot concatenate 'str' and 'int' objects
None
Run Code Online (Sandbox Code Playgroud)
而不是第3行的"无",我希望得到当我注释掉sys.excepthook行时会发生什么:
Traceback (most recent call last):
File "log-test.py", line 17, in <module>
error = a+b
Run Code Online (Sandbox Code Playgroud)