Categories
Programming

Cypress E2E testing best practices + gotchas

Cypress E2E testing best practices + gotchas

Cypress is a new testing framework that we just moved to, so it is common to have growing pains and learning the ins and outs as we work with it more. Here are some common practices that we found to prevent any flakiness in the tests.

  • Always clean up any entities in the test suite before and after the test suite

E.g in the `beforeEach() or before()`

before(() => {

   cy.serviceVersion(‘DELETE’, ‘service-version-new’).then(() => {

     cy.servicePackage(‘DELETE’, ‘service-package-new’)

   })

 })

Also make sure to delete it in the `afterEach() or after()` as well.

afterEach(() => {

   cy.serviceVersion(‘DELETE’, ‘service-version-new’).then(() => {

     cy.servicePackage(‘DELETE’, ‘service-package-new’)

   })

 })

This will minimize any lingering entities and make the tests more independent and deterministic

  • Make sure the element you are selecting has a unique selector

Cypress will error if it finds multiple elements selected, so make sure that the element that you are selecting has a unique data-testid or selector so that it doesn’t potentially return more than one value.

       cy.get(‘[data-testid=”i-am-very-unique”]’).click()

  • Make sure you assert on elements that are unique to the page you are testing

This goes in hand with point 2, but the Cypress test environment is very eager so as soon as it finds an element matching the selector, it will act on it, even if it hasn’t navigated to the proper page yet – it will attempt to assert it on the current page if there is an matching element. So make sure the selector is unique to the page you are testing.

     cy.get(‘[data-testid=”i-only-exist-on-the-page-you-want-to-test”]’).click()

  • Be careful of using `.contains()` – it may not work the way you expect it to

In cypress, .contains() will yield a DOM element which you can chain other commands to, but it will operate under the scope of that selected DOM element. This can cause undesired assertions if we are inadvertently chaining a lot of assertions. If we just want to make a straight assertion on the DOM, we should use .should(‘contain’) instead

cy.get(‘foo’).contains(‘bar’) // everything chained after this will operate under the foo element that contained bar

cy.get(‘foo’).should(‘contain’, ‘bar’) // a straight assertion that doesn’t yield unexpected side effects when chaining

  • Try to assert on an element on the page before navigating or clicking somewhere

In Cypress, it will eagerly try to click or navigate as soon as it finds the element on the page before data is fully rendered – this leads to unexpected consequences. Instead of a .wait we can also assert on something in the page which will cause Cypress to wait until that element loads before the next step. 

cy.get(‘[data-testid=”Plugin-card”] .empty-state-content’).should(‘exist’) // this causes Cypress to wait until the KEmptyState has loaded which was a result of an XHR request returning an empty dataset. This ensures that Cypress waited for that request to finish before moving to next step.

cy.get(‘[data-testid=”entity-button”]’).click() // and then click on the entity button. Had we not done the previous assertion, Cypress would have clicked this immediately and any props or params that we got from any XHR requests would not have been set correctly.

 

Categories
Programming Tech

Interesting gadgets, JS Frameworks, Libraries, Tech Links, Tech Articles

Cool past gadgets
Sony Rolly
Sony P series
Golden-i headsets
Ultra Mobile PC
Samsung Q1
Sony CLIE PEG-UX50
HP IPAQ
HP Touchsmart TX2
Dell XPS M2010
Sony P Tablet
Oakley THUMP 2
Sony Mylo
Nokia N810
HTC Shift
Handheld PCs
HP Jornada
MM2Go
Sony Vaio Duo
Danger Hiptop/T-mobile Sidekick
Palm Treo (the first smartphone)
PDas and Pocket PCs
Sony Vaio Duo
Sony UX Micro PC
OQO Model 02
Slingbox
Roku
Archos Gen 6
Dell Adamo
Asus Taichi
Voodoo Envy 133
Asus EEE PC
Pleo RB
Alienware m11x
Dell XPS M2010
Nokia N93
Eon 13S
Soundmatters foXLv2
Dell XPS 12
Myvu Crystal
AR figure Alice
Drobo
Creative Recon3D THX sound processor
Turtle Beach Dolby processor
Astel & Kern MQS player
Custom Relics
Chromebook Pixel
Ultra sabers
Swart Amps

I read alot. Except I don’t read books, I read Wikipedia articles and nerdy articles. Lots of them.. here are few I came across:

