learned something new again
Jun. 18th, 2014 03:59 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
override def getEOBs: Outcome = { import JavaScript._ val outcome = for (_ ← clickElementHavingText("a", "My Stuff") onError suspiciousError; _ ← waitSelector("input#continue"); _ ← clickElementHavingText("input[name=dateRangeSelection]", "past year"); _ ← findElement("input[name=selectedMembers]"); _ ← js(s"$foundElement.checked = true"); _ ← clickElementHavingText("input#continue", ""); _ ← clickElementHavingText("a", "INTERNET.com"); _ ← findElementContainingText("*", "Processed"); _ ← clickElementHavingText("a", "More"); _ ← clickElementHavingText("input", "View All"); (contents, source) <- pageContents.toResultKeepingSource) yield { println(contents.toFormattedString) jsREPL("So?") } debug(s"Got $outcome"); OK }
What happens here: we do these operations, monadically, since each one depends on the success of the previous one; errors are stored in negative result. If everything went well, I grab page contents and convert it to
Result[Props]
, so the props contain all the information I managed to extract from the page.On failure the error is logged; what can we do, it requires human interference.
All this amounts to flatMap on my
Result
class.Yes, it does remind checked exception handling, but well, we are not in denial here; and we could do applicative join if needed.