Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

MCQ 2 - Selenium - Main

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15
At a glance
Powered by AI
Some of the key concepts covered across the pages include CSS selectors, Selenium methods, TestNG annotations and features.

The 5 types of CSS Selectors are ID, Class, Attribute, Sub-String, and Inner Text.

The WebDriverWait class from the Selenium WebDriver library contains predefined conditions for handling dynamic waits.

1.

Sarah is coding in a test scenario, in which she must fetch the


booking id as a text message from the span element.
The web element looks like
<Space> order completed with Booking id:6665<Space>
Help Sarah to find a method from the webdriver library to fetch the
booking ID?
Ans - getText();

2. James is automating a script and using CSS Selector as a locator.


What are the primitive types for designing the CSS selector?
ANS - .id, .Attribute, .innerText()
(Explanation - There are 5 types of CSS Selectors in Selenium tests-
ID, Class, Attribute, Sub-String, Inner Text) SACIIT

3. Which expression is used in CSS Selectors to match the attribute


value with a prefix?
ANS- ^=
(Explanation - [attr^=value] Represents elements with an attribute name
of attr whose value is prefixed (preceded) by value.)

4. Write in correct order.


a. Triggers the build
b. Open reports to see the latest test results.
c. Jenkins checks the Git Repository periodically to detect changes in
build project.
d. The build is successful / Failure.
e. Testers/ Developers commits source code changes to the shared Git
Repository.
ANS- e,c,a,d,b

5. Kevin has designed a TestClass with the following methods:


public class TestClass {
@Test
public void testMehod1() {int a = 78;}
@Test
public void testMehod2() {Assert.assertEquals(67, 76);}
public void testMehod3() {System.out.println("Welcome");}
@Test
public void testMehod4(){Assert.assertEquals("Hello”, “Hello");}
}
Kevin executes the above TestClass as a TestNG test. Which of the
following correctly represents the test result?
ANS - Total tests run: 3, Passed: 2, Failed: 1
6. Identify the correct way of launching the Chrome browser through
WebDriver instance with the correct property.
ANS -
System.setProperty("webdriver.chrome.driver","src/test/resources
/chromedriver.exe");
WebDriver driver = new ChromeDriver();

7. Samantha wants to write an automation script that determines the


count of Hobbies checkboxes. These checkboxes have a name
attribute as “hobbies”. Assist Samantha by choosing the correct
command.
ANS –
driver.findElements(By.name(“hobbies”)).size()

8. Henry is designing a script and using CSS Selector as the locator


strategy. He must locate the element effectively. The element
inspected looks like:
<input id=“newPassword” type=“password”>
ANS - By.cssSelector("input[id$='Password']")

9. Kevin is automating a test scenario. In which he wants to locate an


element with the class attribute “classg1 jkyu_90”. Assist Kevin in
setting up the correct locator for the element.
ANS - By.className(“classg1”)

10. Select the correct order of execution of annotations, as per the life
cycle of the TestNG which can be applied for test methods along
with beforeXXXX – afterXXXX methods. TCM
ANS - @BeforeTest, @BeforeClass, @BeforeMethod, @Test,
@AfterMethod, @AfterClass, @AfterTest

11. Sean is coding an automation script for emulating user actions by


mouse actions using webdriver library. Assist Sean to choose the
correct syntax to create an object for Actions class from the
following options.
ANS -
Actions act = new Actions(driverinstance) correct ans :option 1
Actions act = new Actions()
Actions act = (Actions)driverinstance
12. Kevin is using a CSS Selector as a locator strategy for the following
element:
<h1 id=“msg01” name=“success”>Registration completed</h1>
He must identify the element effectively.
ANS –
By.cssSelector(“h1[id=‘msg01’]”) all three options are correct
By.cssSelector(“h1[id=‘msg01’][name=‘success’]”)
By.cssSelector("h1#msg01[name='success']")

13. Which of the following method causes a thread to pause for a


specified duration?
Sleep()

14. What are the features of TestNG?


Annotation Based
Parallel Testing
Reporting

15. __ Closes all the associated windows of webdriver.


Quit()

16. Which of the following components identify the artifacts in


Maven?
Artifact Id
Group ID
Version

17. What is the correct Syntax to instantiate a Firefox Browser


session?
WebDriver driver = new FirefoxDriver();

18. whithere are three frames in a web page, which method below is
used to comeback to main window before switching to any frame?
switchTo.defaultContent()
19. Which of the following methods will be used to handle an alert
dialog box?
alert.accept()

20. Which of the given options are structure-based locators?


CSS
XPATHsean is

21. Which of the following command should be used to extract more


than one element on web page?
findElements

22. Which of the following is a term used in thee testing of computer


software to describe testing done using a table of conditions directly
as test data inputs?
Data Driven Testing

23. getText() method extracts the text from an element.


True

24. Sean is coding to automate a web application using the webDriver


library. He had set the implicit wait of 30 seconds. However, the
webelement was found within 10s. Will the webdriver wait for
further 20 seconds before executing the next line of code?
YES , webDriver will wait 20 more seconds.
No ,Web driver will resume immediately
25. Sarah wants to automate the selection of only one option from a
drop-down box as shown below.
<html>
<body>
<select multiple>
<option value = “web”> html</option>
<option value = “prog”> python</option>
<option value = “prog”> java</option>
<option value = “prog”> python</option>
<option value = “prog”> java</option>
</select>
</body>
</html>
Sarah has to select only the fourth option i.e., python from the
option list .
selectByIndex()

26. Sean is automating a test scenario in which he has to fetch the URL
of the webpage using webDriver API. Suggest a method for Sean to
get the link address.
getCurrentURL()

27. Which method is used in the Apache POI library to fetch the cell
value from a row? Identify the correct format of invoking the
library functions to get the value from the cell.
sheet.getRow(rowno).getcell(col no).getStringCellValue()

28. Match the following tools with the correct description.


Description
A. GIT 1. A cloud service for remote hosting of git
repositories. In addition to hosting your
code, the site helps manage software
development projects.
B. Git Lab 2. Open-Source platform or continuous
inspection of code quality to perform
automatic review with static analysis of
code to detect bugs.
C. SonarQube 3. Software that handles source code
versioning, letting you make and track
local file changes and share with remote
repository.
A-3, B-1, C-2

29. Sarah is coding an automation script to switch to IFRAME in a


web application .Which of the listed options(s) will help Sarah to
switch to a particular frame on a web page using the webdriver
library?
driver.switchTo().frame(int index)
driver.switchTo().frame(string nameOrld)
driver.switchTo().frame(WebElement frameElement)

30. Sean is coding an automated script to launch the web application


on a browser window. Which of the following listed option will help
Sean to launch the desired application on a web browser in
selenium?
driver.get(“URL”)
driver.navigate().to(“URL”)

31. Which of the following is correct about generating XML suite file
in TestNG for Test Suite Execution?
TestNG XML Suite file can be generated at the time of creating a
TestNG class.
TestNG XML Suite file can be generated using ‘convert to
TestNG’ option in Eclipse after a java class is created.

32. Sam is designing an automation test, where test data is specified in


an external excel file. Which command will be helpful to get across
to the 2nd sheet of excel file? Assume wb is the workbook object.
wb.getSheetAt(1)

33. Sarah is coding to automate script to switch to multiple windows in


a web application. She has to store all the window instances in a
java variable which is retrieved by driver.getWindowHandles().
Suggest Sarah with a compatible return type to store the window
references.
set <string>

34. When verification fails in TestNG, what forces the test to stop
execution and mark as Fail?
AssertionError

35. Samantha wants to automate selection of value from a drop-down


menu. When the element was Inspected. She found:
<html>
<body>
<select name=”jobrole”>
<Option value=”1”>Manager</option >
<option value=”2”>Lead</option>
<option value=”3”>Analyst</option>
</select>
</body>
<html>
Choose “lead” as the test data. Assist her by choosing the correct
options.
selectByIndex(1);
selectByVisibleText(“Lead”)
selectByValue(“2”)

36. In distributed version control system for SCM, which of the


following is not true?
Only online commits are allowed. Servers cannot be replicated in distributed
version control system

37. Which plugin can be used as an IDE(like Eclipse) extension that


helps to detect and fix quality issues of code written in
java/python/html/JavaScript/php?
Sonar Lint

38. Sarah is an Automation Engineer and wants to build a job from


Jenkins server. The Jenkins server is up and running. What is the
default port number that Sarah needs to remember to access the
Jenkins server with URL? whereas for sonarqube 9000
8080

39. Which of the following are supporting attributes for @Test?


priority
enabled

40. Identify the wait time method which is not the Selenium way to
handle synchronization in Test Automation.
Sleep()

41. Which of the following library is used for designing the test scripts
using the predefined classes, methods, and annotations?
TestNG Library

42. Sean is working on a Test Automation project; He is looking for


different strategies for identifying the elements/objects from the
web application using Selenium locators. Suggest Sean with the
available locators in Selenium.
By.id()
ID,name,tag name,class name,
link text,partial link text,
css selector,xpath

By.tagName()
By.partialLinkText()
(Explanation – SELENIUM Selectors - ID, Tag Name, Link Text,
Name, CSS Selector, Partial Link Text, Class Name, XPath)

43. Which of the following is used to pass data from a source to a


particular test method to replace the constant values with variables
in TestNG?
Data Provider hook

44. In the TestNG framework, which of the following contains


Single/Multiple Test Cases? test Suite --> Test Case --> test class --> test method
Test Suite

45. List out the operating systems that are supported by Selenium.
Windows, Linux, Mac, android & iOS

46. Sean is filling a web form with his contact details like email, phone
number, and address while performing registration to an event. He
clicked on submit button without entering the phone number and a
pop-up window appeared saying "Contact Number is required".
Identify the correct way to handle such pop-up windows using
Selenium WebDriver.
driver.switchTo().alert()

47. Identify the child tags that are required to add inside dependency
tag in order to download the desired libraries/jar from the maven
central repository without any errors.
groupId
version
artifactId

48. Sarah is coding an automation script to switch to frame in a web


application. Help her to switch a particular frame on a web page
using the window library. She wants to interact with the pop-up
window and decline the confirmation pop up window show a
message “Do you want to cancel the payment?”. Assist Samantha to
interact with
Driver.SwitchTo().frame(int index)
Driver.SwitchTo().frame(String name or id)
Driver.switchto().frame(webelement frameelement)

49. Testing an automation script to test a web application. He has to


store the Logout link in the using a driver.findElement() method.
Suggest Sean with a compatible return to leg out least object.
WebElement

50. James wants to automate the selection of ID proofs drop-down box


in the web application. He has to verify the drop-down has a
selection of more than one option. Which of the following method is
suggested to James?
isMultiple()

51. Kevin wants to generate extensive report for the test automation
project. He decides to use Extent reports library. Which class in
this library is used to create labels, code blocks and labels in the
report? tables
Markup Helper

52. Sarah is coding an automation script to switch to multiple windows


in a web application . She has to store all the window instance in a
java variable which is returned by driver.getWindowHandles().
Suggest Sarah with a compatible return type to store the window
References.
Set<String>

53. Sarah is coding an automation Script to locate a child element in


an unordered list. The list is given below:
<html>
<body>
<ul class=”cities”>
<li>Bangalore</li>
<li>Chennai</li>
<li>Hyderabad</li>
<li>Mumbai</li>
<li>Pune</li>
</ul>
</body>
</html>
Sarah wants to locate the 3rd child element i.e., Hyderabad.
Suggest the appropriate locator strategy for Sarah. css="ul.cities li:nth-child
CSS = "ul.cities li:nth-of-type("Hyderabad") (3)"

54. Which java Enum is used to handle the keyboard strokes from web
driver library? Choose the most appropriate option.
Keys

55. There is an element on the web page when inspected on the


browser it looks like <div class=”errorMsg”>Error Message</div>
James wants to use selenium locators to identify the element.
Choose the correct set of commands to locate the element
effectively.
By.cssSelector(“div.errorMsg”)

56. George is reviewing the quality of the Java code given to him using
SonarQube and identified that the variables are named without
following java variable naming convention rules. Under which
category this issue can be tracked in the tool? Choose the most
appropriate option.
Minor

57. Sam has created a TestNG project with below specified TestClass.
public class TestClass
{
@Test(priority=1)
public void method1() {….}
@Test
public void method3() {….}
@Test
public void method2() {….}
@Test(priority=2)
public void method4() {….}
}
Predict the test method execution sequence. Choose the most
appropriate option.
method2, method3, method1, method4
58. What method in the Web driver library is used to get the attribute
value of a web element? Choose the appropriate option.
getAttribute(“attributeName”)

59. Sean is coding to automate mouse interactions on a web browser.


Assist Sean to identify the mouse event specific methods from the
below options. Choose the appropriate options.
moveToElement() doubleclick,click and hold,
moveByOffset() release.drag and drop,
drag and drop by,
release() movetoelement.movebyoffset

60. Samantha has designed a TestClass with the following methods:


public class TestClass
{
@BeforeMethod
public void method1() {……}
@AfterMethod
public void method2() {……}
@Test(dataProvider=”loginData”)
public void method3(String u, String p) {…..}
@DataProvider
public Object[][] loginData() {….}
}
Suppose loginData() generates 5 sets of login credentials, how many
times method1, method2 and method 3 would be executed ? Choose
the appropriate option.
Method1 – 5 times, Method2 – 5 times, Method3 – 5 times

61. Identify the correct flow of Jenkins build, when a maven project
job in Jenkins is triggered for build.
pom.xml >testing.xml- >testing classes>reports

62.Sarah has her code in git local repository, but her team lead had
pushed the new changes into the remote repository, which git
command would you recommend Sarah with new changes into her
working copy?
add pull
63. Mary is struggling to find a suitable simple wild cart character
that matches any single character. Please suggest to her which of
the following characters many be relevant to her search
(?) - single character search (*) - one or more

64. Sean configured his project for the test suite execution using
TestNG. He wants to perform parallel execution of the test cases.
Which attribute represents the parallel execution of the test cases?
parallel="tests"

65. Kevin is designing an automation test, where test data is specified


in an external excel file. Which command will be helpful to write
the data into a cell of the excel file? Assume c1 is the cell object.
c1.setCellValue("data")

66. Which of the following Java classes are from the Extent API
library? classes in api are:
ExtentReports extentsparkreporter ,extent reports,
Status extent test, extent color,
markuphelper, status,
67. Which date format is used to customize the system data to year-
month-day format?
new SimpleDateFormat(“yyyy-MM-dd”)

68. Fuller has written an automation script using selenium webdriver


commands. He has used all the necessary and appropriate locators
for interacting with the web elements. When he executed the script
the web driver was not able to locate an element resulting in the test
script failure. Which error/ exception is thrown by webdriver?
NoSuchElementException

69. What are the various status options available in the Extent reports
library?
PASS,FAIL,SKIP,FATAL,ERROR,WARNING,INFO

70. Kevin wants to fetch all the data from the country drop down
menu and verify the data against data from the database. He is
looking into the library for a method to fetch all the data from the
country drop down box. Which method will help Kevin?
getOptions()
71. Samantha has to execute automation scripts across multiple
platforms like windows, mac, Linux which tool in the selenium suite
will be used by Samantha? Choose the most appropriate option.
selenium RC selenium grid

72. The web element looks like


<a href=”icart.jsp? params”>cart[19]</a>.
Which locator is most recommended for the scan to identify the
cart web element for all test iterations ?
By.partialLinkText()

73. Kevin is planning to write automation script for below scenario.


Given the user is on the payment page. He views a textbox with
attribute values . “Enter Mobile Number” written in the box. The
user must enter the mobile number in the box to proceed. Please
choose the correct command to help Kevin in automating the
scenario. Assume the textbox element is already identified and
stored in mobile txt box variable.
mobileTxtBox.clear(); mobileTxtBox.sendKeys(“xxxxxxxxxx”);

74. Which MS office component(s) can be handled by Apache POI


Library? ppt.outllok,excel,word
XLSX all the above
if xslx present it is the option
75. Sarah is coding to automate a scenario for the selection of the
“from Cities” drop down box IN the flight booking application web
page, which WebDriver library class helps Sarah to automate the
drop-down box with different functions?
Select Class

76. Sean is performing verification using assert class functions from


TestNG. Suggest him the correct method to verify the
reference/address of the two objects to be identical?
assertSame(object1,object2)

77. Sean wants to switch to multiple frames on a web page when an


operation is completed on a frame and test flow needs to move to
another frame. Calling the driver.switchTo().frame() immediately
will not move the context to next frame, which is at the same level
in DOM. The test will first need to switch to the main document
and then activate the frame. Which method is used to switch back
to the main document from the frame?
switchTo.defaultContent()

78. Samantha is automating a test scenario. This scenario involves a


pop-up of confirmation window. She wants to interact with the pop-
up window and decline the confirmation. Pop-up window shows a
message “Do you want to cancel the payment?”
Driver.switchTo().alert().dismiss()

79. Sarah is coding an automation script, where she has to validate the
price of the holiday package based on the drag & drop of island city
from the menu. The price is fetched from the server and displays
without reloading the web page. Which WebDriver library class
has the predefined conditions for handling dynamic waits in
selenium WebDriver Library?
WebDriverWait Expected conditions

80. While using Soft Assertion in the Test Class, James must specify a
method, that will collate and display the assertion results.
assertAll()

81. Which java interface is used to capture screenshot of web page


using Web Driver API?
TakesScreenshot

82. Consider the below HTML code snippet.


Email ; <label id= “Email” class= “style1” name= “input”>
Which is the best locator to identify the email web element?
By.xpath(“//label[@id= ‘email’]”) By.id("Email")

83. Which among the following is a term used in the testing of


computer software to describe testing done using a table of
conditions directly as test data inputs?
Ans: Data driven testing

84.What is/are the tools available with selenium suite?


Ans: All Tools: Webdriver , grid , IDE

85.Webdriver implements the following class/classes


Ans : All
86.Which of the following is used for designing the test scripts using
the predefined classes, methods and annotations?
Ans : Testng library

87.Which of the following contains single/multiple test cases?


Ans: test suite

88. Which method in the web driver library is used to get the attribute value of a web
element?
Ans: getAttribute(“AttributeName”)

90) Sarah as an automation engineer triggers a new build from Jenkins as a maven project
having source codes in git repository which of the following tools/ Software are required to be
configured by Sarah in Jenkins to make the build success.

Ans: jre , jdk ,meavon git,maven,jdk

You might also like