Interesting Links/News
Someone was paid to hack Facebook exploiting Oath2?
Tells you some of the myths about guitar pickup tone
Someone actually made stacksort!! (based on an xkcd comic)
So this is the guy who started phreaking?
Chinese immigrants had it hard…
I wonder who still uses Telnet… if its always more insecure than SSH
Loved this game when I was young… didnt realize it was only released in Japan!
Super Audio CD?? I never knew this existed, I wonder if its actually audibly better than CD.
CGA is the PC’s first color standard – I remember the days of 16 colors.
Building a naive Bayes classifier, which has lots of uses in making complicated problems less complicated as it seems 😛
10,000 year old clock
Did you know MS made a JS replacement language, that adds modules, classes, interfaces and type checking?
Chinese sites look so awful and cluttered and looking at the minified JS, they even have chinese characters in JSON… omg must be a nice time parsing that
This guy ruled South Korea for 16 years until he was assassinated!! O_O
Email loops…
Vestal Virgins!
Let’s save IE6!!! hehe
The woman who had immortal cells
extreme pogo sports…
This is the first FPS game, not Wolf3D, not Doom. This game, and I played it when I was young.. pretty decent 🙂
Did you know? The first Chinese dynasty was started by this guy
The first Firefox phone?? omg
The Japanese have urinal games… wow
Prions are viral infection agents caused by eating brains o_O
This is a cool name for a Apache Ruby module
The game boy printer was really ahead of its time… people barely had dot matrix printers back then
There’s a programming language based on Lolcats
The Apple Newton had a programming language…
There’s a programming language that is multi-lingual keyworded
Woody Allen’s first movie was a 1960s Japanese dubbed spy thriller (it was a good movie, I watched it)
This was the most popular bike in the world thanks to China
Did you know? in WWI, people used pigeons to take aerial photos
Did you know? This is the worst pc game of all time, mainly cause it doesn’t work. At all.
Pig toilets… yes people used to use these
This is the crater that caused the extinction of the dinos
This is the biggest extinction event in Earth’s history
The original AI program Eliza, as a Java applet
Dunning-Kruger effecta cognitive bias in which unskilled individuals suffer from illusory superiority, mistakenly rating their ability much higher than average.
Apparently this guy lived for 152 years
A PS Emulator that was sold IN STORES
Oh yeah NeXT computers used these…
Someone sued a guy named Mike Rowe for having this domain name…
Charismatic megafauna – I suppose they are “charming” to scientists? hehe
Chinese magic mirror..
Werecats exist?
Black swan theory – this actually makes sense to me. Lots of everyday things have very small probabilities of occurring, but because there’s so many probabilities in general, the chance of any individual small probability happening is actually quite big.
RDRAM.. 😀
Wow this is a rare add-on for Sega saturn..
I used to own one of these guys before Pocket PCs were there…
This chinese woman worked on the manhatten project… at a time when Chinese people couldn’t immigrate to America.
A game console that downloads games for free? – awesome. The future of gaming is streaming from the cloud – and this is the first step.
4004 was the first available microprocessor

Nice JS articles and tech sites
http://www.json.org/JSONRequest.html
http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html
http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
http://stackoverflow.com/questions/4869609/how-can-jquery-deferred-be-used
http://perfectionkills.com/extending-built-in-native-objects-evil-or-not/
http://perfectionkills.com/whats-wrong-with-extending-the-dom/
http://coding.smashingmagazine.com/2012/11/05/writing-fast-memory-efficient-javascript/
http://www.nczonline.net/blog/2009/12/29/feature-detection-is-not-browser-detection/
http://dailyjs.com/2012/06/25/this-binding/
http://markdotto.com/2012/03/02/stop-the-cascade/
http://www.igvita.com/slides/2012/devtools-tips-and-tricks/#1
http://www.webdesignshock.com/responsive-design-problems/
http://learn.jquery.com/javascript-101/
http://www.igvita.com/slides/2012/devtools-tips-and-tricks/
http://markdotto.com/2012/02/16/scope-css-classes-with-prefixes/
Java 8 looks pretty neat.. Joda time and Lambdas
http://coding.smashingmagazine.com/2012/12/05/client-side-templating/
http://www.codethinked.com/preparing-yourself-for-modern-javascript-development
Overapi kinda sucks as a Java reference (HashTables? really?) but the jQuery reference is decent. This site also compiles a nice list of Web dev articles. Here’s another checklist for web devs.
http://www.smashingmagazine.com/
http://alistapart.com/
Good front end dev interview questions
http://52weeksofux.com/
http://www.altdevblogaday.com/2011/12/24/static-code-analysis/
http://nicolasgallagher.com/pure-css-gui-icons/demo/
http://dev.opera.com/articles/view/graceful-degradation-progressive-enhancement/
http://www.mkyong.com/
http://stackoverflow.com/questions/8659390/context-to-use-call-and-apply-in-javascript
http://net.tutsplus.com/
http://calendar.perfplanet.com/2012/deciphering-the-critical-rendering-path/
http://alexsexton.com/blog/2013/03/deploying-javascript-applications/
jQuery 2.0 beta is out!
Comparing front end frameworks
http://shichuan.github.com/javascript-patterns/
http://alexmaccaw.com/posts/async_ui
http://developer.yahoo.com/yui/yuiloader/
http://kangax.github.io/nfe/
http://webaim.org/blog/user-agent-string-history/
http://www.adobe.com/devnet/html5/articles/css-shaders.html
http://accidentaltechnologist.com/javascript/7-resources-every-javascript-developer-should-know/
http://backbonetutorials.com/organizing-backbone-using-modules/
http://stackoverflow.com/questions/1906344/should-you-only-mock-types-you-own
https://developers.google.com/web/fundamentals/
http://hackerboss.com/the-golden-rule-of-unit-testing/
http://www.programmableweb.com/apis
http://www.chromeexperiments.com/
http://chrome.blogspot.com/
http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/
http://zacstewart.com/2012/04/14/http-options-method.html
http://jtaby.com/3/modern-web-development-part-1.html
http://www.codinghorror.com/blog/2013/03/why-ruby.html
http://blog.apps.npr.org/2013/02/14/app-template-redux.html
http://marakana.com/s
http://stackoverflow.com/questions/8659390/context-to-use-call-and-apply-in-javascript
http://www.javascriptturnsmeon.com/the-tilde-operator-in-javascript/
http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html

