cypress メモ
Intellisense
TypeScript を使用する場合は <project-root>/cypress/tsconfig.json を作成する
code:tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"es5",
"dom"
],
"types": [
"cypress"
]
},
"include": [
"**/*.ts"
]
}
"types": ["cypress"] を入れることで、mocha, chai, cypress の型定義が読み込まれる
JavaScript を使用する場合はファイルの先頭に /// <reference types="cypress" を入れる
これを入れておかないと
describe などで、isolatedModule のエラーが出てくる
should のアサーションが面倒
CustomCommand の型付け
複数の Element に match する時
テスト実行時に数字が出てくる
timetravel して dev console を開くと、console にログが出ているので、そこから対象を絞り込むことができる
https://gyazo.com/878a794dca359910d40e99af5fc6498c
eq で n element 目を取得できるので assertion を書ける
cy.get("dt").eq(0).contains("4 Courses")
Element の絞り込み
code:typescript
cy.get("something").find("a") // something で抽出した Element の中から Element を絞りこめる