LoginSignup
2
1

More than 3 years have passed since last update.

Cypressでスマホモードでテストするには、config.jsonのuserAgentを変更する

Posted at

環境

  • macOS Mojave バージョン 10.14.6

前提条件

  • Cypressは導入完了している

対象者

手順

UserAgentを設定する

  • 1. config.json に以下のコードを追加する
{
  "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1"
}

画面サイズをスマホにする

  • 1. テストコードの前に、以下のコードを追加する
cy.viewport("iphone-6")

describe("view", () => {

  it("show ticket", () => {

    cy.viewport("iphone-6") // iphone6の大きさになる

    cy.visit("https://xxxx")
  })

参考

Intent to Deprecate and Freeze: The User-Agent string

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1