私は Behat|Mink を通じて BDD に取り組んできました。
ただし、ID または名前が完全でない場合、入力 (フィールド) を見つけることができません。
私は次のようなことをするつもりでした:
$field = $this->getSession()->getPage()->findField( "*first_name*" );
「*」は、そこにある任意の文字列であることを意味します。
問題は、完全なIDの原因を確実に知ることができない場合があることです:
id="<random-string>_<actual-field-name>_<random-number>"
どうすればこれを行うことができますか?
私は何を試しましたか
- get it through label (for some reasons there are some labels that dont have 'for' attribute and sometimes the name is a sentence and not an simple name)
- get it through css/classes (to many variables)
編集:
属性を読み取り、目的の属性の値を返す php 関数を作成しました。
/**
*
* @param string $haystack The complete html
* @param string $needle The string with the part of the attribute value
* @param string $tag The tag of where the attribute should belong
* @param string $attr The attribute to ifnd
* @return string
*/
protected function findCompleteAttribute( $haystack, $needle, $tag = null, $attr = 'id' )
ただし、別のフィールド (例: 非表示のログイン フォーム) があり、針がそれらの入力にもある場合、それらが最初であればそれらを取得します。
したがって、フォームを指定する必要がありますが、もう一度、名前からフォームを見つける方法がありません。
$field = $this->getSession()->getPage()->find( 'named', array( 'form', $formName ) );