DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Coding for Workarounds So You Know When They Are Fixed

Coding for Workarounds So You Know When They Are Fixed

Alan Richardson talks about how handy the act of setting up your code to detect when workarounds have been fixed can be. Read on to see an example.

Alan Richardson user avatar by
Alan Richardson
·
Jun. 17, 16 · Web Dev Zone · Opinion
Like (2)
Save
Tweet
2.35K Views

Join the DZone community and get the full member experience.

Join For Free

with most libraries you use to automate your work, you have to code workarounds.

i coded a workaround in my selenium webdriver tests because there was a bug in chromedriver which meant that cookies were created differently than other browsers.

when i upgraded to webdriver 2.53.0 and chromedriver 2.21 , i discovered i didn’t need my workaround anymore.

in the code, i had one set of code for chrome, and another set for other browsers:

// chromedriver has a bug where the domain is prefixed with '.' 
//therefore
// the app 'updates' a new cookie so when chromedriver
// returns the cookie it returns
// the first and not the updated one
if(driver.currentbrowser()== driver.browsername.googlechrome){
  acookie = getcookiewithlargestvaluenamed
               ("seleniumsimplifiedsearchnumvisits");
}else {
  acookie = driver.manage().getcookienamed(
                "seleniumsimplifiedsearchnumvisits");
}

the bug was 7499 and was fixed in the recent update to chromedriver.

how do i know it was fixed?

because i had failing @test methods.

tests in error:
  changecookievisitscountusingcookiebuilder
  (com.seleniumsimplified.webdriver.cookies.
   cookiesexercisestestworkwithextrasync): 
  chrome cookie creation issue has been resolved
  changecookievisitscount(
    com.seleniumsimplified.webdriver.cookies.
    cookiesexercisestestworkwithextrasync): 
  chrome cookie creation issue has been resolved

why did they fail (the workaround was still valid)?

because i had code that checked for that.

// this currently fails on chrome driver since
// chromedriver adds some extra cookies when it creates 
// a cookie with a domain
// https://code.google.com/p/selenium/issues/detail?id=7499
if(driver.currentbrowser() != driver.browsername.googlechrome){
  assertequals("we added the cookie correctly", cookiecount, 
               driver.manage().getcookies().size());
}else{
  if(driver.manage().getcookies().size()==cookiecount){
    throw new runtimeexception(
                 "chrome cookie creation issue has been resolved");
  }
// also chromedriver now adds a '.' in front of the domain
}

i added extra code to throw an error if the problem i was coding a workaround for went away.

i don’t know if that is a normal practice. but since i don’t really want workarounds in my code forever, and i likely won’t remember to check the release notes on every fix to see if i coded a workaround for a fix. this seems like a good workaround to check if workarounds are no longer good.

the code i was using to check for the largest value in a cookie, by the way, was:

private cookie getcookiewithlargestvaluenamed(string cookiename) {
    int largestcookieval=0;
    cookie largestcookie=null;
    for(cookie acookie : driver.manage().getcookies()){
        if(acookie.getname().contentequals(cookiename)){
            int cookieval = integer.parseint(acookie.getvalue());
            if(cookieval>largestcookieval) {
                largestcookieval = cookieval;
                largestcookie = acookie;
            }
        }
    }
    return largestcookie;
}
Workaround Coding (social sciences)

Published at DZone with permission of Alan Richardson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Composable Architecture
  • How to Determine if Microservices Architecture Is Right for Your Business
  • 5 Steps to Strengthen API Security
  • Modernizing Testing With Data Pipelines

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo