Monday, August 5, 2019

Automated UI Testing with Selenium and JavaScript

Selenium is great, and it can be integrated with many different languages, and today I will show you how it can be done with JavaScript. This is an ongoing project, and I plan to update more examples or test cases in the future, so feel free to ask questions and create tickets on the project.

1. Installation

You need to install either Yarn or Node on your machine. In this project, I will use Yarn for installing packages and running scripts.

First, we need to start a project

yarn init
OR
npm init

Then install dependencies

yarn add chromedriver selenium-webdriver
yarn add mocha -D

2. Getting Started

After that, we can start writing our test cases

// test.js
// Import requirement packages
require('chromedriver');
const assert = require('assert');
const {Builder, Key, By, until} = require('selenium-webdriver');
describe('Checkout Google.com', function () {
    let driver;
    before(async function() {
        driver = await new Builder().forBrowser('chrome').build();
    });
    // Next, we will write steps for our test.
    // For the element ID, you can find it by open the browser inspect feature.
    it('Search on Google', async function() {
        // Load the page
        await driver.get('https://google.com');
        // Find the search box by id
        await driver.findElement(By.id('lst-ib')).click();
        // Enter keywords and click enter
        await driver.findElement(By.id('lst-ib')).sendKeys('dalenguyen', Key.RETURN);
        // Wait for the results box by id
        await driver.wait(until.elementLocated(By.id('rcnt')), 10000);
        // We will get the title value and test it
        let title = await driver.getTitle();
        assert.equal(title, 'dalenguyen - Google Search');
    });
    // close the browser after running tests
    after(() => driver && driver.quit());
})

3. Run The Test Case

It is a good practice to add scripts to package.json.
// package.json
"scripts": {
   "test": "mocha --recursive --timeout 10000 test.js"
},
Whenever you want to run the test, just use this command:
yarn run test

The below result shows that the test has been successfully completed.

dnguyen$ yarn run test
yarn run v1.9.4
$ mocha --recursive --timeout 10000 test.js

Checkout Google.com
    ✓ Search on Google (2058ms)
1 passing (3s)

✨  Done in 3.79s.


Read more here

Thursday, August 1, 2019

7 Major Advantages Why Enterprises Should Prefer Selenium Test Automation

Summary: No matter what the domain or company, there are some common problems that always tend to affect new automation projects. Here are 7 advantages that companies prefer to choose Selenium Test Automation.

Software test automation is the way where the future vision of testing is heading upon. Automation testing uses automation tools to reduce human intervention and keep a check on the mundane human repeatable tasks. These varied automation tools are available as open-source and paid tools. 

Whenever we talk about automation testing, Selenium is as an open- source tool which is widely used by testers and developers across the globe. Selenium tool is best suited and used for as an automated testing suite for all web applications across browsers and delivers good results for wall tests as it is an integral part of the automation testing.


Some of the Benefits with Software Test Automation


· Helps to find bugs at an early stage
· Testing becomes easy with pre-recorded and predefined actions
· It becomes easy to compare test results to expected behavior and report the success or failure
· Testing can be done from any device even from remote
· Automated tests are reusable and are more dependable than manual test outcomes
· Shortens overall testing time when compared to manual testing
· Testers can reuse the code on different versions of the software
· Lowers overall testing costs
· Ensures faster time to market and generates quicker ROI

Coming to the major advantages Enterprises need to select Selenium test automation are:


1. Open Source Tool: Selenium is available as an open-source tool and is a publicly accessible test automation framework. There is a separate community for all open-source tools wherein they continuously add new features and functionalities to make it more viable for developers and automation engineers.

2. Supports Many Languages: 

The ease of this tool is its flexibility to support all languages such as Ruby, Perl, Java, Python, JavaScript, C#, programming languages wherein scripts can be written and selenium converts them into selenium compatible codes. Every selenium supported language certainly has dedicated frameworks that help in writing test scripts for selenium automation testing.

3. Ease of usage due to Multi-Browser Support: 

The major advantage with this tool is, it supports all web browsers such as Chrome, Firefox, Internet Explorer, Opera, and Edge browsers. The most useful feature is there is no explicit need to rewrite the selenium scripts separately for each of the browsers, but rather a single script holds good for all.

4. Effective tool for Web Applications: 

It enables to record and playback for testing web applications and can run multiple scripts across various browsers such as IE, Firefox, Chrome, etc. In addition, this framework is highly useful for developers as they can analyze the code due to screen shot property. The tests are very easy to maintain and it is also easy to repair the test suites of the application using this framework.

5. Ensures Parallel Test Execution: 

Any automated testing is taken up to ensure that testing time is saved and equivalent human effort is saved such that the tester can be used for other activities. With the help of selenium grid, the tester can execute multiple tests in parallel, thus reducing the overall test execution time.

 6. Cross Browser Support with Its Flexibility for Testing:

It is a highly flexible tool for testing functional and regression test cases and also supports cross browsing where the test cases run across various platforms simultaneously. Another suitable feature of the tool is that it helps in creating robust and browser-based regression automation suites to perform tests.

7. Selenium Suite of Tools:  

It is mainly composed of four tools such as Selenium IDE, Selenium RC, Selenium WebDriver and Selenium Grid. Each of these tools effectively support for record & playback for scripts, supports every web browser, accepts commands and sends them to a browser and selenium WebDriver API helps in communication between languages and browsers.

Thus, after overviewing all the above features, enterprises can choose this as a promising tool for all your web applications testing due to the overwhelming features it is embedded with. Selenium testing services can be leveraged to get your applications tested thoroughly to achieve faster time to market and quicker ROI.

Courtesy by:  https://www.bloglovin.com/@testingxperts/7-major-advantages-why-enterprises-need-to