Selenium-Based Multithreading Functional Testing

In a software development projects, testing is an activity that can spend time, effort or cost up to 35%. To reduce this, developers can choose automatic testing. Automated testing, especially for functional testing, on web applications can be done by using tools, one of which is Selenium. By default, Selenium testing is done sequentially and without exploiting multithreading, which has an impact a sufficiently long time. In this study, a platform that allows Selenium users to test and utilize multithreading with Ruby language to speed up testing was developed. Thr result shows that Ruby's multithreading has proven to be capable of speeding functional testing up on various web applications. Variations occur depending on the functionality being tested, the testing approach and also the type of browsers used..


INTRODUCTION
Finding defects in a software before its official release is compulsory, as studies revealed that fixing bugs in early steps of software development will minimize cost significantly.Finding such defects in the maintenance phase might incur cost up to 100% compared to that of the design phase [1].One of the approach to achieve that saving is by carrying out a software testing.Unfortunately, software testing itself is an activity that might consume about 30% up to 35% of the total effort in the project [2] [3].To overcome such situation, developers choose to apply automatic testing, which means that the test can be repeated many times on the software  ISSN (print): 1978-1520, ISSN (online): 2460-7258 IJCCS Vol. 12, No. 1, January 2018 : 63 -72 64 under test.This automatic testing is carried out also using tools or software.
Among existing testing types, functional testing is the most frequently carried out testing using automatic testing approach, including for a web application.Functional testing aims at verifying the software under test whether or not it has met predefined requirements and focusing on comparing input given into its forms with output and status that should be accepted [4].Several tools are available for functional testing for a web application, one of them is Selenium.By default, script in Selenium is executed in a single thread, leading to consequence that all test cases will be done sequentially or serially.In carrying out functional testing for a web application, access to I/O devices and network device will be much greater than access to CPU, and the testing script will be waiting for more (for the data to be completely processed).This waiting time will be minimized by increasing the access to CPU by multithreading approach.By now, it is still difficult to find tools for web application testing which provide support for multithreading and direct access to web driver API.
Based on what has been described above, this research will discuss the use of Selenium as a tool for functional testing with several test cases provided by users, and they will be executed in multithreading way to improve efficiency and shorten the testing time duration.
An automated testing tools based on Selenium, combined with Fitnesse, was introduced to and enabled users to carry out a testing collaboratively [5].It was mentioned in the paper that even though Selenium is not a tool to solve any problems in testing, the existence of an increase in its community, both either users or developers, indicates that Selenium was quite promising to be used in functional system testing in future.
Another research related to Selenium has also been conducted on the topic of automated browsing on AJAX website [6].In the research, Selenium can recognize only some specific events, meanwhile in AJAX requests may happen in various types of event.The reduction of the event was aimed at avoiding event flooding, that is the number of events captured by listener such that it is beyond being effective and efficient.
Beside Selenium, Sahi is also a quite popular tool for automatic testing on a web application domain.Both Selenium and Sahi have their own advantages and disadvantages.In [7], both are compared in terms of test-case creation time, test execution speed, installation and configuration, record and playback, logging and reporting, cost, and platform compatibility.It disclosed that Selenium was leading in terms of test-case creation time, single thread execution time, logging and reporting, and ease of installation, while Sahi provides a feature of executing test cases in parallel which enable users to shorten test execution time if such feature is activated.
Other research on automatic testing using Selenium disclosed that Selenium-based functional tests for the web application are modified as the project evolve [8].In other words, the paper called that it co-evolved with WAUT (web application under test).
Selenium comes in two version: IDE and Webdriver.Both versions were discussed in [9] which compares capture-replay web testing (using Selenium IDE) with programmable web testing (using Webdriver).Testing an application requires the development of test suites.These facts mean more time is needed.When programmable web testing is adopted, such time is more expensive but the test suite maintenance is less expensive.In cumulative, using programmable web testing, cost becomes lower compared to that of capture-replay approach.
By default, Selenium does not provide configuration file which makes ease users in doing testing based on existing configuration.An effort to improve testing features based on Selenium by incorporating configuration file, Junit report and parallel testing for each browser into Selenium model is discussed in [10].This testing was executed in Python.
In [11], an extension of Selenium to accommodate testing web application which accesses database claim that the proposed approach could reduce efforts of executing test case suites up to 88% compared to semiautomated strategy, and 92% compared to manual IJCCS ISSN (print): 1978-1520, ISSN (online): 2460-7258  Selenium-Based Multithreading Functional Testing (Khabib Mustofa) 65 strategy.The extension will read the contents of the database and compare them with the test output.The access to a database is carried out at the same time the test case is being executed.

