Skip to content

Instantly share code, notes, and snippets.

@spikeheap
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save spikeheap/8862048 to your computer and use it in GitHub Desktop.

Select an option

Save spikeheap/8862048 to your computer and use it in GitHub Desktop.
Geb context clicks

Geb context click example

A simple test demonstrating how to do a context click in Geb.

apply plugin: 'groovy'
repositories{
mavenCentral()
}
dependencies{
compile 'org.codehaus.groovy:groovy-all:2.2.1'
compile "org.gebish:geb-core:0.9.2", "org.gebish:geb-spock:0.9.2", "org.seleniumhq.selenium:selenium-firefox-driver:2.39.0", "org.seleniumhq.selenium:selenium-support:2.39.0"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}
task runScript (dependsOn: 'classes', type: JavaExec) {
main = 'contextClicker'
classpath = sourceSets.main.runtimeClasspath
}
// place in src/test/groovy/
import geb.Browser
import geb.*
import org.openqa.selenium.firefox.FirefoxDriver
import geb.spock.GebSpec
class contextClickerSpec extends GebSpec{
def "Context click opens menu"(){
setup:
go "http://medialize.github.io/jQuery-contextMenu/demo.html"
def contextBox = $(".context-menu-one")
contextBox.text() == "right click me"
when: "I context-click the div"
interact{ contextClick(contextBox) }
def editOption = $('li.context-menu-item:nth-child(1) > span:nth-child(1)')
then: "It displays the edit option"
editOption.displayed
editOption.text() == "Edit"
cleanup:
quit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment