Aug. 19th, 2013

juan_gandhi: (VP)
// returning value = 
      withSelector("body", 1) { // waits until <body> is available on the page
        FillFormField("body", "#FilterUC_hdn_Fromdate", yearAgoAsString).
          withErrorMessage("The page is in bad shape, could not set From Date") <*>
      withSelector("body", 1) {// takes forever to boot
          FillFormField("body", "#FilterUC_hdn_Todate", todayAsString).
            withErrorMessage("The page is in bad shape, could not set To Date")
        }
      }


What happens here:
- withSelector waits for the element to load (in this case body is kind of trivial to wait); why do I need it? bad web design, they refresh the page on every form field change...
- and then it calls the method in curlies; result is of type Result[String]
- the call .withErrorMessage means that we add an explanation to possible errors;
- the same thing happens for another element
- two results are blended ("tensor product", omfg) via <*>, which means that:
if both are good, we have Good(("OK","OK")),
otherwise we have Bad(...) with a list of error messages inside (with provided explanations);

Questions? Obvious? Funny? Weird?

I just love this style. But if you think there's a better form of expressing things...

Take 2:
      whenSelectorAvailable("body", 1) { // waits until <body> is available on the page
        FillFormField("body", "#FilterUC_hdn_Fromdate", yearAgoShortString).
          orCommentTheError("The page is in bad shape, could not set From Date")
      } <*>
      whenSelectorAvailable("body", 1) {// takes forever to boot
        FillFormField("body", "#FilterUC_hdn_Todate", todayShortString).
          orCommentTheError("The page is in bad shape, could not set To Date")
      }

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
171819 20212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 26th, 2025 07:59 am
Powered by Dreamwidth Studios