Last active
June 30, 2017 10:25
-
-
Save kodaitakahashi/ebffe3654f4ff5e7d8c7d2823ed408ff to your computer and use it in GitHub Desktop.
Spock+Gebでダイアログ操作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geb.report.ScreenshotReporter | |
import org.openqa.selenium.ie.InternetExplorerDriver; | |
environments { | |
ie { | |
driver = { new InternetExplorerDriver() } | |
} | |
} | |
reporter = new ScreenshotReporter(){ | |
@Override | |
protected escapeFileName(String name) { | |
name.replaceAll('[\\\\/:\\*?\\"<>\\|]', '_') | |
} | |
} | |
reportsDir = "./report" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geb.Page | |
class NextPage extends Page{ | |
static at = { title == 'NextPage' } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"/> | |
<title>SamplePage</title> | |
<script> | |
function btn(){ | |
if(confirm('ダイアログ操作')){ | |
location.href = 'next.html' | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<button id="confirm" onclick="btn()" >ダイアログ</button> | |
</body> | |
</html> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geb.Page | |
class SamplePage extends Page{ | |
static at = { title == 'SamplePage'} | |
static url = 'http://path.to.sample.html' | |
static content = { | |
btnConfirm {$('#confirm')} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geb.spock.GebReportingSpec | |
class SampleSpec extends GebReportingSPec{ | |
def 'ダイヤログ出現時にOKを選ぶとネクストページに遷移する'(){ | |
when: 'サンプルページに移動' | |
to SamplePage | |
then: 'サンプルページに遷移していること' | |
waitFor{ at SamplePage } | |
when: 'ダイアログボタンをクリック' | |
btnConfirm.click() | |
//ダイアログを操作に切り替え | |
def confirm = driver.switchTo.alert() | |
// confirmでtrueの結果を返せる | |
confirm.accept() | |
then:'ネクストページに遷移していること' | |
waitFor{ at NextPage } | |
} | |
def 'ダイヤログ出現時にキャンセルを選ぶとネクストページに遷移する'(){ | |
when: 'サンプルページに移動' | |
to SamplePage | |
then: 'サンプルページに遷移していること' | |
waitFor{ at SamplePage } | |
when: 'ダイアログボタンをクリック' | |
btnConfirm.click() | |
//ダイアログを操作に切り替え | |
def confirm = driver.switchTo.alert() | |
// confirmでfalseの結果を返せる | |
confirm.dismiss() | |
then:'サンプルページにいること' | |
at SamplePage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment