LoginSignup
2
0

More than 5 years have passed since last update.

Gebで特定のテストケースのみUserAgentを切り替える

Posted at

Specの中でUserAgentを切り替えるスマートな方法が探してもぱっと出てこなかったので暫定処置。

class SPPageSpec extends GebSpec {

    def "SP用ページ表示のテスト"() {
        setup:
        FirefoxProfile profile = new FirefoxProfile();
        String userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 9_0 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13A344 Safari/601.1"
        profile.setPreference("general.useragent.override", userAgent)
        driver = new FirefoxDriver(profile);
        driver.manage().window().size = new Dimension(320, 640)

        when:
        go "https://www.google.com"

        then:
        title.contains("Google")

        cleanup:
        browser.quit()
    }
}

cleanupでquitしないとブラウザが開いたまま残ってしまう。

2
0
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
0