![]() ![]() $b.text_field(:xpath => iterate through each available word. $b.element(:xpath => when the input field is visible, click it so that you can start typing into it # wait for the words to actually show up on the screen before doing anything else # go straight to the english typing test, saves time. Then once we have all this support code set up, we can write the script: # setup the browser instance We’ll also need a function to close out the browser when the script is done, otherwise you’ll have a browser window open every time you run the script: def teardown ![]() We need a thread spun up to actually load the link we want to go to, and to shut down the thread when done: def go_to_url(url) Once we open a browser, we need a place to go. $b = Watir::Browser.new :chrome, :http_client => client # $b = Watir::Browser.new :ff, :http_client => client # set up the $b component with the info here. If you want to dig in and figure out how it works, be my guest, but it’s kind of out of scope of this article: def setupĬlient = Selenium::WebDriver::Remote::Http::Default.new Next we need a function that opens up a browser window and hooks the Watir session to it. Below is just some boiler plate code that I’ve been using for years. From here down, put all the code sections into the same script, in the order they’re presented.įirst we need to tell the script which Ruby gems to use: require "rubygems" So do the same Inspect Element operation on the text field below, and see what can be identified about it: Next, we need to find out where to actually type the word. So a locator for these words can be found by searching for the following XPath: particular XPath will give you multiple hits, which is fine, because Ruby allows you to iterate through a list of items and act on each one. Right-click on the first highlighted word and click “Inspect Element” in Chrome or Firefox. ![]() We first need to know how to tell what word to have the script type. There’s a structure to this page that will need to be known before automating. When you have finished a test, start up another one and let’s take a look at the guts of what’s going on with this page. Every time you type a word, and hit the space bar, the next word will highlight. Or automate it.įirst let’s head over to the site itself,, and click the “Start a Typing Test” button at the bottom. Plus it saves my fingers some wear-and-tear, and instead of typing here, I can type on a typing test. I won’t be digging into details much about really small details, like figuring out how to locate an element–I’m just going to put the locator in there, with minimal explanation, because I know you’re smart people and can learn more by just grabbing the code and fooling with it, than any amount of talking I do. Today I’m going to walk through a script that automates an online typing test, using that toolset. For UI automation as a hobby, I tend to use Ruby and Watir. ![]()
0 Comments
Leave a Reply. |