テキストの検証(textIs, textContains, …)

in English

要素のラベル(表示テキスト)を検証します。

対象は常に「直前に取得した要素」で、これらのコマンドにセレクタは渡しません。 まず select(または exist / tap など)で要素を取得し、そのうえで検証します。 次の3つの書き方はまったく同じ意味で、記録されるステップもデバイス往復の回数も同じです。

select("#msg").textIs("完了")                 // 戻り値へチェーン
select("#msg"); lastElement.textIs("完了")    // lastElement を明示
select("#msg"); textIs("完了")                // 暗黙(直前に取得した要素)

引数は、肯定形が (期待値, requireVisible:, strict:, waitSeconds:)、否定形が (期待値, strict:, waitSeconds:)、空判定が (strict:, waitSeconds:) です(textMatchesDateFormat は strict: を取りません。下の表のとおり)。セレクタを渡す形はありません — textIs("#msg", "完了") はコンパイルできません。

暗黙形(textIs("…") のように lastElement を省いた形)に、# で始まる英数字だけの文字列や ||・>> を含む文字列を渡すと、セレクタの書き誤りとみなして実行前に失敗します。そういう文字列を期待値にしたいときはチェーン形(select("#tag").textIs("#swift"))で書いてください。

関数

肯定 否定 判定
select(selector).textIs(expected, requireVisible:, strict:, waitSeconds:) textIsNot(expected, strict:, waitSeconds:) 完全一致
textContains(expected, requireVisible:, strict:, waitSeconds:) textContainsNot(expected, strict:, waitSeconds:) 部分一致
textStartsWith(expected, requireVisible:, strict:, waitSeconds:) textStartsWithNot(expected, strict:, waitSeconds:) 前方一致
textEndsWith(expected, requireVisible:, strict:, waitSeconds:) textEndsWithNot(expected, strict:, waitSeconds:) 後方一致
textMatches(pattern, requireVisible:, strict:, waitSeconds:) textMatchesNot(pattern, strict:, waitSeconds:) 正規表現(部分一致。全体一致は ^…$)
textMatchesDateFormat(format, requireVisible:, waitSeconds:) — DateFormatter の書式文字列(例: "yyyy/MM/dd")
textIsNotEmpty(strict:, waitSeconds:) textIsEmpty(strict:, waitSeconds:) 空でない / 空

上記はすべて exist / select の戻り値にチェーンでき、直前に取得した要素に効く 暗黙形(自由関数。引数はチェーン形と同じ)も持ちます。

例

select("#msg").textIs("完了")

exist("#total")
    .textStartsWith("合計")
    .textEndsWith("円")

注意点