Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to run Geb functional tests on a hybrid Phonegap app. This require Appium server running on the local environment as well as XCode install for Mac and/or Android emulator installed.
apply plugin: 'groovy'
sourceCompatibility = 1.7
version = '1.0'
repositories {
jcenter()
}
ext {
ext {
groovyVersion = '2.3.9'
gebVersion = '0.10.0'
}
}
dependencies {
// If using Spock, need to depend on geb-spock
testCompile "org.gebish:geb-spock:$gebVersion"
testCompile("org.spockframework:spock-core:0.7-groovy-2.0") {
exclude group: "org.codehaus.groovy"
}
testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
// Drivers
testCompile "io.appium:java-client:2.1.0"
}
task "AppiumTest"(type: Test) {
reports {
html.destination = reporting.file("$name/tests")
junitXml.destination = file("$buildDir/test-results/$name")
}
outputs.upToDateWhen { false } // Always run tests
systemProperty "geb.build.reportsDir", reporting.file("$name/geb")
systemProperty "geb.env", 'appium'
// If you wanted to set the baseUrl in your build…
// systemProperty "geb.build.baseUrl", "http://myapp.com"
}
import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.ios.IOSDriver
import io.appium.java_client.remote.MobileCapabilityType
import org.openqa.selenium.Capabilities
import org.openqa.selenium.remote.DesiredCapabilities
waiting {
timeout = 2
}
Capabilities androidCapabilities = new DesiredCapabilities()
androidCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android")
androidCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.2")
androidCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator")
androidCapabilities.setCapability(MobileCapabilityType.APP, '/Users/nvinet/dev/ctp/ctp-mobile/platforms/android/ant-build/CordovaApp-debug.apk')
Capabilities iosCapabilities = new DesiredCapabilities()
iosCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS")
iosCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.1")
iosCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator")
iosCapabilities.setCapability(MobileCapabilityType.APP, '/Users/nvinet/dev/ctp/ctp-mobile/platforms/ios/build/emulator/CtpMobile.app')
driver = {
// new IOSDriver(new URL('http://127.0.0.1:4723/wd/hub'), iosCapabilities)
new AndroidDriver(new URL('http://127.0.0.1:4723/wd/hub'), androidCapabilities)
}
import geb.spock.GebSpec
import io.appium.java_client.AppiumDriver
import org.openqa.selenium.By
class Test extends GebSpec {
AppiumDriver currentDriver
void setup() {
currentDriver = driver as AppiumDriver
Set<String> contextNames = currentDriver.contextHandles
println 'available contexts: ' + contextNames
currentDriver.context(contextNames[1]) // set context to WEBVIEW_1
println 'current context: ' + currentDriver.context
}
void cleanup() {
currentDriver.context("NATIVE_APP")
currentDriver.quit()
}
void "Can see app title"() {
expect: 'The app title to be visible'
$('li').text() == 'Hello World: testService'
}
}
@Jitesh-Mohite

This comment has been minimized.

Copy link

Jitesh-Mohite commented Dec 19, 2016

driver = {
// new IOSDriver(new URL('http://127.0.0.1:4723/wd/hub'), iosCapabilities)
new AndroidDriver(new URL('http://127.0.0.1:4723/wd/hub'), androidCapabilities)
}

can you tell me when it is called while running test cases ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.