Codeception / Codeception/module-webdriver

Make WebDriver::getLocator (and WebDriver::getStrictLocator) public

オープン
#50 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
PHP
スター
39
フォーク
25
PR マージ指標
30日以内にマージされた PR はありません

説明

#### What are you trying to achieve?
Write a custom action that uses the WebDriver locator service to locate an element by its selector string.
I would like to do this by getting the web driver module with `$this->getModule('WebDriver')` rather than extending `WebDriver` to keep my testing architecture consistent with other modules I've written.

#### What do you get instead?
Unable to use the functions because they're protected.

```php
/**
* @param $selector
* @return WebDriverBy
* @throws \InvalidArgumentException
*/
protected function getLocator($selector)
{
if ($selector instanceof WebDriverBy) {
return $selector;
}
if (is_array($selector)) {
return $this->getStrictLocator($selector);
}
if (Locator::isID($selector)) {
return WebDriverBy::id(substr($selector, 1));
}
if (Locator::isCSS($selector)) {
return WebDriverBy::cssSelector($selector);
}
if (Locator::isXPath($selector)) {
return WebDriverBy::xpath($selector);
}
throw new \InvalidArgumentException("Only CSS or XPath allowed");
}

// ...and

/**
* @param array $by
* @return WebDriverBy
*/
protected function getStrictLocator(array $by)
{
$type = key($by);
$locator = $by[$type];
switch ($type) {
case 'id':
return WebDriverBy::id($locator);
case 'name':
return WebDriverBy::name($locator);
case 'css':
return WebDriverBy::cssSelector($locator);
case 'xpath':
return WebDriverBy::xpath($locator);
case 'link':
return WebDriverBy::linkText($locator);
case 'class':
return WebDriverBy::className($locator);
default:
throw new MalformedLocatorException(
"$by => $locator",
"Strict locator can be either xpath, css, id, link, class, name: "
);
}
}
```
### Details
It seems to me that these are services that the `WebDriver` module should expose, as some public `WebDriver` functions take `WebDriverBy` arguments (e.g. `WebDriver::findElements`). We need some service to get these `WebDriverBy` arguments, or we won't be able to use the public function calls that are exposed through `$this->getModule('WebDriver');`. Alternatively, maybe the `WebDriver` module should expose some public `findElement` type of function that takes a selector string rather than a `WebDriverBy` instance.

* Codeception version: 2.2.10
* PHP Version: 7.0.10

Apologies if this has already been discussed, I didn't see it on the issues board. And thanks for making such a fantastic tool!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

WebDriver::getLocator と WebDriver::getStrictLocator のエントリポイントから始め、WebDriver::findElements などの public 関数が WebDriverBy 引数をどのように受け取るかを調べます。$this->getModule('WebDriver') で取得したモジュールがカスタムアクションから両方のロケーターサービスを使用できることを検証し、無効なセレクターの処理が issue に示されている既存の動作によって引き続きカバーされていることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
testing-qa
issue の種類
機能追加
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。