Skip to content

Instantly share code, notes, and snippets.

@lefthandedgoat
Last active January 11, 2018 12:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lefthandedgoat/18464c3a14e5b98c24a5 to your computer and use it in GitHub Desktop.
Save lefthandedgoat/18464c3a14e5b98c24a5 to your computer and use it in GitHub Desktop.
What to talk about in a canopy presentation
  • People (usually no F# exposure) always want to understand what &&& is ex:
    • "Some test" &&& fun _ -> url "http://www.google.com"
    • To explain this I teach them about infix operators which also helps with them understand why you can do "#name" == "Bob" and with |>
  • Its good to point out that canopy uses selenium and does not hide it at all. If you need to do something that canopy does not support, you can google for it and take the example and convert it to f#. browser is the instance of ISeleniumWebDriver
  • UI Automation works really well but is a pain because its sometimes more precise that people care about. It will uncover subtle bugs that people often time don't want to research and fix =(
  • A great property of F# is that the most recent definition of a function is the one that is used. This lets you 'override' core functionality with some that is better for you. ex if you dont like how displayed works, you can create your own version and put it in a module and open it after opening canopy.
  • When testing a web page you should think of it like a database, that changes even when you didn't do anything to it, Ajax calls, browser reorging the dom, animations etc. Putting meaningful ids/classes/data-whatever in your markup makes a HUGE difference. You don't even have to do it on all stuff. Just core pieces, like a div that wraps the left nav of your app, so you can get all <a> tags in it, and not across the whole page with #left-nav a. If you have a grid of user data, and you want to click on the row that Sue is in, often times the html will render like this <td> Sue </td> which means you cant do click "Sue" because of the white space. If you put add an arbitary attirbute like <td data-name='Sue'> Sue </td> you can write nice helper functions like let name n = sprintfn "[data-name='%s']" n and use it like click <| name "Sue"
  • Write ugly code like selectors in your page modules, along with helper functions etc, and write nice clean pretty code in your test
  • canopy supports many types of selectors by default, see here https://github.com/lefthandedgoat/canopy/blob/master/src/canopy/finders.fs#L60-L65
  • You can add more if you code follow a common convention, like with place holders for inputs etc, or if the page under test is an asp.net webforms style app that generates those nasty Ctr001_003_002_FirstName Ids, you can build add a selector that will automatically build [id $= '_FirstName'] for you.
  • You can do a LOT with CSS/Jquery selectors, but sometimes Xpath is required, for things like parent nodes in your selector etc. If you find yourself using lots of Xpath, considering adding some helper tags to other parts of your html to make navigating the dom more sane
  • Hand writting css and xpath selectors takes more knowledge but its totally worth it. Right clicking a node and letting chrome generate a css or xpath selector will lead to fragile tests.
  • If you are a developer and write some ui automation you will become MUCH more in tune with your code base, be better at development etc, its a great learning experience and most of the knowledge is transferable, css selectors are useful for jquery and css, xpath useful for xml and dom, etc.
@ashtonkj
Copy link

Thanks Chris. This is exactly the kind of info I was looking for. You're a scholar and a gentleman. And great work on canopy by the way. It makes life so much easier (I don't just use if for testing - it works wonders for screen scraping when people don't provide any api for you to use). I think one other point I will mention is that it is probably best to use phantomjs web driver as it works well and is easy to hide and deploy to build / test servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment