What Is Selenium Webdriver? Why Is It Used? Selenium Webdriver Is a Web Framework That Permits You to Execute Cross-Browser Tests
Total Page:16
File Type:pdf, Size:1020Kb
DEPARTMENT OF INFORMATION SCIENCE AND ENGINEERING Study Material for Academic Year 2020-21 (Odd Semester) COURSE NAME : SOFTWARE TESTING AND AUTOMATION COURSE CODE : ISE72 SEMESTER : V111 DepartmentofISE NHCE UNIT-5: Testing Tools: Features of Testing Tools – Guidelines for Selecting Tools – StaticTesting Tools – Dynamic Testing Tools – Advantages and Disadvantages of Testing Tools – When to use Test Tools? Junit, selenium, AutomationScripts practice. Testing Tools: Tools from a software testing context can be defined as a product that supports one or more test activities right from planning, requirements, creating a build, test execution, defect logging and test analysis. Classification of Tools Tools can be classified based on several parameters. They include: The purpose of the tool The Activities that are supported within the tool The Type/level of testing it supports The Kind of licensing (open source, freeware, commercial) The technology used Types ofTools: S.No. Tool Type Used for Used by 1. Test Management Tool Test Managing, scheduling, defect testers logging, tracking and analysis. 2. Configuration For Implementation, execution, All Team management tool tracking changes members 3. Static Analysis Tools Static Testing Developers 4. Test data Preparation Analysis and Design, Test data Testers Tools generation 5. Test Execution Tools Implementation, Execution Testers 6. Test Comparators Comparing expected and actual results All Team members 7. Coverage measurement Provides structural coverage Developers tools 8. Performance Testing Monitoring the performance, response Testers tools time 9. Project planning and For Planning Project Tracking Tools Managers 10. Incident Management For managing the tests Testers Tools Tools Implementation - process Analyse the problem carefully to identify strengths, weaknesses and opportunities The Constraints such as budgets, time and other requirements are noted. Evaluating the options and Short listing the ones that are meets the requirement Developing the Proof of Concept which captures the pros and cons Create a Pilot Project using the selected tool within a specified team Rolling out the tool phase wise across the organization Junit: JUnit is a Regression Testing Framework used by developers to implement unit testing in Java, and accelerate programming speed and increase the quality of code. JUnit Framework can be easily integrated with either of the following − Eclipse Ant Maven Features of JUnit Test Framework JUnit test framework provides the following important features − Fixtures Test suites Test runners JUnit classes Fixtures Fixtures is a fixed state of a set of objects used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well-known and fixed environment in which tests are run so that results are repeatable. It includes − setUp() method, which runs before every test invocation. tearDown() method, which runs after every test method. Let's check one example − import junit.framework.*; publicclassJavaTestextendsTestCase{ protectedint value1, value2; // assigning the values protectedvoid setUp(){ value1 =3; value2 =3; } // test method to add two values publicvoid testAdd(){ double result = value1 + value2; assertTrue(result ==6); } } Test Suites A test suite bundles a few unit test cases and runs them together. In JUnit, both @RunWith and @Suite annotation are used to run the suite test. Given below is an example that uses TestJunit1 & TestJunit2 test classes. import org.junit.runner.RunWith; import org.junit.runners.Suite; //JUnit Suite Test @RunWith(Suite.class) @Suite.SuiteClasses({ TestJunit1.class,TestJunit2.class }) publicclassJunitTestSuite{ } import org.junit.Test; import org.junit.Ignore; importstatic org.junit.Assert.assertEquals; publicclassTestJunit1{ String message ="Robert"; MessageUtil messageUtil =newMessageUtil(message); @Test publicvoid testPrintMessage(){ System.out.println("Inside testPrintMessage()"); assertEquals(message, messageUtil.printMessage()); } } import org.junit.Test; import org.junit.Ignore; importstatic org.junit.Assert.assertEquals; publicclassTestJunit2{ String message ="Robert"; MessageUtil messageUtil =newMessageUtil(message); @Test publicvoid testSalutationMessage(){ System.out.println("Inside testSalutationMessage()"); message ="Hi!"+"Robert"; assertEquals(message,messageUtil.salutationMessage()); } } Test Runners Test runner is used for executing the test cases. Here is an example that assumes the test class TestJunit already exists. import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; publicclassTestRunner{ publicstaticvoid main(String[] args){ Result result =JUnitCore.runClasses(TestJunit.class); for(Failure failure : result.getFailures()){ System.out.println(failure.toString()); } System.out.println(result.wasSuccessful()); } } JUnit Classes JUnit classes are important classes, used in writing and testing JUnits. Some of the important classes are − Assert − Contains a set of assert methods. TestCase − Contains a test case that defines the fixture to run multiple tests. TestResult − Contains methods to collect the results of executing a test case. SELENIUM FRAMEWORK: Selenium automates browsers. Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks. Selenium IDE is an integrated development environment for Selenium scripts. It is implemented as a Chrome and Firefox extension, and allows you to record, edit, and debug tests. Selenium IDE is not only a recording tool: it is a complete IDE. You can choose to use its recording capability, or you may edit your scripts by hand. With autocomplete support and the ability to move commands around quickly, Selenium IDE is the ideal environment for creating Selenium tests no matter what style of tests you prefer. Features: Easy record and playback Intelligent field selection will use IDs, names, or XPath as needed Autocomplete for all common Selenium commands Walk through tests Debug and set breakpoints All in one project file, containing all test cases and suites Selenium IDE has plugin support. Selenium WebDriver WebDriver is designed in a simpler and more concise programming interface along with addressing some limitations in the Selenium-RC API. WebDriver is a compact Object Oriented API when compared to Selenium1.0 It drives the browser much more effectively and overcomes the limitations of Selenium 1.x which affected our functional test coverage, like the file upload or download, pop-ups and dialogs barrier WebDriver overcomes the limitation of Selenium RC's Single Host origin policy WebDriver is the name of the key interface against which tests should be written in Java, the implementing classes one should use are listed as below: ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver, InternetExplorerDriv er,PhantomJSDriver, RemoteWebDriver, SafariDriver Selenium WebDriver is one of the most important parts of the Selenium test-suite family, but before directly hopping on to Selenium WebDriver, we must have a basic idea about Selenium. What is Selenium? Selenium refers to a suite of tools that are widely used in the testing community when it comes to cross-browser testing. Selenium cannot automate desktop applications; it can only be used in browsers. It is considered to be one of the most preferred testing tool-suite for automating web applications as it provides support for popular web browsers which makes it very powerful. Browsers supported by Selenium: Google Chrome 12+ Internet Explorer 7,8,9,10 Safari 5.1+ Opera 11.5 Firefox 3+ Along with this, Selenium is also capable of working on multiple Operating Systems. Multiple Operating Systems supported by Selenium: Windows Mac Linux/Unix Another reason why Selenium is gaining popularity is that it provides compatibility with different programming languages which makes it very flexible for the testers to design test cases. Programming Languages supported by Selenium C# Java JavaScript Ruby PythonPHP Note: It is not mandatory to write your Selenium code in the same language as the application. For example, if the application under test is written in PHP, then you don’t have write your Selenium code in PHP. Thus, if a website is written in C#, the Selenium code can be written in PHP too. Selenium Components The Selenium test suite comprises of four main components:- Selenium IDE Selenium RC Selenium Webdriver Selenium Grid Selenium IDE (Integrated Development Environment) is primarily a record/run tool. It is an Add-on or an extension available for both Firefox and Chrome that generates tests quickly through its functionality of record and playback. You don’t need to learn any test scripting language for authoring any functional tests. In the case of working with Selenium RC (Remote Control), one must have good knowledge in at least one programming language. This tool allows you to develop responsive design tests in any scripting language of your choice. Server and client libraries are the two main components of Selenium RC. Its architecture is complex and it has its limitations. Selenium WebDriver is an enhanced version of Selenium RC. It was introduced in the market to overcome the limitation faced in Selenium RC. Though it is an advanced version of RC, its architecture is completely