



















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This entry-level automation exam tests Python scripting fundamentals for test automation. Topics include Python syntax, file handling, exception management, test data creation, basic API testing, automation logic, and writing maintainable test scripts. Real-world tasks require candidates to automate small scenarios and debug faulty scripts.
Typology: Exams
1 / 91
This page cannot be seen from the preview
Don't miss anything!




















































































Question 1. Which of the following best describes an “automation‑ready” task? A) A task that requires creative decision‑making B) A repetitive, rule‑based, high‑volume process C) A one‑off manual data entry D) A task that depends on unpredictable human input Answer: B Explanation: Automation‑ready tasks are those that are repetitive, follow clear rules, and occur frequently, making them ideal for scripting or robotic process automation. Question 2. In calculating ROI for an automation project, which factor usually has the greatest impact? A) License cost of the automation tool B) Time saved per execution multiplied by execution frequency C) Number of developers involved D) Length of the source code file Answer: B Explanation: ROI is driven primarily by the time saved (in labor cost) and how often the automated task runs; high frequency magnifies savings. Question 3. Which statement correctly differentiates attended from unattended automation? A) Attended automation runs on a server without user interaction, unattended requires a user present. B) Attended automation is triggered by a user, unattended runs automatically without human initiation. C) Attended automation can only be written in Python, unattended must use PowerShell. D) There is no functional difference; the terms are interchangeable.
Answer: B Explanation: Attended automation is invoked by a user (e.g., a macro), while unattended runs on its own schedule or trigger without user involvement. Question 4. Which command creates a new isolated Python environment named “env” using the built‑in venv module? A) python - m pip create env B) python - m venv env C) pyenv install env D) pipenv --python env Answer: B Explanation: python - m venv <folder> creates a virtual environment in the specified folder. Question 5. After activating a virtual environment, which command installs packages listed in a requirements file? A) pip install - r requirements.txt B) python install requirements.txt C) pipenv sync requirements.txt D) conda install - f requirements.txt Answer: A Explanation: pip install - r <file> reads the file and installs each package with the specified version. Question 6. Which of the following is the correct way to access the third command‑line argument passed to a Python script? A) sys.argv[2]
Question 9. In Python, which of the following statements correctly imports the Path class from the pathlib module? A) import pathlib.Path B) from pathlib import Path C) import Path from pathlib D) from os import Path Answer: B Explanation: The syntax from <module> import <name> imports a specific class or function. Question 10. What is the primary advantage of using pathlib.Path over the older os.path functions? A) It only works on Windows systems. B) It provides an object‑oriented interface that is more readable and chainable. C) It automatically installs missing packages. D) It replaces the need for any file I/O operations. Answer: B Explanation: pathlib offers an OO approach, allowing path manipulations via methods and operator overloading, improving readability. Question 11. Which of the following loops will execute at least once regardless of the condition? A) for i in range(5): B) while condition: C) do … while condition (Python does not have this) D) None; Python has no loop that guarantees at least one execution. Answer: D
Explanation: Python lacks a do…while construct; all its loops may skip execution if the condition is false initially. Question 12. What will be the output of the following list comprehension? [x**2 for x in range(3) if x%2==0] A) [0, 1, 4] B) [0, 4] C) [1, 9] D) [0, 2, 4] Answer: B Explanation: range(3) yields 0,1,2; filter x%2==0 keeps 0 and 2; squaring gives 0 and 4. Question 13. Which keyword is used to define a function that can accept an arbitrary number of positional arguments? A) **kwargs B) *args C) *var D) **params Answer: B Explanation: *args collects extra positional arguments into a tuple. **Question 14. Consider the following code:
x = 10 def foo(): ## Practice Exam A) import utils.py B) from utils import * C) import utils D) include utils Answer: C Explanation: `import utils` loads the module; the `.py` extension is omitted. **Question 17. When handling file I/O, which exception is raised if the specified file does not exist?** A) IOError B) FileNotFoundError C) OSError D) ValueError Answer: B Explanation: In Python 3, `FileNotFoundError` is a subclass of `OSError` specifically for missing files. **Question 18. Which pattern correctly implements a retry mechanism that attempts a network call up to three times before failing?** A) ```python for i in range(3): try: request() break ## Practice Exam except ConnectionError: continue B)
while True: request() C)
try: request() except: pass D)
retry(request, 3) B) csv.DictReader C) csv.load_dict D) csv.getrows Answer: B Explanation: csv.DictReader maps each row to a dict using the first row as field names. Question 22. When writing JSON data to a file, which parameter ensures the output is human‑readable with indentation? A) indent= B) pretty=True C) format='json' D) line_break=True Answer: A Explanation: json.dump(..., indent=4) adds whitespace for readability. Question 23. Which regular‑expression pattern matches an email address of the form [email protected]? A) \w+@\w+\.\w+ B) [a-z]+@[a-z]+.[a-z]+ C) .+@.+\..+ D) [\w.-]+@[\w.-]+\.[a-zA-Z]{2,} Answer: D Explanation: Option D correctly allows letters, digits, underscores, dots, hyphens, and enforces a top‑level domain of at least two letters. Question 24. In the openpyxl library, which object represents an individual worksheet?
A) Workbook B) Worksheet C) Sheet D) ExcelSheet Answer: B Explanation: openpyxl.Workbook contains Worksheet objects accessed via wb.active or wb[sheetname]. Question 25. Which HTTP status code indicates that the client’s request was successful and a resource was created? A) 200 B) 201 C) 202 D) 204 Answer: B Explanation: 201 (Created) signals that a new resource has been successfully created. Question 26. When using the requests library, which method sends a POST request with JSON payload automatically encoded? A) requests.post(url, data=json_data) B) requests.post(url, json=json_data) C) requests.post(url, payload=json_data) D) requests.send(url, json=json_data) Answer: B Explanation: The json= parameter serializes the object to JSON and sets the appropriate header.
Explanation: button.submit-btn selects <button> elements that have the class submit-btn. Question 30. When automating a browser with Selenium, which method clicks on a web element stored in variable elem? A) elem.select() B) elem.click() C) elem.press() D) elem.activate() Answer: B Explanation: click() triggers a mouse click on the element. Question 31. Which Python module provides a simple way to schedule recurring jobs without external cron? A) schedule B) timeit C) threading D) joblib Answer: A Explanation: The schedule library lets you define jobs with every().day.at() etc., and run them in a loop. Question 32. In the logging module, which log level is intended for detailed diagnostic information? A) INFO B) DEBUG C) WARNING
Answer: B Explanation: DEBUG is the lowest level, used for verbose debugging output. Question 33. Which handler writes log records to a file named app.log? A) logging.StreamHandler('app.log') B) logging.FileHandler('app.log') C) logging.ConsoleHandler('app.log') D) logging.OutputHandler('app.log') Answer: B Explanation: FileHandler directs logs to a specified file. Question 34. Which of the following smtplib methods initiates a TLS‑encrypted session after connecting? A) starttls() B) enable_tls() C) secure() D) encrypt() Answer: A Explanation: SMTP.starttls() upgrades the connection to use TLS. Question 35. In a Windows environment, which command creates a scheduled task that runs script.py daily at 02:00? A) schtasks /create /tn "MyTask" /tr "python script.py" /sc daily /st 02: B) taskschd /new /name "MyTask" /run script.py /daily 02:
B) is_file() C) is_dir() D) is_path() Answer: B Explanation: is_file() returns True only if the path exists and is a regular file. Question 39. Which of the following code snippets correctly creates a dictionary comprehension that maps numbers 1‑5 to their squares? A) {x: x**2 for x in range(1,6)} B) [x: x**2 for x in range(1,6)] C) dict(x, x**2 for x in range(1,6)) D) {x, x**2 for x in range(1,6)} Answer: A Explanation: Dictionary comprehensions use {key: value for ...} syntax. Question 40. In Python, which built‑in function can be used to convert an iterable into a list? A) tuple() B) set() C) list() D) dict() Answer: C Explanation: list(iterable) returns a list containing the items from the iterable. Question 41. Which exception should you catch to handle a failed HTTP request due to a timeout using the requests library?
A) requests.HTTPError B) requests.ConnectionError C) requests.Timeout D) requests.RequestException Answer: C Explanation: requests.Timeout is raised specifically when a request exceeds the timeout limit. Question 42. Which of the following statements about *args and **kwargs is true? A) *args captures keyword arguments, **kwargs captures positional arguments. B) Both must appear together in a function definition. C) *args must appear before any regular positional parameters. D) **kwargs must appear after any *args in the parameter list. Answer: D Explanation: The correct order is def func(pos1, *args, **kwargs): .... Question 43. Which shutil function copies a single file while preserving its metadata? A) copy() B) copy2() C) copyfile() D) move() Answer: B Explanation: shutil.copy2() copies the file and attempts to preserve metadata such as timestamps.
Question 47. Which log level should be used for messages that indicate a recoverable problem that does not stop program execution? A) INFO B) DEBUG C) WARNING D) CRITICAL Answer: C Explanation: WARNING signals an issue that may need attention but doesn’t abort the program. Question 48. Which of the following statements about Python’s with statement is correct? A) It can only be used with file objects. B) It ensures that the entered context’s __exit__ method is called, even if an exception occurs. C) It automatically retries the block on failure. D) It replaces the need for functions. Answer: B Explanation: The with statement guarantees cleanup by invoking __exit__ regardless of exceptions. Question 49. Which pathlib method returns the file name and extension of a path as a string? A) name() B) stem() C) name
D) suffix Answer: C Explanation: Path.name returns the final component, including extension; stem returns name without suffix. Question 50. In a REST API, which status code indicates that the client is not authorized to access the requested resource? A) 401 B) 403 C) 404 D) 500 Answer: A Explanation: 401 (Unauthorized) means authentication is required or failed; 403 means authenticated but forbidden. Question 51. Which of the following Python statements correctly appends a new row to a CSV file using csv.writer? A) writer.writerow(['a','b','c']) after opening file with mode 'a' B) writer.write(['a','b','c']) after opening file with mode 'w' C) writer.addrow(['a','b','c']) D) writer.append(['a','b','c']) Answer: A Explanation: Opening the file in append mode ('a') and calling writer.writerow() adds a new row. Question 52. Which of the following is a correct way to parse a JSON string s into a Python dictionary?