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://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://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://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://eviltester.com/categories/selenium-simplified-blog/">Selenium Simplified Blog </a><a class="catlabel" href="https://eviltester.com/categories/webdriver/">WebDriver </a> </p> </div> <div class="post-forward-back"> <div class="meta"> <div class="post-back"> <a class="basic-alignment left" href="https://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://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> <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, Coach and Consultant</a></p> </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> <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> <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 only $5 per month.</p> <p><a href="/patreon">Learn more about Patreon Mentoring</a></p> </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 class="sidebar-books"> <h2>Books</h2> <a href="http://compendiumdev.co.uk/page/deareviltester" title="Dear Evil Tester"> <img src="https://lh4.googleusercontent.com/proxy/41YWPMgqGGuWdio6jm5QoO1j-kYxSRLf629CojRLzbg_IG5-8yyQKT92KFkEzAqrSpKR4O2Pew9eWjrCgApzbqWycitmqcFRORQaddovvWP4daMSUAUsgjzkYTniTjVN5BI4-Usd6R7Bv-BsyWP4gIGuNg=s0-d" alt="Buy Dear Evil Tester Book"> </a> <a href="http://www.compendiumdev.co.uk/page/javafortestersbook" title="Java For Testers"> <img src="https://lh5.googleusercontent.com/proxy/eKRLP5Qx7nk6ctRYa5rKmIvYiARQtYbcG9FmAQFzDdtqJHh3xE-_jfXbx_3hvnNLIaawPO_crcgiTPVWHYQXv-3XnlIiMQ6f5ljsOxpx9Ea1=s0-d" alt="Buy Java For Testers Book"> </a> <a href="http://www.compendiumdev.co.uk/page/tracksrestapibook" title="Automating and Testing a REST API"> <img src="https://lh6.googleusercontent.com/proxy/KTfVJo4xAC94GrF6d6fQcQUkgnyHxcwHJg6RSeGkpmlwU17CUgK-uY5NdAWqGjqEiTkKkZMVud-EviwylZJQ9vli0H_A4Q6O2wJVtSbJK6N0MX2CwbpZLYOKhGaNL-oXALLOgLqD=s0-d" alt="Buy Automating and Testing a REST API"> </a> <a href="http://www.compendiumdev.co.uk/selenium" title="Selenium Simplified"> <img src="https://lh4.googleusercontent.com/proxy/ZjMa3A0R9xv0f51OSLCJstJeu2tdSCMUAAyxrKg4HZnfd4dGEinRkVG4gk8kdy4LIw_GYW4yntwjWdhMNiPQvRNvKQtAnxW0P93OjA9dYY9DkrkuIvuxW93kJ2Px=s0-d" alt="Buy Selenium Simplified Book"> </a> </div> <div> <h2>Need some motivation?</h2> <p>Try the <a href="/apps/sloganizer.html">Sloganizer</a></p> </div> <div class="sidebar-courses"> <h2 class="title">Online Training Courses</h2> <p><a href="http://unow.be/at/learnwebdriver">Selenium WebDriver With Java</a></p> <p><a href="http://unow.be/at/learnwebdriver"><img src="https://lh6.googleusercontent.com/proxy/hnJZKKqwCpNEahCPHzn3PFGOnIpS_oUNm9Ry9AWlgRMsjLgol3x-3J2P-VqFK4opzjeml9t3Sok0qWpcHyo3KSXvHM7oPgjwibT5q4z_aStT-2lHrtE-jLfsGtob=s0-d" alt="Selenium 2 WebDriver API course"></a></p> <ul> <li><a href="http://unow.be/at/techwebtest101">$10 Technical Web Testing Course</a></li> <li><a href="http://compendiumdev.co.uk/page.php?title=ettalkstechnical">$10 Evil Tester Talks Bundle</a></li> </ul> <p><a href="https://www.compendiumdev.co.uk/page/online_training">More Courses</a></p> </div> <div> <h2>Recent Blog Posts</h2> <p><a href="https://eviltester.com/2019/01/install-windows-git-server.html">How to install Bonobo Git Server On Windows</a></p> <p><a href="https://eviltester.com/2019/01/tactical-automation-case-study.html">A Tactical Automation Case Study - Java, JavaScript, API and Dev Tools</a></p> <p><a href="https://eviltester.com/2019/01/pro-con-but-what-if.html">Pro Con Critical Evaluation - but What If?</a></p> <p><a href="https://eviltester.com/2019/01/patreon-eviltester.html">Patreon for Software Testing and Development</a></p> <p><a href="https://eviltester.com/2018/12/merging-blogs-test-report.html">A Testing Case Study for Merging Blogs</a></p> <p><a href="https://eviltester.com/blog/seleniumsimplified/2018-12-28-tactical-selenium-ide/">Is Selenium IDE a Tactical or Strategic tool?</a></p> <p><a href="https://eviltester.com/2018/12/merging-blogs.html">New Blog RSS Feed locations</a></p> <p><a href="https://eviltester.com/2018/12/two-java-beginner-coding-tips.html">Two Java Beginner Coding Tips</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 - 2018, 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 defer="defer" src="https://code.jquery.com/jquery-1.10.2.min.js"></script><script defer="defer" src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></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>