Hey Welcome to BTER Rajasthan Polytechnic.
1. Join Groups for PDF's & Regular Updates
Join the community of Civil Engineering students at BTER Polytechnic and stay updated:
- Telegram Channel: Join Telegram Channel 📱
- WhatsApp Group: Join WhatsApp Group 💬
- YouTube Channel: Visit YouTube Channel 🎥
2. Help & Donations 💖
If you find our resources helpful and wish to support our initiative, your donation will help us continue improving and providing valuable study material.
- UPI ID: garimakanwarchauhan@oksbi
- QR Code:
💰 Your support matters! Every contribution helps us reach more students and provide better resources! 🙏
3. Notes Website
- Official Notes Website: Visit Notes Website 📝
This website provides all study materials, notes, and important updates for Civil Engineering students.
4. Important Links
Explore the following links for additional resources and exam preparation:
- Syllabus: Download Syllabus 📚
- Previous Year Papers: View Previous Year Papers 🗂️
- Study Materials: Download Study Materials 📑
UNIT 4: Test Automation
Test automation refers to the use of specialized tools and scripts to perform tests on the software without manual intervention. This unit covers the reasons why automation is essential, when it is not ideal, how to write simple automated test cases, and explores a popular automated testing framework like Selenium.
4.1 Why Automation?
Test Automation is essential in modern software development for the following reasons:
-
Speed and Efficiency: Automated tests can run much faster than manual tests. Once the test script is written, it can be executed multiple times without human intervention.
- Example: Running 100 test cases manually might take several hours, but an automated script can complete the same tests in minutes.
-
Reusability: Automated test scripts can be reused across different versions of the application, saving time on repetitive testing tasks.
- Example: The same login test script can be reused in multiple releases or after code changes, ensuring consistency in testing.
-
Consistency: Automation eliminates human errors during test execution. The same steps will be executed in the exact same way every time.
- Example: A tester might accidentally miss a step while manually testing, but an automated test will always follow the predefined sequence.
-
Regression Testing: Automated tests are highly effective in regression testing (testing that new code doesn't break existing functionality). Once created, the scripts can be rerun quickly whenever there are changes in the codebase.
- Example: After updating a payment gateway, automated tests can quickly check that existing features like login, product addition, etc., still work as expected.
-
Cost-Effective in the Long Run: Although the initial setup for automation can be expensive, over time it reduces the cost of testing as tests can be run repeatedly with little manual effort.
- Example: For an application with frequent updates, running manual tests for every release can be expensive and time-consuming. Automation reduces these costs.
4.2 When Not to Automate?
While automation offers numerous benefits, there are some scenarios where it may not be the right choice:
-
Short-Term Projects: If the project is small or has a limited lifespan, it may not be worth investing time in automating tests.
- Example: A small prototype application that is going to be discarded in a few months might not require automation.
-
Unstable or Frequently Changing Code: If the application is still in early development or if features are being added and changed rapidly, automating tests might be time-consuming and less effective.
- Example: If the UI is being redesigned constantly, it might not be the best time to automate tests as frequent changes will require constant updates to the scripts.
-
Low-Risk or Simple Tasks: If the functionality being tested is simple and unlikely to cause defects, automating such tests may not be efficient.
- Example: Testing basic text inputs or simple calculations might be better done manually, as the automation effort might outweigh the benefit.
-
One-Time Tests: Some tests are only needed once and don’t require repetitive execution. These are better suited for manual testing.
- Example: One-time tests like installation or setup process may not justify the overhead of automation.
-
Highly Complex User Interfaces: If the application has a dynamic and complex user interface with frequent layout changes, automating UI tests can be challenging and prone to errors.
- Example: A heavily animated web application with dynamic content that frequently changes may require manual inspection and intervention.
4.3 Writing Simple Automated Test Cases
When automating tests, you typically follow a structured approach. Below are the steps for writing simple automated test cases:
Steps to Write Automated Test Cases:
-
Set up the Test Environment: Ensure that the necessary software and tools (e.g., Selenium, test libraries) are installed and configured.
- Example: Install Selenium WebDriver and set up a browser driver (e.g., ChromeDriver, FirefoxDriver).
-
Identify the Test Case: Choose a simple test case to automate. For example, testing a login page with valid credentials.
- Example: Test case: "Verify that the user can log in with valid credentials."
-
Write the Test Script: Using a testing framework like Selenium, write the script to automate the test case.
- Example: A simple Selenium test script in Java to automate a login test could look like this:
- Example: A simple Selenium test script in Java to automate a login test could look like this:
-
Execute the Test: Run the test script to ensure that the steps in the script match the expected results.
-
Verify the Outcome: After execution, verify if the test passed by comparing actual results with expected outcomes.
-
Maintain and Update: Ensure that the automated test script is maintained and updated as the application evolves (e.g., new fields, changed UI elements).
4.4 Learn and Practice a Test Automation Framework Like Selenium
Selenium is one of the most widely used frameworks for web application testing. It supports multiple programming languages (Java, Python, C#, etc.) and allows automation of browsers.
What is Selenium?
Selenium is a suite of tools used to automate web browsers. It supports various browsers and platforms and is highly extensible.
- Components of Selenium:
- Selenium WebDriver: A tool for automating web applications across different browsers. It directly communicates with the browser and performs actions like clicking buttons, entering text, etc.
- Selenium Grid: Used to run tests on different machines and browsers in parallel, which helps speed up test execution.
- Selenium IDE: A browser extension that allows for recording and playback of tests. It is great for beginners but not as flexible as WebDriver.
Getting Started with Selenium:
-
Install Selenium:
- First, you need to download and install Selenium WebDriver for the browser you want to automate (e.g., ChromeDriver, GeckoDriver for Firefox).
- For Java, you need to add Selenium WebDriver's dependency in your project using Maven or download the JAR files manually.
-
Create a Basic Script:
- After setting up the WebDriver and browser, you can begin creating automation scripts, as shown in the example above.
-
Best Practices:
- Modularize Test Scripts: Use functions or classes to make your test cases reusable.
- Use Locators Effectively: Prefer using unique locators (e.g.,
id
,name
,xpath
) for finding elements in the DOM. - Synchronization: Ensure that the script waits for elements to load (using
WebDriverWait
in Selenium) to avoid timing issues. - Assertions: Use assertions to validate test results.
-
Advanced Features:
- Data-Driven Testing: Use test data from external sources (like CSV, Excel, or databases) to run the same tests with multiple data sets.
- Headless Testing: Run tests without a browser UI, which is faster and more suitable for Continuous Integration (CI) environments.
Example of a Simple Test Case with Selenium in Python:
Summary of Topics:
- Why Automate?: Automation helps speed up testing, provides consistency, supports regression testing, and reduces long-term testing costs.
- When Not to Automate?: Avoid automation in short-term projects, unstable applications, simple tests, and for one-time tests.
- Writing Simple Automated Test Cases: Writing automated tests involves setting up the environment, identifying the test case, writing the script, and verifying results.
- Learning Selenium: Selenium is a powerful framework for web application automation. It supports multiple languages and browsers, making it ideal for cross-browser testing.
📢 🔔 Download PDF & Join Study Groups:
📥 WhatsApp Group: Join Now
📥 Telegram Channel: Join Now
📺 Watch Lecture on YouTube: BTER Polytechnic Classes
📍 Stay connected for more study materials! 🚀
Thank You for Visiting!
We wish you all the best for your studies. Keep learning, and don't hesitate to reach out for help! 📚✨
0 Comments