System Architecture
In this research, a computer will be used with the following configuration: 1.The main computer is running natively on Windows 10 which will act as the tester.2. A virtual machine is running on top of the Windows to execute Linux Ubuntu version14.10with a web server inside.The application to be tested is running on this web server.3. On the main computer, text editor, Selenium Webdriver and Visual Studio have been installed as the tools for the system development.

Testing the Platform
The proposed platform uses a command line as the interface.It was developed in Ruby and utilizing JSON for storing data and testing configuration to be executed.Basic use of the script to start a testing platform is as follows: In the above command, the name of the platform is coba and its first parameter, test, is the command to do the testing.The next parameter is the address of the configuration file.This configuration file might include default browser, address of the Selenium script to be executed, address of the test case file for data input, number of thread to be used (minimum 1), and configuration of the input form to be tested.While the last parameter, browser_name, may be used if the user wants to override browser configuration.Figure 1 shows the architecture of the testing platform.
From Figure 1, it can be explained that: 1. Test Suite consists of scripts, configuration, and test-case input Here, all the data will be processed as the preparation step before testing 3.In this Test Runner, there will be adjustment or assignment of the port (which will be used to communicate between Selenium with driver), work queue, and thread pool (which will arrange execution of each work queue into thread).As it is important in multithreading to follow thread-safety, it is necessary to implement the thread such that shared variables are not overlapping.
In Ruby, a class named Queue which has the characteristic of following threadsafe concept is used in the implementation of the platform.Besides, as there are some lines of code which need to be executed in interleaving way, a class Mutex (Mutual Exclusion) is used to ensure that the execution of threads is synchronized, thus, consequently, the data consistency can be maintained.4. Each thread executes Selenium script through Selenium Wrapper.This wrapper contains functions which will execute our scripts.It will also store a log of execution in JSON format and report the execution status via command line interface.

Test-case Generator
Similar to the testing platform, Test-case Generator runs with command line interface.Test-case Generator is basically a script, written in Javascript, whose main task is to generate test-case consisting of input and output.Figure 2 shows the architecture of the test-case generator.
To generate input, a validation is required by the application to be tested.As an illustration, if there is a field name of input form that must be filled in with minimum 4 characters and maximum 20 characters, then this input field will have validation: required, min:4 and max:20.These validations are then used to generate input for the input field.
There are several validations supported by the proposed platform: 1. required 2. max:x 3. min:y 4. emai 5. alpha Those validations need be written in a configuration file copied from the template on the phase of test suite composition.For the example of input field name, the validation can be represented in the form of an array as shown in Figure 3.
It was mentioned above that there is a limited number of validation offered in this platform.If needed, user or tester may add custom validation by creating a file in the validation folder and being saved in Javascript format.All of the input test cases generated will be saved in a JSON file defined in the configuration file.
In generating input test case, the platform utilizing total combination or number of subset formula to determine the number of possible values for the input validation defined.To illustrate the process, the following description will refer to the case as explained in Figure 3.
Based on Figure 3, it is clear that the validation consists of three elements: required, min:4 and max:20.Using total combination formula, it can be calculated that there should be 8 subsets as depicted in Table 1.Suppose that an input field satisfies only proper subset of the set containing all validation elements, then it can be said that there is/are missing rule(s), and this missing rule(s) will be used to generate a conclusion determined using a regular expression.In the proposed platform, the regular expressions are formed using Javascript library called randexp.js.For a case with more than one input fields, the formula will be adjusted by applying the product of all sets involved.As an illustration, if a form has two input fields: the above-mentioned name field and a field whose validations are email and required.From the second field, it can be derived that the subsets generated would be 4. Thus, there will be 8 x 4 = 32 possible combination of validation cases.In general, the number of possible combination of validation cases could be represented as Eq. 1.

