使用Selenium WebDriver进行Facebook身份验证

使用Selenium WebDriver,我想处理Facebook身份验证并使用
HtmlUnitDriver获取Access Token,我该怎么办? 最佳答案 很多这些函数的目的都是你必须推断出来的,但这是我写的关于oauth流本身的一个测试:

$this->loginAsTestUser();

$oauth_uri = $this->fbURI()
  ->setPath('/dialog/oauth')
  ->addQueryData('client_id', self::RELL_APP_ID)
  ->addQueryData('redirect_uri', self::RELL_URL);
$this->open($oauth_uri);
$this->platform->tosApp();

$code = $this->getURI()->getQueryData('code');
$this->assertNotEmpty($code, 'No code returned in redirect url');

$token_uri = $this->fbURI('graph')
  ->setSecure(true)
  ->setPath('/oauth/access_token')
  ->addQueryData('client_id', self::RELL_APP_ID)
  ->addQueryData('client_secret', self::RELL_SECRET)
  ->addQueryData('code', $code)
  ->addQueryData('redirect_uri', self::RELL_URL);
$this->open($token_uri);
$this->assertRegExp(
  '/access_token=.+/', $this->source(),
  'No access token returned in source');
点赞