Codeception ではリンクの href を取得するメソッドが特殊すぎるためありませんが、Mink API を使用して WebHelper クラスで独自のアクションを定義し、href を取得することができます。モジュールとヘルパーの詳細をお読みください。
リンクの href を取得するアクションの例を次に示します。
public function grabHref($locator)
{
$webDriver = $this->getModule('Selenium2');
$link = $webDriver->session->getPage()->findLink($locator);
if ($link) {
return $link->getAttribute('href');
}
$this->fail("Link '{$locator}' not found");
}
この関数を _helpers/WebHelper.php ファイルに配置し、テスト スーツの構成で WebHelper モジュールを有効にします。
class_name: WebGuy
modules:
enabled: [Selenium2, WebHelper]
次に、実行codecept build
して WebGuy クラスを再構築します。
これで、cept/Cest ファイルでgrabHref アクションを使用できます。
$I = new WebGuy($scenario);
$I->wantTo('Grab Href');
$I->amOnPage('/');
$href = $I->grabHref('Link text or ID or Title');