Skip to main content

Posts

Showing posts with the label javascript

Accurate Word Counter for non-Latin characters in Javascript regex

There is a problem that involves Javascript and regular expressions. The JS implementation of regexp does not support Unicode properly, for example /\b\S+\b/g regular expression will not count words with Unicode characters of many national alphabets and scripts, such as Cyrillic, Greek and Hindi. Unfortunately \S is restricted to Latin-only characters of English alphabet. To solve this problem we must explicitly include all Unicode characters. My solution is to use /([\u0080-\uFFFF\w]\u0027?)+/g regular expression instead. It covers the wide range of Unicode characters (from 0080 to FFFF) that includes all national alphabets + apostrophe symbol (0027). This regex has been tested with the following sample text and it counts all 55 words accurately, ignoring all special characters and punctuation, I used https://regexr.com to test it with this sample text that includes words from several alphabets.

Hiding a blinking caret (cursor) on the page with Webdriver and Javascript

When you use Applitools for testing, it is important to keep all pages in the same state as they used to be when the baseline Applitools screenshot was taken. In Applitools visual difference means a bug. This is why a blinking caret (cursor) can become a problem when the baseline screenshot was taken with a caret either visible or invisible, as long as the actual screenshot was captured with a different state of the caret. We can avoid this issue if we hide the caret by making it transparent before taking a screenshot in Applitools. This is how we can do it in Selenium Webdriver (Javascript bindings) (assuming that you initialized the driver object with Webdriver).

Basic setup and configuration of TestObject in Node JS for testing of a web application

If you are already using SauceLabs for automated web UI testing on mobile devices, then you could be interested in trying TestObject cloud service that was acquired and became a part of SauceLabs family in 2017. It allows you to run your existing tests on real devices (Android and iPhone). SauceLabs provides emulators, which work quite well, but, depending on the requirements of your project, you may need to execute tests on real hardware. Another reason for switching to TestObject could be using the latest version of Android OS which may not be available at SauceLabs. At the moment of posting this article the latest supported version was Android 7.1 on SauceLabs and Android 8.1 on TestObject. Luckily the transition to TestObject is quite seamless. You don't need to modify your existing automated tests, only the provider endpoint and a few capabilities. The disanvantage of using a free Testobject account is that you are limited to only a few devices which are marked as Free in th

Reading a Gitlab pipeline variable in NodeJS synchronously

I'm assuming you already created your project on Gitlab and got your personal access token . This is a simple synchronous function that reads a Gitlab pipeline variable in NodeJS using Gitlab REST API v3. It uses sync-request that is not recommended to use in a production environment, although it can be successfully used in automated testing and various scripts.

Verify conditions synchronously with CasperJS / PhantomJS

Synchronously waiting for a condition to be met in CasperJS (during AJAX calls and dynamic content loading on the page), implementation of helper methods: And now we can dynamically verify that our startup dialog has some text (in case the text is loaded by an AJAX call some time after the dialog was called):

Using querySelector in Selenium WebDriver

Sometimes it's very helpful if we are able to click some element directly, by calling JavaScript click event. For example, this can be the case when the element is not visible, or not clickable, thus we cannot use native WebDriver methods. WebDriver driver = new FirefoxDriver(); JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.querySelector('.pane .object_options .dropdown-toggle span').click();");