문제

Does anyone have an examples or experience of writing UI automation in a functional language? I'm currently learning F# to get a better understanding of functional concepts and I'm having difficulty working out how an automated UI test would be structured in a functional language - seems easy to use the same page/screen object patterns I would in Java or C#, but given lack of experience I'm curious if there's a different approach I've missed.

도움이 되었습니까?

해결책

Your biggest win with using a functional language will come from not having to use classes at all, but being able to when they are the right answer. Also, F# allows for a nice clean 'dsl' looking test suite because of type inference and the syntax. Common actions (example: logging in) are easily abstracted into a function and called within a test. Any function that is very specific to a page can be added to that page's module along with its defining features (css selectors etc).

Here is an example of a test written with canopy

test(fun _ ->
    //description of the test
    describe "registering a user"

    //go to root
    url "/" 

    //ensure that you are on the login page
    on "/Account/LogOn" 

    //click the registration link
    click "form a[href='/Account/Register']" 

    //verify that you were redirected
    on "/Account/Register" 

    //set the value of the input to email address specified
    "#Email" << "username@example.com"

    //set the value of the input to "Password"
    "#Password" << "Password" 

    //set the value of the input to "PasswordConfirmation" 
    "#PasswordConfirmation" << "Password" 

    //click the register button
    click "input[value='register']" 

    //verify that you were redirected
    on "/" 

    //log off after test
    url "/account/logoff"  
)

More about canopy

I've written a Web automation framework/library in F# (also one in Ruby) and thus far, while I wouldn't consider its style to be functional, it doesn't have any classes. Almost everything is a function. Your test suite is a list of functions that are run.

github page
some examples

With < 500 LoC there are only 3 modules, the main set of functions to interact with your page, a simple test runner, and some configuration variables. At this point this paradigm has worked really well for me. I don't use classes for page definitions because for me, a page definition is as simply the css selectors I use. A module with a bunch of values fulfills this need nicely.

Give it a shot, I think you will find it to be an excellent way to accomplish your goals.

Sorry first time post so it wont let me show more links. Look on github and you can see the source at /canopy/canopy/canopy.fs

다른 팁

You seem to answer your own question, F# supports OOP, OOP is a good fit in this case, and the distinction between imperative vs functional is separate from structure in this case.

So use classes and methods just like you would in C#, but write the unit tests themselves in a functional manner.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top