Unit tests or end-to-end tests in web apps? How to decide

Clicking elements

$('.submit-button').click();

Pressing keys

$('.username').sendKeys('john.doe');

Get the number of elements

$$('.items li').count();

Navigation & routing

$('a#bing-link').click();browser.get('https://www.bing.com');
expect(await browser.getCurrentUrl()).toBe('https://www.bing.com');

Hovering elements

browser.actions().mouseMove($('#go-top-button')).perform();

Checking whether elements are present / visible

$('#submit-button').isPresent();$('#submit-button').isEnabled();

Responsive testing

expect(await $('#menu-toggle').isPresent()).toBe(false);
browser.driver.manage().window().setSize(640, 360);
expect(await $('#menu-toggle').isPresent()).toBe(true);

Getting cookies / window storage

browser.manage().getCookies();
browser.executeScript('return localStorage.getItem("' + item + '");');

Getting HTML attributes

$('.user-table').getAttribute('class');

Scrolling (e.g. to an element)

browser.executeScript(`document.querySelector(${selector}).scrollIntoView()`);

Drag & Drop

browser.actions().
dragAndDrop($('#source'), $('#target')).
perform();

Conclusion

Senior Software Engineer @LeanIX. Co-founder of Sedeo. Passion for software engineering and startups. Looking forward to build great things. 有難うございます。🚀

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store