小编Jus*_*att的帖子

php-webdriver:使用click()提交表单后等待浏览器响应

除了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)

php selenium phpunit selenium-webdriver

10
推荐指数
2
解决办法
1万
查看次数

如何使用Guzzle组合默认查询字符串参数和请求特定的参数?

当我运行以下代码(使用最新的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将默认客户端查询字符串参数与特定于请求的参数组合在一起?

guzzle

6
推荐指数
1
解决办法
3135
查看次数

在期待回溯时,traceback.format_exc/print_exc返回None

我无法弄清楚为什么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)

python exception-handling

5
推荐指数
1
解决办法
2976
查看次数