Table 1 Total combination of input test case with 3 validation
where C i = 2 k , k is number of validation elements for field i.
Output test case generation can only happen when input test case generation has already been completed.The output test case generator will access the file (if exist) containing the results of input test case generation, and then process it to obtain values of possible response from the application to be tested, otherwise, it will throw an error message.

Testing Design
Testing is carried out using the proposed platform by considering the following factors:

Environment Condition
In order to achieve a good and reliable quality of data, the environment of testing should be adjusted to be in a relatively similar condition.As the testing platform runs on Windows, the operating system is ensured to run in a clean boot; that is the OS only loads services necessary for the OS itself and without any third party services running.This conditions can be achieved among others by: 1. disable all non-Windows services.Users can do this step by using dialog provided by Windows from msconfig command and then configure such options.

disable startup program. Users do this configuration by disabling all items in Start Up
tab available in Task Manager.

Testing Process
The followings are basic steps in testing the proposed platform.
1. Preparing the test.In this stage, some files must be prepared, depending on the features to be tested.At the minimum, four files should exist: three Selenium scripts (script before testing, testing script, and script after testing) and one configuration file 2. Generating input and output test cases.Validations on the forms to be tested are added into the configuration file.If the testing does not use input/output test case generator, testers/users may create JSON file containing arrays of object accordingly.3. Testing script creation.A testing script using Selenium is created.The script will be run before the real testing to ensure that the script behaves as expected.4. Testing on the platform.The script is run on the platform developed.The platform is tested against some functional features of the WAUT: login, register, profile update, activity creation, and sub-activity creation.c.Using multithreading.In this method, Javascript method with 4 (four) threads is used.For each testing, a folder will be created to hold folders representing features of WAUT, such as folder login, register, profile update, etc.Each folder will contain configuration and test case different one with another.Database migration.As the condition of the database might change during the testing process, so it is necessary to restore the database state to the initial condition.This step is done manually each after the completion of the test for each browser.

RESULTS AND DISCUSSION
Based on some scenario or functional features as stated above, the following tables (Error!Reference source not found.,Table 3, Table 4, Table 5 and Table 6) show some results of the testing: 1.The percentage in the second row of each table means that there is positive or negative speedup of the single-thread Javascript compared to the single-thread sendKeys.Negative value means that there is slowdown in performance of the single-thread Javascript testing against the single-thread sendKeys ones.2. The first percentage of the third row means that there is positive or negative speedup of the multi-thread Javascript compared to the single-thread sendKeys.3. The second percentage of the third row means that there is positive or negative speedup of the multi-thread Javascript compared to the single-thread Javascript.
On the test using the sendKeys method, in general, Internet Explorer is much slower than others.While Firefox, Chrome, and PhantomJS are taking turns recorded the best testing time.But when the test uses Javascript method, inconsistency in performance is shown by PhantomJS and Firefox, as sometimes those browsers experience negative speedup.
There are cases where multi-threaded testing becomes slower.It only occurs in Firefox.The diagnosis of this case might be that high Firefox driver initiation time even becomes higher when multi-threaded testing is performed.This happens because basically multithreading on Ruby does not execute commands fully in parallel, but just being concurrent, and the driver initiation process is a CPU bound.Coupled with a small number of test cases, fast test execution time is not comparable to a decrease in the speed at the driver initiation time.

ConfigurationFigure 1
Figure 1 Architecture of the Testing Platform

Figure 2
Figure 2 Test-case Generator Architecture

Figure 3
Figure 3 Validation for an input field in a configuration file The testing is done on browsers which have support for Selenium: Internet Explorer version 11.0.15063.0,Firefoxversion 54.0.1, Chrome version 60.0.3112.90, and PhantomJS version 2.1.The Selenium used in the testing is of version 3.4.4., including its corresponding web driver.When the script is running, elapsed time to run the script on the platform is recorded.There are two different methods for the tests:a.Using sendKeys method to fill in the form.The method is the method recommended by Selenium as it resembles the input given by real users.The method fills in the input following the generic format Using Javascript to fill in the form.The method is introduced as an alternative as sometimes browser does not respond well the execution of the sendKeys method.The method fill in the input as illustrated below: