diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c3f61f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea/ +.gradle/ +geb-mobile-extension.iml +build/ +src/test/resources/testapk/resigned-selendroid-test-app-0.9.0.apk diff --git a/README.md b/README.md index d2f9fa9..16c7413 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ ## Geb Mobile Extension for appium ( UIAutomator ) and selendroid ( InstrumentationFramework ) ## -# for easy dev: put break-point on desired method, -# open evalute window: (CTRL-U) , run -# AppiumPageSourceConverter.writeActivityContent(driver) +* for easy dev: put break-point on desired method, +* open evalute window: (CTRL-U) , run +* AppiumPageSourceConverter.writeActivityContent(driver) # Info zu AppiumDriver diff --git a/build.gradle b/build.gradle index 2ce5cbf..16ef31f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'groovy' apply plugin: 'maven' apply plugin: 'idea' -group = 'mueke' +group = 'dr.legacy' version = '0.1-SNAPSHOT' ext.gebVersion = '0.9.1' @@ -12,7 +12,12 @@ ext.groovyVersion = '2.3.4' ext.selendroidVersion = '0.10.0' repositories { - mavenCentral() + mavenCentral() +} + +configurations { + selendroid + iosdriver } dependencies { @@ -48,44 +53,94 @@ dependencies { compile "io.selendroid:selendroid-standalone:$selendroidVersion" compile "io.selendroid:selendroid-client:$selendroidVersion" compile "org.uiautomation:ios-client:0.6+" - compile('io.appium:java-client:1.6.1'){ - // exclude module: "selenium-java" + compile('io.appium:java-client:1.6.1') { + //exclude module: "selenium-java" } + + selendroid "io.selendroid:selendroid-standalone:${selendroidVersion}" + + iosdriver "org.uiautomation:ios-server:0.6+" + } -task startSelendroid << { - "java -jar ${projectDir}" +def startServer = { server, command -> + println "Starting $server with $command" + ProcessBuilder builder = new ProcessBuilder(command.split(' ')) + builder.redirectErrorStream(true) + builder.directory(buildDir) + Process process = builder.start() + ext[server] = process + println "$server started : $process" + Thread.start("logging-$server") { + FileOutputStream fout = new FileOutputStream(new File(buildDir, "${server}.log")) + int bb + while ((bb = process.getInputStream().read()) > 0) { + fout.write(bb) + } + } } -task startAppium << { - "appium --command-timeout 90000 &".execute() +def stopServer = { server -> + if (ext.has(server)) { + def process = ext.get(server) + println "send CTRL-C to server" + process.getOutputStream().write(3) + process.getOutputStream().flush() + process.destroy() + } else { + println "No Server $server found in process list" + } } +task startSelendroid << { + startServer( "SELENDROID" , "java -cp ${configurations.selendroid.files.toList().join(":")} io.selendroid.SelendroidLauncher -port 4444 -aut ${projectDir}/src/test/resources/testapk/selendroid-test-app-0.9.0.apk") +} +task stopSelendroid << { + stopServer( "SELENDROID" ) +} +task startAppium << { + //startServer("APPIUM", "appium --command-timeout 90000") +} +task stopAppium << { + stopServer("APPIUM") +} task startIosdriver << { - "java -jar ios-driver".execute() + startServer( "IOSDRIVER", "java -cp ${configurations.iosdriver.files.toList().join(":")} org.uiautomation.ios.IOSServer" ) +} +task stopIosdriver << { + stopServer("IOSDRIVER") } +task stopServers << { + ["SELENDROID","APPIUM","IOSDRIVER"].each{ + if( ext.has(it) ) stopServer(it) + } +} -task runSelendroidTests(type:Test,dependsOn:[startSelendroid]) { +task runSelendroidTests(type: Test, dependsOn: [startSelendroid]) { systemProperty "appUT_absolutePath", "${projectDir}/src/test/resources/testapk/selendroid-test-app-0.9.0.apk" - systemProperty "appUT.package","io.selendroid.testapp" - systemProperty "appUT.version","0.10.0" - systemProperty "appUT_cap_Emulator","false" - systemProperty "framework","selendroid" - include '' - + systemProperty "appUT.package", "io.selendroid.testapp" + systemProperty "appUT.version", "0.10.0" + systemProperty "appUT_cap_Emulator", "false" + systemProperty "framework", "selendroid" + include '**/GebMobileAutomationTestWithPagesSpec.*' } -task runAppiumTests( type: Test, dependsOn:[startAppium]){ - systemProperty "appUT.package","io.selendroid.testapp" +task runAppiumTests(type: Test) { + systemProperty "appUT.package", "io.selendroid.testapp" systemProperty "appium_app", "${projectDir}/src/test/resources/testapk/selendroid-test-app-0.9.0.apk" //To run the test on a specific device //System.setProperty("appium_udid","192.168.56.10:5555") //System.setProperty("appium_automationName","selendroid") //Use Appium - systemProperty "framework","appium" + systemProperty "framework", "appium" + include '**/GebMobileAutomationTestWithPagesSpec.*' +} +tasks.withType(Test){ task-> + stopServers.mustRunAfter(task) + ignoreFailures = true } diff --git a/config/iosdriver_logging.properties b/config/iosdriver_logging.properties new file mode 100644 index 0000000..8fe12cb --- /dev/null +++ b/config/iosdriver_logging.properties @@ -0,0 +1,39 @@ +.level = FINEST +handlers = java.util.logging.ConsoleHandler,java.util.logging.FileHandler +org.uiautomation.ios.level = FINEST + +org.uiautomation.ios.IOSServer.level = FINEST + +org.uiautomation.ios.mobileSafari.level = WARNING +org.uiautomation.ios.wkrdp.internal.DefaultMessageHandler.level = WARNING +org.uiautomation.ios.mobileSafari.WebInspector.level = WARNING +org.uiautomation.ios.wkrdp.ResponseFinderList.level = WARNING + +#DOMContext +org.uiautomation.ios.wkrdp.DOMContext.level = WARNING + +org.uiautomation.ios.wkrdp.WebInspector.level = WARNING +org.uiautomation.ios.wkrdp.events.level = WARNING +org.uiautomation.ios.wkrdp.internal.AlertDetector.level = WARNING +org.uiautomation.ios.servlet.IOSServlet.level = WARNING +org.uiautomation.ios.servlet.level = WARNING +org.uiautomation.ios.application.LanguageDictionary.level = OFF + +# webkit protocol +org.uiautomation.ios.wkrdp.message.level = FINEST +org.uiautomation.ios.command.web.level = FINEST +org.uiautomation.ios.mobileSafari.remoteWebkitProtocol.RemoteIOSDriver.level= FINEST + +#instruments output. +org.uiautomation.ios.servlet.InstrumentsLogServlet.level = FINEST +org.uiautomation.ios.utils.level = FINEST + +# Console Logging +#java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n" +java.util.logging.ConsoleHandler.level = ALL +java.util.logging.ConsoleHandler.formatter = org.uiautomation.ios.LogFormatter + +# File Logging +java.util.logging.FileHandler.level = ALL +java.util.logging.FileHandler.pattern = ios-driver.log +java.util.logging.FileHandler.formatter = org.uiautomation.ios.LogFormatter diff --git a/src/main/groovy/geb/mobile/driver/GebMobileDriverFactory.groovy b/src/main/groovy/geb/mobile/driver/GebMobileDriverFactory.groovy index 2b796fa..49f6196 100644 --- a/src/main/groovy/geb/mobile/driver/GebMobileDriverFactory.groovy +++ b/src/main/groovy/geb/mobile/driver/GebMobileDriverFactory.groovy @@ -68,7 +68,9 @@ class GebMobileDriverFactory { log.error("eXC: $e.message", e) if( e.message =~ /Android devices must be of API level 17 or higher/ ){ capa.setCapability("automationName","selendroid") - driver = new SelendroidDriver(getURL("http://localhost:4723/wd/hub"), capa) + try { + driver = new SelendroidDriver(getURL("http://localhost:4723/wd/hub"), capa) + }catch(ex){ log.error("Error:",ex)} } } if (!driver) throw new RuntimeException("Appiumdriver could not be started") diff --git a/src/test/groovy/geb/mobile/android/instrumention/specification/selendroid/GebMobileAutomationTestWithPagesSpec.groovy b/src/test/groovy/geb/mobile/android/instrumention/specification/GebMobileAutomationTestWithPagesSpec.groovy similarity index 87% rename from src/test/groovy/geb/mobile/android/instrumention/specification/selendroid/GebMobileAutomationTestWithPagesSpec.groovy rename to src/test/groovy/geb/mobile/android/instrumention/specification/GebMobileAutomationTestWithPagesSpec.groovy index eff47b7..c0db37f 100644 --- a/src/test/groovy/geb/mobile/android/instrumention/specification/selendroid/GebMobileAutomationTestWithPagesSpec.groovy +++ b/src/test/groovy/geb/mobile/android/instrumention/specification/GebMobileAutomationTestWithPagesSpec.groovy @@ -1,5 +1,6 @@ -package geb.mobile.android.instrumention.specification.selendroid +package geb.mobile.android.instrumention.specification +import geb.mobile.GebMobileBaseSpec import geb.mobile.android.instrumention.activities.HomeScreenActivity import geb.mobile.android.instrumention.activities.WebViewActivity import spock.lang.Stepwise @@ -8,7 +9,7 @@ import spock.lang.Stepwise * Created by gmueksch on 23.06.14. */ @Stepwise -class GebMobileAutomationTestWithPagesSpec extends GebMobileAutomationTestBase { +class GebMobileAutomationTestWithPagesSpec extends GebMobileBaseSpec { def "open test-app and enter text "() { given: diff --git a/src/test/groovy/geb/mobile/android/instrumention/specification/appium/AppiumWithGebMobileAutomationTestBase.groovy b/src/test/groovy/geb/mobile/android/instrumention/specification/appium/AppiumWithGebMobileAutomationTestBase.groovy deleted file mode 100644 index d4a9977..0000000 --- a/src/test/groovy/geb/mobile/android/instrumention/specification/appium/AppiumWithGebMobileAutomationTestBase.groovy +++ /dev/null @@ -1,21 +0,0 @@ -package geb.mobile.android.instrumention.specification.appium - -import geb.mobile.GebMobileBaseSpec - -/** - * Created by gmueksch on 27.06.14. - * Base class which sets the System properties to use Appium with the selendroid interface - */ -class AppiumWithGebMobileAutomationTestBase extends GebMobileBaseSpec{ - - static{ - System.setProperty("appUT.package","io.selendroid.testapp") - System.setProperty("appium_app", new File(ClassLoader.getSystemResource("testapk/selendroid-test-app-0.9.0.apk").toURI()).absolutePath) - //To run the test on a specific device - //System.setProperty("appium_udid","192.168.56.10:5555") - //System.setProperty("appium_automationName","selendroid") - - //Use Appium - System.setProperty("framework","appium") - } -} diff --git a/src/test/groovy/geb/mobile/android/instrumention/specification/appium/AppiumWithGebMobileAutomationTestWithPagesSpec.groovy b/src/test/groovy/geb/mobile/android/instrumention/specification/appium/AppiumWithGebMobileAutomationTestWithPagesSpec.groovy deleted file mode 100644 index 34e77f7..0000000 --- a/src/test/groovy/geb/mobile/android/instrumention/specification/appium/AppiumWithGebMobileAutomationTestWithPagesSpec.groovy +++ /dev/null @@ -1,57 +0,0 @@ -package geb.mobile.android.instrumention.specification.appium - -import geb.mobile.android.instrumention.activities.HomeScreenActivity -import geb.mobile.android.instrumention.activities.WebViewActivity -import spock.lang.Stepwise - -/** - * Created by gmueksch on 23.06.14. - */ -@Stepwise -class AppiumWithGebMobileAutomationTestWithPagesSpec extends AppiumWithGebMobileAutomationTestBase { - - def "open test-app and enter text "() { - given: - at HomeScreenActivity - when: - myTextField = "selendroid" - then: - myTextField.text() == "selendroid" - } - - def "find Button, click and return"() { - when: - waitFor { - at HomeScreenActivity - } - startWebviewButton.click() - then: - waitFor { - at WebViewActivity - } - when: - goBack.click() - then: - waitFor { - at HomeScreenActivity - } - } - - def "find Button, click and return with back"() { - when: - at HomeScreenActivity - startWebviewButton.click() - then: - waitFor { - at WebViewActivity - } - when: - back.perform() - then: - waitFor { - at HomeScreenActivity - } - } - - -} diff --git a/src/test/groovy/geb/mobile/android/instrumention/specification/selendroid/GebMobileAutomationTestBase.groovy b/src/test/groovy/geb/mobile/android/instrumention/specification/selendroid/GebMobileAutomationTestBase.groovy deleted file mode 100644 index 4146096..0000000 --- a/src/test/groovy/geb/mobile/android/instrumention/specification/selendroid/GebMobileAutomationTestBase.groovy +++ /dev/null @@ -1,18 +0,0 @@ -package geb.mobile.android.instrumention.specification.selendroid - -import geb.mobile.GebMobileBaseSpec - -/** - * Created by gmueksch on 27.06.14. - * Base class which sets the System properties - */ -class GebMobileAutomationTestBase extends GebMobileBaseSpec{ - - static{ - System.setProperty(appUT_absolutePath, new File(ClassLoader.getSystemResource("testapk/selendroid-test-app-0.9.0.apk").toURI()).absolutePath) - System.setProperty("appUT.package","io.selendroid.testapp") - System.setProperty("appUT.version","0.10.0") - System.setProperty("appUT_cap_Emulator","false") - System.setProperty("framework","selendroid") - } -} diff --git a/src/test/resources/GebConfig.groovy b/src/test/resources/GebConfig.groovy index 5762b41..ff5ce0f 100644 --- a/src/test/resources/GebConfig.groovy +++ b/src/test/resources/GebConfig.groovy @@ -1,15 +1,14 @@ +/* + Minimum GebConfig + */ + import geb.mobile.GebMobileNavigatorFactory import geb.mobile.driver.GebMobileDriverFactory +import io.appium.java_client.AppiumDriver +Class.forName("io.appium.java_client.AppiumDriver") driver = { -// System.setProperty("appUT.package","io.selendroid.testapp") -// System.setProperty("appium_app", new File(ClassLoader.getSystemResource("testapk/selendroid-test-app-0.9.0.apk").toURI()).absolutePath) -// //To run the test on a specific device -// //System.setProperty("appium_udid","192.168.56.10:5555") -// //Use Appium -// System.setProperty("framework","appium") - GebMobileDriverFactory.createMobileDriverInstance() } diff --git a/src/test/resources/testapk/selendroid-test-app-0.9.0.apk b/src/test/resources/testapk/selendroid-test-app-0.9.0.apk index 2ee2b6b..e241ac5 100644 Binary files a/src/test/resources/testapk/selendroid-test-app-0.9.0.apk and b/src/test/resources/testapk/selendroid-test-app-0.9.0.apk differ