International Journal of Advanced Engineering Science and Technological Research (IJAESTR) ISSN: 2321-1202, www.aestjournal.org @2015 All rights reserved
292
JAVASCRIPT CODE REFACTORING USING TDD AND SELENIUM FRAMEWORK
Sanjay Singh
School of computer Science Engineering Galgotias University Greater Noida , Uttar Pradesh, India [email protected]
ABSTRACT- JavaScript is dynamic in nature hence it’s difficult to refractor with existing technologies .Refactoring algorithm that have been developed for statically type language are not applicable to JavaScript. So we propose a technique for implementing JavaScript refactoring based on Selenium framework using TDD (Test driven development). The JavaScript code refactoring must be based on functional test.
For generating test script automatically, the existing test cases will be regarded as the foundation. Hence, test cases must be designed by testers or produced through model based testing before script generating. The existing information might be described by natural language, formal or semi-formal method, but nature language and semi-formal language can hardly be accepted by computer so it should be converted into the formal uniform in order to be received by the scripts parsing tool. In addition, to prepare test scripts for JavaScript refactoring, these test cases must be run once at least along with the expected results must be gotten already. In this way, our tool can be used to accomplish
Test automation tasks from scripts generation and execution phase to the result evaluation phase Keywords- Code refactoring, Test data driven, Java Script, Selenium.
I.INTRODUCTION
JavaScript plays a central role in modern web applications. Although originally designed for simple scripting, modern JavaScript programs are complex pieces of software that involve intricate communication with users and servers. Compared to
languages such as Java and C#, relatively little tool support is available to assist JavaScript programmers with testing their applications. In current practice, JavaScript programmers construct test cases either manually or using unit testing tools with capture- replay facilities such as Selenium, Watir, and Sahi.
These tools provide functionality for recording the GUI actions performed by a user in test scripts, for running a suite of tests, and for visualizing test results. However, even with such tool support, testing remains a challenging and time-consuming activity because each test case must be constructed manually.
Obtaining reasonable coverage of an application may be difficult because of JavaScript’s event-driven style, which often gives rise to a combinatorial explosion in the number of possible executions, and because of JavaScript’s extremely dynamic nature , which makes it difficult for users to understand how to write test cases that exercise a particular feature of an application.
The goal of our research is to develop scalable and effective algorithms for automated testing of JavaScript applications to discover common programming errors of various kinds, including uncaught exceptions (e.g., runtime errors resulting from the use of undefined in a dereference or a function call), unusual type coercions or misuses of the browser’s built-in libraries, invalid HTML, AJAX HTTP errors, and violation of assertions. A prerequisite for discovering such errors is that the generated tests obtain high code coverage, which we focus on in this paper.
.
2.RELATED WORK
International Journal of Advanced Engineering Science and Technological Research (IJAESTR) ISSN: 2321-1202, www.aestjournal.org @2015 All rights reserved
293
For the JavaScript programming language, however, existing refactoring tools are less mature and often unable to ensure that program behavior is preserved.Refactoring algorithms that have been developed for statically typed languages are not applicable to JavaScript because of its dynamic nature.
Ruifeng Chen, Huaikou Miao[1] gives a novel approach of automatic test script generation for JavaScript code refactoring of Web application.
Selenium is the core platform, which provides the flexible APIs for testing automation. The XML format description of test case and test suite is the first key research. In addition, the approach to parse the semi-formal test cases in XML into executable JAVA code is another emphasis. The costs of test and JavaScript code refactoring will be reduced and the less manual interaction the few mistakes will be made. Pooja Gadave,Nilam Tule[2] There long- term goal is to automate, as much as possible, an even more expensive part of the software development process. A program with a set of input parameters; automatically generate a set of input values that, upon execution, will exercise as many program statements as possible. In automating test generation using program analysis is an old idea not theoretical tools have only started to emerge during the last few years. This recent progress was intellectual enabled by advances in the dynamic test generation which generalizes and is more powerful than a traditional static test generation [3]. Dynamic test generation with model checking to systematically execute a program achievable program path[3].If the testing process could be automated, the cost of developing software should be reduced significantly.
Of the problems involved in testing software, one is of particular relevance here: the problem of developing test data [4]. Test data generation in software testing is the process of identifying program input data which satisfy the selected testing criterion.
Harpreet Kaur,Dr. Gagan Gupta[5] Software testing provides a means to reduce errors, cut maintenance and overall software costs. Testing has become most important parameter in the case of software development lifecycle (SDLC). Testing automation tools enables developers and testers to
easily automate the entire process of testing in software development. It is to examine & modify source code. Effective Testing produces high quality software. The objective of the paper is to conduct a comparative study of automated tools such as available in market in Selenium free source, HP Quick test professional (QTP) and TestComplete (TC). The aim of this research paper is to evaluate and compare three automated software testing tools to determine their usability and effectiveness. There is wide variety of software testing tools available in market. Software testing tools has major features likes: web testing, window application etc. S.Artzi[6]
studied Current practice in testing JavaScript web applications requires manual construction of test cases, which is difficult and tedious. They present a framework for feedback-directed automated test generation for JavaScript in which execution is monitored to collect information that directs the test generator towards inputs that yield increased coverage. They implemented several instantiations of the framework, corresponding to variations on feedback-directed random testing, in a tool called Artemis. Experiments on a suite of JavaScript applications demonstrate that a simple instantiation of the framework that uses event handler registrations as feedback information produces surprisingly good coverage if enough tests are generated. By also using coverage information and read-write sets as feedback information, a slightly better level of coverage can be achieved, and sometimes with many fewer tests. The generated tests can be used for detecting HTML validity problems and other programming errors.
Sherry Singla, Harpreet Kaur [7] this thesis is to perform Automation Testing for web applications using Software Testing Tool “Selenium Web driver”.
With this web testing tool, I have developed keyword driven framework that means instead of writing multiple functions to automate driven website, we have abstracted those functions to excel files and in that excel file we are giving the steps and the program written is going to drive best on the data excel set. In this way with this web testing tool, test cases are automatically tested by using Keyword driven framework
.
Monika Sharma, Rigzin Angmo[8] have discussed various web automation testing tools which will help us to understand theInternational Journal of Advanced Engineering Science and Technological Research (IJAESTR) ISSN: 2321-1202, www.aestjournal.org @2015 All rights reserved
294
automation testing as well as the tools available for automation testing. A variety of web based systems and applications are tested by automation testing tools. The automation testing script is used in test automation. To choose the best tool for a task, various issues like ease of integration should be considered and weighed against the cost and performance. Also the tool needs to be compatible with the design and implementation of an application.N.Uppal and V.Chopra described [11] , If users wants to run recorded tests in different browsers like IE or Chrome then Selenium tools web driver has features to support with others browser . In this paper they had described Integrating Selenium IDE and web driver in one single package so that recorded tests on IDE can be run as web driver tests from single UI. Umar el Erris [12 ] proposed a testing strategy that targets Java applications with complex GUI structure and event interactions. They present a capture and replay testing technique which can be employed for different testing purposes: GUI convergence, functional testing and regression testing. The proposed strategy drastically improves, and from different aspects, on standard capture and replay tools. This is done by combining both a model based testing approach with the capture and replay approach and by implementing different automated test oracles. They first model the behavior of the system from the functional specifications or from a trusted version of the system. Tests are then derived from this model to exercise the system in order to ensure correct functional behavior and to cover goal oriented interactions
III.AUTOMATED TESTING TOOLS a.Selenium
Selenium IDE is a free and open source add-on for the Firefox web browser. It can be easily downloaded from the internet using selenium web site. It is primarily used by the Web development community to perform automated testing of web applications. In this paper firstly we analyzed the Integrated Development Environment of Selenium a Software testing tool. Secondly we have performed the black box testing of web application.
The selection of particular automated testing tool is based on the type of application we are testing and
the cost associated with the tool. In the present work, we have evaluated the open source software testing tool Selenium. Our main motive is to perform black box testing on the web application
b.QTP
Quick Test Professional is a graphical interface record-playback automation tool. Trial version of QTP can be downloaded from the official web site of HP. In this paper firstly we analyzed the Integrated Development Environment of QTP a Software testing tool. Secondly we have performed the functional testing of web application goodreads.com and we have discussed the main features of QTP. Automated testing tool QTP provides the industry‟s good solution for functional test and regression test automation – addressing every major software application and environment. Quick Test Professional also enables us to test Java applets and applications, and multimedia objects on Applications as well as standard Windows applications, Visual Basic 6 applications and .NET frame work applications. It works by identifying the objects in the application user interface or a web page and performing desired operations (such as mouse clicks or keyboard events);
it can also capture object properties like name or handler ID. HP Quick Test Professional uses a VBScript scripting language to specify the test procedure and to manipulate the objects and controls of the application under test. To perform more sophisticated actions, users may need to manipulate the underlying VBScript. Although HP Quick Test Professional is usually used for “UI Based” Test Case Automation, it also can automate some “Non-UI”
based Test Cases such as file system operations and database testing. . In the present work, we have evaluated the functional testing tool QTP. Our main motive is to perform functional testing on the web application goodreads.com and Data driven testing
c.Test Complete
TesComplete is a graphical interface record-playback automation tool. Trial version of 30 days can be downloaded from the official web site of Smartbear.TestComplete supports various testing types and methodologies: unit testing, functional and
International Journal of Advanced Engineering Science and Technological Research (IJAESTR) ISSN: 2321-1202, www.aestjournal.org @2015 All rights reserved
295
GUI testing, regression testing, distributed testing.Test Complete supports two types of applications, web Applications and window applications. Testing is a process of analyzing a software item to detect the differences between existing and required conditions and to evaluate the features of the software. It is the important phase of system development life cycle.
Software companies follow the complete software testing life cycle to test the application.
The selection of particular automated testing tool is based on the type of application we are testing and the cost associated with the tool Test Complete offers automated functional, unit, regression, manual, data- driven, object-driven, and distributed, HTTP load, stress and scalability testing in one easy-to-use it is a full-featured environment for automated testing of Windows, .NET, Java and web applications. It has been designed to free developers and QA departments from the massive drain on time and energy required by manual testing.
IV.PROPOSED SYSTEM ARCHITECTURE We propose a technique for implementing JavaScript refactoring based on Selenium framework using TDD (Test driven development).
The JavaScript code refactoring must be based on functional test. For generating test script automatically, the existing test cases will be regarded as the foundation. Hence, test cases must be designed by testers or produced through model based testing before script generating. The existing information might be described by natural language, formal or semi-formal method, but nature language and semi- formal language can hardly be accepted by computer so it should be converted into the formal uniform in order to be received by the scripts parsing tool. In addition, to prepare test scripts for JavaScript refactoring, these test cases must be run once at least along with the expected results must be gotten already. In this way, our tool can be used to accomplish Test automation tasks from scripts generation and execution phase to the result evaluation phase. This flow diagram shows step by step implementation of our research.
Fig :Proposed methodology Following typical TDD steps:
1. Write the test suit 2. Make it fail
3. Write the code to make the test succeed 4. Refractor
5. Repeat and start at Step Test Driven Development
Test Driven Development is the craft of producing automated tests for production code, and using that process to drive design and programming[11] .For every bit of functionality, we first develop a test that specifies and validates what the code will do. We then produce exactly as much code as necessary to pass the test. Then we refractor (simplify and clarify)
Write JavaScript Code
Test Performance Automatic Code Refactoring
with
Selenium framework Apply Test Driven
Development
Start
International Journal of Advanced Engineering Science and Technological Research (IJAESTR) ISSN: 2321-1202, www.aestjournal.org @2015 All rights reserved
296
both production code and test code using selenium [10]Why Use Selenium
For a task like this need a tool that can actually perform this action on their behalf. Selenium conveniently does this in a browser and this is an excellent open source tool, such that it can be modified to needs that are necessary. Selenium provides web based functional tests, and also allows the tests to be written as simple html tests, providing an interpreter that runs those actions for the develop.
Selenium is an open-source and a portable automated software testing tool for testing web applications. It has capabilities to operate across different browsers and operating systems. Selenium is not just a single tool but a set of tools that helps testers to automate web-based applications more efficiently. Tools available in the Selenium suite and their usage:
Selenium IDE Selenium Integrated Development Environment (IDE) is a Firefox plugin that lets testers to record their actions as they follow the workflow that they need to test.
Selenium RC Selenium Remote Control (RC) was the flagship testing framework that allowed more than simple browser actions and linear execution. It makes use of the full power of programming languages such as Java, C#, PHP, Python, Ruby and PERL to create more complex tests.
Selenium WebDriver Selenium WebDriver is the successor to Selenium RC which sends commands directly to the browser and retrieves results.
Selenium Grid Selenium Grid is a tool used to run parallel tests across different machines and different browsers simultaneously which results in minimized execution time.
V.RESULT & DISCUSSION
Efficiency: In our proposed algorithm Identify defects earlier and Identify cause more easily.
Higher value of test effort: Producing a more reliable system Improve quality of testing (maintain
automated tests),Minimization of schedule, Stable code base,
Reducing Defect Injection: Small “fixes” have are 40 times more error prone than
new code => Fine grained tests + run tests
After using selenium we found advantage of selenium over QTP is:
VI.CONCLUSION
This paper described the advantages of selenium with test driven development for increase efficiency of selenium IDE, selenium alone is not so efficient for perform automated testing and code refactoring. It
Selenium QTP
Selenium is an open- source tool.
QTP is a commercial tool and there is a cost involved in each one of the licenses.
Can be extended for various technologies that expose DOM
Limited add-ons and needs add- ons for each one of the technologies.
. Has capabilities to execute scripts across different browsers
Can run tests in specific versions of Firefox , IE, and Chrome
Can execute scripts on various operating systems
Works only with Windows.
Supports mobile devices
Supports mobile devices with the help of third-party tools.
Executes tests within the browser, so focus is NOT required
while script
execution is in progress.
Needs Focus during script execution, as the tool acts on the browser (mimics user actions).
Can execute tests in parallel with the use of Selenium Grids.
QTP cannot execute tests in parallel, however integrating QTP with QC allows testers to execute in parallel. QC is also a commercial tool.
International Journal of Advanced Engineering Science and Technological Research (IJAESTR) ISSN: 2321-1202, www.aestjournal.org @2015 All rights reserved
297
increase the efficiency of programmer .JavaScript is used for code refactoring. It reduce the manual interaction the few mistake will be made .In future work we will try to increase the test efficiency and reduce the effort of the testerREFERENCES
[1] Ruifeng Chen, Huaikou Miao ,”A selenium based approached to automatic test script generation for Refactoring java Script”,2013 IEEE
[2]Pooja Gadave,Nilam Tule,Shital Tule,Vrushali Shendge,B.Burghate,.Automated Testing Framework for rapid Application testing,PISER-15
[3]. Automating Software Testing Using Program Analysis,Patrice Godefroid, Peli de Halleux, Aditya V. Nori, Sriram K.Rajamani, Wolfram Schulte, and Nikolai Tillmann, MicrosoftResearch Michael Y.
Levin, Microsoft Center for Software Excellence September/October 2008.
[4]. BOGDAN KOREL, MEMBER, Automation test generationIEEE TRANSACTIONS ON SOFTWARE ENGINEERING. VOL.16. NO. X. AUGUST 1990 [5]Harpreet Kaur,Dr. Gagan Gupta,”Comparative Study of Automated Testing Tools:Selenium ,Quick Test professional and test complete”. Interantional Jornal of Engg. Research and application.Sept-Oct 2013.
[6] S.Artzi, Julian Dolby, S.H. Jensen , A.Moller, F Tip ,”A Framwork for Automated Testing of JavaScript Web application”, ICSE May 21-28,2011 Honolulu,Hawai,,USA.
[7] Sherry Singla, Harpreet Kaur, Selenium Keyword Driven Automation Testing Framework, International Journal of Advanced Research in Computer Science and Software Engineering, Volume 4, Issue 6, June 2014
[8] Monika Sharma, Rigzin Angmo, Web based Automation Testing and Tools, International Journal of Computer Science and Information Technologies, Vol. 5 (1) , 2014, 908-912
[9] SAKSOFT: Information management specialist, Automation using selenium
[10]D. Jansen and H. Saiedian. Test-Driven Development: Concepts, Taxonomy and Future Direction. IEEE Computer September 2005
[11]Nidhika Uppal and Vinay Chopra. Article:
Design and Implementation in Selenium IDE with Web Driver. International Journal of Computer Applications 46(12):8-11, May 2012
[12] Omar El Ariss, Dianxiang Xu ,Santosh Dandey, Brad Vender, Phil McClean And Brian Slator "A Systematic Capture and Replay Strategy for Testing Complex GUI based Java Application " Seventh International Conference on Information Technology,2010