Nice tech:

http://plumbr.eu/
http://c9.io/
http://www.plug.dj/
http://lolcode.com/
Interesting startup job repo
http://plumbr.eu/
http://www.onyxbits.de/
http://www.trypair.com/
http://newrelic.com/BFF
http://jsfiddle.net/
This is a really cool graphical tessellation generator…
http://www.hipmunk.com
http://cleverbot.com/
Combine your Chrome tabs!
http://q42.com
Firesheep

Frameworks/Libraries
(JS Library Reference can be found here)

Categories
Tech

Bioshock Infinite review, Archos tablet review

Bioshock Infinite
Just finished playing Bioshock Infinite. It’s a good game, but not as good as reviewers say. There’s reason why I will list here:
1) Low quality textures – There’s some textures that are really low quality. Most parts of the game is fine, but on some small details like doors or small objects it is noticeable on my PS3.
2) Inaccurate voice casting – The main guy is supposed to be from New York in 1912. People from NY in 1912 did not talk with a modern day California accent, they spoke with a distinct New York accent (see: Franklin Roosevelt).
3) CPUs other than Elizabeth are not exciting. Irrational Games was good with the Elizabeth CPU – its cool that she doesn’t need to be told what to do, and she’s actively looking around in her environment. But what would take this further is having all the cpus in the game be like that. For example, when I steal a drink or food from the cart, I expect people to react. When I listen in on a conversation about a guy buying hot dogs, I expect him to eventually buy and eat it, not just standing around being scripted. That part needs some work. Fallout for example, does this quite well. I can easily interact with any NPC, and all my actions have consequences. Irrational should learn a bit from Bethesda in the NPC department. (but can you imagine them doing a game together? would be awesome).

Overall the game is pretty good, but once we have all the CPUs function exactly like humans do – randomly then thats the future of gaming I think.
4) The game is short, like 12 hours, with little replay value. Thats a general trend of modern games, and one I don’t like. What happened to games like Ultima or Prince of Persia where you could play for like 100 hours? But nope, these days companies are just shipping incomplete games and gouging customers on DLC or expansions instead (you hear that Blizzard? Starcraft 1 had all the campaigns in ONE game, and people weren’t forced to buy expansions to beat the game). Yeah.. and multiplayer is often half assed. Good old 90s dedicated multiplayer games like Quake III and Unreal tournament are way better than the tack on multiplayer you find on most games these days (COD and Halo are exceptions).

Companies using programming tests and self ratings to gauge candidates
I think I wrote before about this, but let me re-iterate this, companies who use programming tests to gauge candidates are crap. It tells you nothing about the candidate, how much knowledge they actually have, how he/she would function in an actual dev environment, etc. It’s one specific problem usually, its biased based on interviewer, and there’s no hard guideline or heuristics. What is this, SAT’s? Are they evaluated based on some arbitrary score? Another thing I dislike – when people ask ‘rate yourself on a scale of 1-10 on [blah]’. What does that accomplish? An arrogant person may rate himself a 10 but is really a 5 and a modest programmer may rate himself a 5 but is really a 9. Its completely arbitrary and doesn’t tell you anything. Big companies are notorious for this.

As an interviewer, I would rather evaluate them based on white-boarding exercises (seeing the candidate do recursion in front of you is better than giving them a recursion exercise and having them google something), broad knowledge based questions (event bubbling vs event capturing), and having their number of years of experience using the language rather than a ‘rating’ of 1-10.

Archos tablet review
httpv://youtu.be/3g9W4KmyVFY
I did a review of the Archos 7 Tablet… I like this tablet mainly because it has alot of storage room, and it can record DVR videos from any A/V input source, something that tablets these days can’t do. Do check out my little PS3 demo.