Hey Alexander, Thanks for sharing your experience with WinApp Driver. It's useful to know that WebDriver API can also be used to automate tests of Windows apps.
I think that using page object in that particular context still has it benefits (single definition of content across multiple tests for example) even if defining urls and navigating to them is not a thing. With regards to having to use findElementByAccessibilityId() - you can always add a syntax sugar method for that to a geb.content.Navigable based trait and mix it into your page classes. Marcin On Wed, Dec 19, 2018 at 3:25 AM Alexander Kriegisch < [email protected]> wrote: > For what it is worth, I played around with WinApp Driver, refactored the > Microsoft > example > <https://github.com/Microsoft/WinAppDriver/blob/master/Samples/Java/CalculatorTest/src/test/java/CalculatorTest.java> > to > Geb and found out a few things: > > - You can get a pseudo HTML representation of the "page", but it does > not make much sense to create page objects because > - CSS selectors are unsupported, > - XPath selectors are unsupported, > - URLs for "to" and "at" checking do not really make sense (you could > define a synthetic page with an "at" checker, but how would you navigate to > that page?), > - element "name" values are language-dependent, > - so your best shot are the automation/accessibility IDs and a > driver-specific method called findElementByAccessibilityId(String). > - The only good news is that when extending GebReportingSpec, > screenshots work just fine. > > Provided you > > - activated developer mode in Windows, > - downloaded and also started the automation host on the default port > and > - have something like this in your GebConfig.groovy file: > > import io.appium.java_client.windows.WindowsDriver > import java.util.concurrent.TimeUnit > > (...) > > environments { > // (...) > win_app { > driver = { > DesiredCapabilities capabilities = new DesiredCapabilities() > capabilities.setCapability("app", > "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App") > def windowsDriver = new WindowsDriver(new > URL("http://127.0.0.1:4723"), capabilities) > windowsDriver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS) > windowsDriver > } > } > } > > > You can then run this test against the Windows Calculator application and > see buttons being pushed and calculations done automatically from Geb: > > package de.scrum_master.testing > > import geb.spock.GebReportingSpec > import org.openqa.selenium.WebElement > import spock.lang.Requires > import spock.lang.Shared > > /** > * Adapted from an example found at https://github.com/Microsoft/WinAppDriver > * and made to work with non-English calculator versions, too (tested with > German) > */ > > @Requires({ os.windows && sys["geb.env"] == "win_app" }) > class CalculatorTest extends GebReportingSpec { > > def setup() { > pushButtons("C") > assert calculationResult == "0" > } > > def addition() { > when: > pushButtons("1", "+", "7", "=") > > then: > calculationResult == "8" > } > > def subtraction() { > when: > pushButtons("9", "-", "1", "=") > > then: > calculationResult == "8" > } > > def multiplication() { > when: > pushButtons("9", "*", "9", "=") > then: > calculationResult == "81" > } > > def division() { > when: > pushButtons("8", "8", "/", "1", "1", "=") > > then: > calculationResult == "8" > } > > def combination() { > when: > pushButtons("7", "*", "9", "+", "1", "=", "/", "8", "=") > > then: > calculationResult == "8" > } > > @Shared > def buttonNames = [ > "1": "num1Button", "2": "num2Button", "3": "num3Button", "4": > "num4Button", "5": "num5Button", > "6": "num6Button", "7": "num7Button", "8": "num8Button", "9": > "num9Button", "0": "num0Button", > "+": "plusButton", "-": "minusButton", "*": "multiplyButton", "/": > "divideButton", > "=": "equalButton", "C": "clearButton" > ] > > def pushButtons(String... buttons) { > buttons.each { > driver.findElementByAccessibilityId(buttonNames[it]).click() > } > } > > @Shared > WebElement calculationResultElement = > driver.findElementByAccessibilityId("CalculatorResults") > > def getCalculationResult() { > return calculationResultElement.text > .replaceAll("[^0-9]+", "") > .replaceAll("[^0-9]*\$", "") > } > > } > > -- > Alexander Kriegisch > https://scrum-master.de > > > Alexander Kriegisch schrieb am 18.12.2018 17:49: > > > I read that too late. I just came home and was able to try WinApp Driver, > > adapting the Windows Calculator example from JUnit to Geb. Because they > used > > "findElementByName" and the names are localised to German on my > platform, I had > > to fiddle around with finding out the names and translating them first, > also > > parsing the displayed result is more difficult in the German version. But > > finally it is running beutifully. I actually wanted to clean up and > refactor > > the sample code a bit for you before posting it, but it seems that your > problem > > is resolved already and you also got a running test, right? > > > -- > You received this message because you are subscribed to the Google Groups > "Geb User Mailing List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/geb-user/20181219022539.48F9766022F4%40dd39516.kasserver.com > <https://groups.google.com/d/msgid/geb-user/20181219022539.48F9766022F4%40dd39516.kasserver.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/CA%2B52dQRavqDdyDbeDS9b0OeE7cmqCggT9cAa-DrGFod%2BpwJ5DA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
