Skip to main content

Aug 3, 2012 - 3 minute read - Selenium Simplified Blog WebDriver

Sporting Event Tribute Using Selenium WebDriver

As I write this, the capital city of England currently hosts a large sporting event. I can mention no names nor dates, for that sequence of words forms part of the protected thou shalt not use list. I don’t even know if ‘they’ will allow me to link to that page.

Regardless, I created a small test app which pays tribute to sporting events through the years.

 

Since I grew up in the 80s, programming on ZX Spectrums, I have a fondness for scrolly text that judders. I decided to replicate this effect using the browser title and hacking in my own text, overwriting the official text in page element.</p> <pre>((JavascriptExecutor)driver).executeScript("document.title='" + displayBanner + "'");</pre> <p> </p> <p>I don’t do this a lot when writing automated tests, but I have to confess - I don’t let the application functionality stopping me testing it. So I do sometimes force elements to be visible so that I can access them through automation. I mainly do this for exploratory automation work.</p> <p>If you have never done this before then I shall recommend now that you try it. Rule nothing out in your hunt for test automation effectiveness.</p> <p>I primarily wrote this little script to experiment with the WebDriver window positioning commands:</p> <ul> <li>(WebDriver) .manage().window.setSize</li> <li>(WebDriver) .manage().window().getPosition()</li> <li>WebDriver) .manage().window().setPosition()</li> </ul> <p>The listing from the video is below:</p> <pre>@Test public void bounceThatWindow(){ WebDriver driver = new FirefoxDriver(); driver.get("file://" + System.getProperty("user.dir") + "/jsrunner.html"); driver.manage().window().maximize(); Dimension fullScreenSize = driver.manage().window().getSize(); int changeWidth = 200; int changeHeight = 210; int xDir = 8; int yDir = 8; int xDirIncrement = xDir; int yDirIncrement = yDir; driver.manage().window().setSize(new Dimension(changeWidth,changeHeight)); Point position = driver.manage().window().getPosition(); String banner = "***BANG****........ AND THEY ARE OFF........ Automation can be fun. " + " EvilTester.com present a javascript and browser" + " animation using Selenium 2 WebDriver tribute to the" + " sporting event that cannot be named lest we be sued"; int bannerStart = 0; for(int bounceIterations = 0; bounceIterations < 1000; bounceIterations ++){ position = position.moveBy(xDir,yDir); driver.manage().window().setPosition(position); if(position.getX()>(fullScreenSize.getWidth() - changeWidth)){ xDir = -1 * xDirIncrement; } if(position.getX()<0){ xDir = xDirIncrement; } if(position.getY()>(fullScreenSize.getHeight() - changeHeight)){ yDir = -1 * yDirIncrement; } if(position.getY()<0){ yDir = yDirIncrement; } String displayBanner = banner.substring(bannerStart,bannerStart+30); ((JavascriptExecutor)driver).executeScript("document.title='" + displayBanner + "'"); bannerStart++; if(bannerStart > banner.length()-35){banner += banner;} } driver.quit(); }</pre> <p>Since I only planned to let the demo run for a short period of time you can see that I just let the banner string extend and extend and extend by continually appending the text to it. Seemed like a nice sensible shortcoming given the nature of the demo. Just a warning to you in case you decide to put this into a loop for an hour or so.</p> <p>You can find the full source listing at <a href="https://github.com/eviltester/webDriverExperiments/">https://github.com/eviltester/webDriverExperiments/</a></p> <p>Specifically <a href="https://github.com/eviltester/webDriverExperiments/blob/master/src/test/java/com/seleniumsimplified/webdriver/sports/SportsEventTributeTest.java" target="_blank">here</a>.</p> <p>The ascii animation was created using <a href="http://asciimator.net/" target="_blank">asciimator.net</a></p> <p>A fun extension, should you want a challenge, would be to create 3 windows, size them, and then have WebDriver play a game of <a href="http://en.wikipedia.org/wiki/Pong" target="_blank">PONG</a> with them.</p> <p>Enjoy.</p> </section> <div class="share-this"> <p><span class="share-text"> Share this post on: <a href="https://twitter.com/intent/tweet?text=Sporting%20Event%20Tribute%20Using%20Selenium%20WebDriver%20https://www.eviltester.com/blog/seleniumsimplified/2012-08-03-sporting-event-tribute-using-selenium-webdriver/%20via%20@EvilTester">Twitter</a>, <a href="https://www.facebook.com/sharer/sharer.php?u=https://www.eviltester.com/blog/seleniumsimplified/2012-08-03-sporting-event-tribute-using-selenium-webdriver/">Facebook</a>, <a href="https://www.linkedin.com/shareArticle?mini=true&url=https://www.eviltester.com/blog/seleniumsimplified/2012-08-03-sporting-event-tribute-using-selenium-webdriver/">LinkedIn</a> </span> </p> </div> <div class="posted-by"> <p class="meta"> <span class="byline author vcard">Posted by <span class="fn">Alan Richardson</span></span> <time>Aug 3, 2012</time> - in <a class="catlabel" href="https://www.eviltester.com/categories/selenium-simplified-blog/">Selenium Simplified Blog </a><a class="catlabel" href="https://www.eviltester.com/categories/webdriver/">WebDriver </a> </p> </div> <div class="blogs-index-links"> <p> <a href="/blog">All Posts</a> | <a href="/blog/eviltester/">Evil Tester</a> | <a href="/blog/javafortesters/">Java For Testers</a> | <a href="/blog/seleniumsimplified/">Selenium Simplified | </a> <a href="/categories">All Categories</a> | <a href="/archive">Archive</a> </p> </div> <div class="post-forward-back"> <div class="meta"> <div class="post-back"> <a class="basic-alignment left" href="https://www.eviltester.com/blog/seleniumsimplified/2012-06-15-second-edition-of-selenium-simplified-is-out/" title="Second Edition of Selenium Simplified is out"><< Second Edition of Selenium Simplified is out</a> </div> <div class="post-forward"> <a class="basic-alignment right" href="https://www.eviltester.com/blog/seleniumsimplified/2012-08-03-a-minimal-webdriver-based-dsl/" title="A minimal WebDriver based DSL">A minimal WebDriver based DSL >></a> </div> </div> </div> <div class="post-comments"> <hr/> <p style="text-align: center">You will need a <a href="https://github.com">Github</a> account to comment. Or you can <a href="/page/contact">contact me</a> with your comment.</p> <p style="text-align: center; font-style: italic;">I reserve the right to delete spam comments e.g. if your comment adds no value and its purpose is simply to create a backlink to another site offering training, or courses, or etc.</p> <script src="https://utteranc.es/client.js" repo="eviltester/blogcomments" issue-term="pathname" theme="github-light" crossorigin="anonymous" async> </script> </div> </div> <div class="sidebar"> <div> <p><a href="/agile">Hire Me - I'm an Expert</a></p> <ul> <li><a href="/page/agile/">Coaching</a>,</li> <li><a href="/page/consultancy">Consultancy</a>,</li> <li><a href="/page/services/mentoring">Mentoring</a>,</li> <li><a href="/page/services/test-automation-consultancy/">Test Automation</a>,</li> <li><a href="/page/services/consultancy/">Health Checks</a>,</li> <li><a href="/page/services/code-reviews">Code Reviews</a>,</li> <li><a href="/page/guide-to-agile-testing/">Agile Testing</a></li> </ul> </div> <div> <h2>Contact</h2> <p><a href="/page/contact">Contact Me</a></p> </div> <div class="sidebar-emaillist"> <div id="mc_embed_signup"> <form action="https://eviltester.us4.list-manage.com/subscribe/post?u=83b0fb8232910a09826751423&id=2ee9bf52d6" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate> <div id="mc_embed_signup_scroll"> <h2>Join Email List</h2> <div class="mc-field-group"> <label for="mce-EMAIL">Email Address </label> <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL"> </div> <div id="mce-responses" class="clear"> <div class="response" id="mce-error-response" style="display:none"></div> <div class="response" id="mce-success-response" style="display:none"></div> </div> <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_83b0fb8232910a09826751423_2ee9bf52d6" tabindex="-1" value=""></div> <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div> </div> </form> </div> <p class="center-text"><a href="/page/emaillist">Email Privacy Details</a>.</p> </div> <hr/> <div class="sidebar-courses"> <h2 class="title">Online Training Courses</h2> <p><a href="/page/onlinetraining/courses/#selenium-webdriver-with-java">Selenium WebDriver With Java (15+ hours)</a></p> <p><a href="/page/onlinetraining/courses/#selenium-webdriver-with-java"><img src="/images/sidebar/webdriver_course.jpg" alt="Selenium WebDriver API course"></a></p> <p><a href="/page/onlinetraining/courses/#technical-web-testing-101">Technical Web Testing Course</a></p> <p><a href="/page/onlinetraining/courses/#technical-web-testing-101"><img src="/images/sidebar/techwebtesting_course.jpg" alt="Technical Web Testing Course" class="aligncenter"></a></p> <p><a href="/page/onlinetraining/courses/#evil-tester-talks-testing">Evil Tester Talks Bundle</a></p> <p><a href="/page/onlinetraining/courses/#evil-tester-talks-testing"><img src="/images/sidebar/evil_tester_talks_course.jpg" alt="Evil Tester Talks Technical Testing Bundle" class="aligncenter"></a></p> <p><a href="/page/onlinetraining/courses/#selenium-webdriver-support-classes-with-java">Selenium WebDriver Support Classes</a></p> <p><a href="/page/onlinetraining/courses/#selenium-webdriver-support-classes-with-java"><img src="/images/sidebar/support-classes-240x126.png" alt="Selenium WebDriver Support Classes in Java" class="aligncenter"></a></p> <p><a href="/page/onlinetraining/courses"> See Even More Courses</a></p> </div> <hr/> <div> <h2>Join Our Mentoring Patreon Community</h2> <p>Gain access to hints, tips, and prompts for improving your testing skills. Regular updates, multiple times a week for as little as $1 per month.</p> <p><a href="/patreon">Learn more about Patreon Mentoring</a></p> </div> <div class="sidebar-books"> <h2>Books</h2> <a href="/page/deareviltester" title="Dear Evil Tester"> <img src="/images/sidebar/dear_evil_tester_book.png" alt="Buy Dear Evil Tester Book"> </a> <a href="/page/books/java-for-testers/" title="Java For Testers"> <img src="/images/sidebar/java_for_testers_book.png" alt="Buy Java For Testers Book"> </a> <a href="/page/books/automating-testing-api-casestudy/" title="Automating and Testing a REST API"> <img src="/images/sidebar/automating_testing_rest_api_book.jpg" alt="Buy Automating and Testing a REST API"> </a> <a href="/page/books/selenium-simplified/" title="Selenium Simplified"> <img src="/images/sidebar/selenium_simplified_book.gif" alt="Buy Selenium Simplified Book"> </a> <p><a href="/page/books/">Learn more about our books</a></p> </div> <div> <h2>Free Agile Testing FAQs eBook</h2> <p>How does Software Testing fit into Agile Projects? <a href="/page/guide-to-agile-testing">Download our free brochure</a> and find out.</p> </div> <hr/> <div> <h2>Follow</h2> <div class="social-media-icons"> <p> <a href="/page/contact"><img src="/images/icons/email.png" alt="Connect via email" title="Contact Form"/></a> <a href="https://twitter.com/eviltester"><img src="/images/icons/twitter.png" alt="Follow on Twitter" title="Twitter"/></a> <a href="https://www.youtube.com/subscription_center?add_user=EvilTesterVideos"><img src="/images/icons/youtube.png" alt="Subscribe to my YouTube Channel" title="YouTube"/></a> <a href="https://uk.linkedin.com/in/eviltester"><img src="/images/icons/linkedin.png" alt="Connect on LinkedIn" title="Linkedin"/></a> <a href="https://github.com/eviltester"><img src="/images/icons/github.png" alt="Follow on GitHub" title="Github"/></a> <a href="https://uk.pinterest.com/eviltester/"><img src="/images/icons/pinterest.png" alt="Follow on Pinterest" title="Pinterest"/></a> <a href="https://www.instagram.com/eviltester/"><img src="/images/icons/instagram.png" alt="Follow on Instagram" title="Instagram"/></a> <a href="https://www.facebook.com/eviltester/"><img src="/images/icons/facebook.png" alt="Follow on Facebook" title="Facebook"/></a> <a class="rss" href="/index.xml"><img src="/images/icons/rss.png" alt="Subscribe to my RSS Feed" title="RSS Feed"/></a> </p> </div> </div> <div> <h2>Podcasts and Videos</h2> <p><a href="/show">Podcasts</a></p> <p><a href="https://www.youtube.com/subscription_center?add_user=EvilTesterVideos">Subscribe to my YouTube Channel</a></p> <p><a href="/webtesting">Web Testing Resource List</a></p></p> </div> <div> <h2>Need some motivation?</h2> <p>Try the <a href="/apps/sloganizer.html">Sloganizer</a></p> <div class="sidebar-sloganizer"> <p class="sidebar-slogan">"<span id="sidebar-slogan">Of course I'm not evil, I just pretend to be.</span>"</p> </div> </div> <script src="/apps/sloganizer/version/4/js/sloganizer/async_slogan_call.js" defer></script> <script src="/js/sidebar_call_sloganizer.js" defer></script> <div> <h2>Recent Blog Posts</h2> <p><a href="https://www.eviltester.com/blog/seleniumsimplified/2019-11-12-abstractions-data-passing/">How to model data shared by Page Objects?</a></p> <p><a href="https://www.eviltester.com/blog/eviltester/summaries/2019-11-07-october-2019-summary/">Journaling and the October 2019 EvilTester.com and Patreon Content Summary</a></p> <p><a href="https://www.eviltester.com/blog/eviltester/slogans/2019-11-01-slogans-collated-reflection/">Good Testing Requires Technological Understanding and Appropriate Tools</a></p> <p><a href="https://www.eviltester.com/blog/eviltester/slogans/2019-10-29-slogans-collated-reflection/">On Goodness, Automation and Modelling</a></p> <p><a href="https://www.eviltester.com/blog/eviltester/slogans/2019-10-21-slogans-role-naming-attitude-purpose/">Reflections on Names, Nasty, Variation and Mystery</a></p> <p><a href="https://www.eviltester.com/blog/eviltester/2019/10/18-how-to-randomize-your-thinking/">How to Randomize your Software Testing Thought Process</a></p> <p><a href="https://www.eviltester.com/blog/eviltester/summaries/2019-10-01-september-2019-summary/">September 2019 EvilTester.com and Patreon Content Summary</a></p> <p><a href="https://www.eviltester.com/blog/eviltester/summaries/2019-09-03-august-2019-summary/">August 2019 EvilTester.com and Patreon Content Summary</a></p> <ul> <li><a href="/categories">All Blog Categories</a></li> <li><a href="/archive">Blog Post Archive List</a></li> </ul> </div> <div> <h2>Also...</h2> <p><a href="/reading">Recommended Reading List</a></p> </div> </div> </section> </div> <footer> <div class="container footer"> <div class="fifty-left"> <p>© Alan Richardson, <a href="https://compendiumdev.co.uk">Compendium Developments Ltd</a> 2012 - 2019, all rights reserved - <a href="/page/privacy">Privacy Policy</a> | <a href="/page/contact">Contact Us</a> </p> </div> <div class="fifty-right"> <div style="text-align: center"> <div class="social-media-icons"> <p> <a href="/page/contact"><img src="/images/icons/email.png" alt="Connect via email" title="Contact Form"/></a> <a href="https://twitter.com/eviltester"><img src="/images/icons/twitter.png" alt="Follow on Twitter" title="Twitter"/></a> <a href="https://www.youtube.com/subscription_center?add_user=EvilTesterVideos"><img src="/images/icons/youtube.png" alt="Subscribe to my YouTube Channel" title="YouTube"/></a> <a href="https://uk.linkedin.com/in/eviltester"><img src="/images/icons/linkedin.png" alt="Connect on LinkedIn" title="Linkedin"/></a> <a href="https://github.com/eviltester"><img src="/images/icons/github.png" alt="Follow on GitHub" title="Github"/></a> <a href="https://uk.pinterest.com/eviltester/"><img src="/images/icons/pinterest.png" alt="Follow on Pinterest" title="Pinterest"/></a> <a href="https://www.instagram.com/eviltester/"><img src="/images/icons/instagram.png" alt="Follow on Instagram" title="Instagram"/></a> <a href="https://www.facebook.com/eviltester/"><img src="/images/icons/facebook.png" alt="Follow on Facebook" title="Facebook"/></a> <a class="rss" href="/index.xml"><img src="/images/icons/rss.png" alt="Subscribe to my RSS Feed" title="RSS Feed"/></a> </p> </div> </div> </div> </div> </footer> <script> var links = document.links; for (var i = 0, linksLength = links.length; i < linksLength; i++) { if (links[i].hostname != window.location.hostname) { links[i].target = '_blank'; links[i].setAttribute("rel","noopener noreferrer"); } } </script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-40223273-4', 'auto'); ga('set', 'anonymizeIp', true); ga('send', 'pageview'); </script> <div id="amzn-assoc-ad-95a37ca4-4500-4277-a60b-a3ad533f36d9"></div><script async src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=95a37ca4-4500-4277-a60b-a3ad533f36d9"></script> </body> </html>