Typography

活版印字


  • Home
  • Archive
  • Categories
  • Tags
  •  

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo

Geb for functional testing of Grails app 重點整理

Posted at 2016-04-11 Geb 

Geb for functional testing of Grails app | Jacob Aae Mikkelsen | GR8Conf India 2016

為什麼我們要用Geb (06:04)

  • 類似於 JQuery 的語法
  • 具有非常強大的 WebDriver,卻是使用非常簡單的 API
  • Robustness of Page Object Modeling
  • 使用 Groovy 描述性語言
  • 跟其他 build framework 整合得很好 (Gradle、Maven)
  • 可做為傑出的使用者文件

Geb selectors (09:52)

  • 相似於 JQuery 的語法
  • 支援 regex
  • 選取後,會回傳一個 Navigator 物件
  • 支援 CSS3 語法

取得資訊 (12:30)

1
2
3
4
$('p').text() == "a"
$('p').tag() == "p"
$('p').@title == "a"
$('p').classes == ["a”, "para"]

與內容相互作用 (12:47)

1
2
3
4
5
$('a').click()
$('div').isDisplayed()
withConfirm {
$('button.delete').click();
}

傳入 input (13:50)

1
2
$('div') << 'abc'
$('input', name: 'foo') << Keys.chord(Keys.CONTROL, 'c')

Interaction (14:25)

Using actions API from WebDriver is possible. But Geb provides the interact closure.

你也許可以使用 WebDriver 的 action API,但 Geb 提供更互動式的 closure。

1
2
3
4
5
6
7
import org.openga.selenium.Keys

interact {
KeyDown Keys.CTRL
click $('a.myLink')
keyUp Keys.CTRL
}

可使用的變數 (16:15)

  • title
  • browser
  • currentUrl
  • currentWindow

更多的可能 (16:50)

  • 上傳檔案
  • 下載檔案
  • 與 js 互動

獨立的 Geb script (17:10)

Geb Spec Basic (23:00)

1
2
3
4
5
6
import geb.spock.GebSpec

@Stepwise
class XXXFunctionalSpec extends GebSpec {

}

Page 物件 - 描述一個頁面 (23:50)

  • Url
  • 如何檢查是否在對的地方
  • 內容是否是我們要的跟如何找到它
  • Helper method

content closure (25:35)

1
2
3
4
static content = {
info(required: false) {$('div.info')}
message(wait: false) {$('div.message')}
}

Modules - 描述重複的內容 (26:10)

  • 跨頁面
  • Within the same page

Modules for repeated content in a page (27:00)

1
2
3
4
5
6
7
import geb.Module

class XXXListItemModules extends Module {
data { $("td”, it) }
name { data(0).text() }
email { data(1).text() }
}

Waiting (36:00)

自定預設的 Waiting 設定值

1
2
3
4
5
6
7
8
// GebConfig.groovy
waiting {
timeout: 10
retryInterval: 0.5
}

baseNavigatorWaiting = true
atCheckWaiting = true

Pausing Geb (36:55)

可做為 debug 用途

1
2
when:
pause() // for Pause Geb until button pressed

Share 

 Previous post: Vultr VPS Next post: Buddy CI 與 Slack 整合 

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo