Selenium

¡Supera tus tareas y exámenes ahora con Quizwiz!

How did you use overloaded Methods in Selenium?

1) When asserting if two values are equal, I use -> Assert.assertEquals(actual, Expected)from TestNG 2) You can put in the parameters String, Objects, int, boolean values

What is Xpath?

1) Xpath is used to find the location of any element on a webpage using html structure. 2) We could navigate through elements and attributes in an XML document to locate web Elements such as textbox. 3) button. checkbox, Image ext... in web Page

How to get all the following siblings of Apple?

1) Xpath: "//ul/li[contains(text(),'Apple Mobiles')]/followingsibling::li" 2) This will give all the preceding siblings ( Nokia Mobiles, HTC Mobiles, Sony Mobiles, Micromax mobiles)

How to get all the preceding siblings of Apple?

1) Xpath: "//ul/li[contains(text(),'Apple Mobiles')]/precedingsibling::li" 2) This will give "Samsung Mobiles"

What if there's no select tag?

1) You have to select the label for the dropdown separately as a webelement. 2) Then manually use click method

Difference between close() and quit() command?

1) driver.close()àused to close the current browser 2) driver.quit()àused to close all the browser instances

What is the difference between driver.get() and driver.navigateto() ?

1) driver.get() -> To open an URL and it will wait till the whole page gets loaded 2) driver.navigateto() -> To navigate to an URL and it will not wait till the whole page get loaded

Page Factory class?

1) Page Factory class comes with Selenium. 2) And it is used whenever we create page object classes. 3) Its purpose is to initialize webElements that were defined in the class.

What we don't do with selenium?

1) Performance, load, stress testing, manual ad hoc testing, (These tests are done by experts trained in these tools) 2) Pure database testing (if we only test the DB itself), 3) Unit tests..., look and feel based testing (color, shapes, etc.), 4) static testing

How check the multiple selected values in dropdown?

1) Select carsList = new Select(el) 2) carList.getSelectedOptions(): //returns the the selected options a list ( List<webelement>) 3) for each : carList.getSelectedOptions()

How do you like Selenium version 3?Is Selenium 3 drastically different from Selenium 2?

1) Selenium 3 has bug fixes from selenium 2 also it is more mobile automation focused. 2) We aim for Selenium 3 to be "a tool for user-focused automation of mobile and web apps". 3) Here is the summary of the change. a) For WebDriver users, it's more of bug fixes and drop-in replacement for 2. b) Selenium Grid bug fixes are done as well. c) Selenium project will not actively support only the WebDriver API. d) By a quirk of timing, Mozilla have made changes to Firefox that mean that from Firefox 48 you must use their geckodriver to use that browser, regardless of whether you're using Selenium 2 or e) As we know Selenium 3.0 is the latest version of Selenium Jar

findElement vs findElements?

1) FindElement > this method returns first WebElement ! a) gives Exception if the element not found 2) FindElements > returns List <WebElement>; b) does not give Exception if the element not found as a result list has null values

What exceptions do you know in Selenium?

1) I often have NoSuchElementException 2) StaleElementException a) The element has been deleted entirely. b) The element is no longer attached to the DOM. c)How we handle StaleElementException; *Element is not attached to DOM -> 'try catch block' within 'for loop' OR *1st Refresh the page and try again for the same element. *2nd Wait for the element till it gets available 3) TimeOutException

What is the key class in Selenium?

1) Gives us option for pressing keys from keyboard 2) Key.ENTER 3) MUST BE PASSED TO SendKeys() method 4) Ex; .sendkeys("charger" + keys.ENTER)

What version of Selenium do you use right now?

1) JDK (JAVA) - 1.8 -> I like it because of -> Lambda exp. and, Try catch error handling you may add multiple catches. 2) IntelliJ - 2018.03.04 3) Selenium - 3.141.59 4) TestNG - 6.14.3 5) Cucumber - 4.2.6 6) Maven - 3.6.0 7) GIT - 2.17.2

What is Thread.sleep()?

1) Slows down selenium to catch up 2) Throws exception so must handle it or throw it

How you handle js alerts?

If the alert on the browser comes from JavaScript, we use the Alert class.

How to handle cookies?

In Selenium Webdriver, we can query and interact with cookies with below built-in method:

How can we move to parent element using xpath?

Using (..) expression in xpath, we can move to parent element

How do you find a text in a webpage?

1) //tagname[contains(text(),'text')] contains certain test 2) //tagname[.='text'] contains exact text sometimes doesn't work Selenium

What is HybridDriven Framework?

1) A combination of the DDF and KDF is commonly said to be HDF. 2) Both the test data and test action are kept in external files.

How to use actions class?

1) Actions class lets us do advanced mouse and keyboard operations: 2) Control the mouse 3) Class that provides methods for advanced user interactions a) Hovering b) Scroll c) Double click d) Drag and drop e) Right click f) mix/match operators 4) Actions action=new Actions(driver) 5) Action methods a)click() b) perform() c) hold() d) keydown()build() e)moveToElement(element) f)dragAndDrop(source,target).perform() g)sendKeys() different from the one we usually use *Let's you do the sendkeys operationon different elements *Regular sendkeys that comes from webelement will throw an exception on something that is not input text. *The long way is; actions.moveToElement(source).clickAndHold().moveToElement(target).release().perform(); 6) Actions won't work unless perform() is used 7) If you are chaining methods, you must use build() before perform()

How you resolve certification issue?

1) CHROME, IE -> DesiredCapabilities capability = DesiredCapabilities.chrome(); 2) on Jenkins we need to insert -> relaxedHTTPSValidation

Why we get NoSuchElementException?

1) Check if locator is correct 2) Check if timing is correct 3) Check if element is hidden inside an iframe

Why do we need to handle cookies?

1) Each cookie is associated with a name, value, domain, path, expiry, and the status of whether it is secure or not. In order to validate a client, a server parses all of these values in a cookie. 2) When Testing a web application using selenium web driver, we may need to create, update or delete a cookie. 3) For example, when automating Online Shopping Application, we many need to automate test scenarios like place order, View Cart, Payment Information, order confirmation, etc. 4) If cookies are not stored, we will need to perform login action every time before we execute above listed test scenarios. This will increase your coding effort and execution time. 5) The solution is to store cookies in a File. Later, retrieve the values of cookie from this file and add to it your current browser session. As a result, you can skip the login steps in every Test Case because your driver session has this information in it. 6) The application server now treats your browser session as authenticated and directly takes you to your requested URL.

How do you handle dynamic elements?

1) Find the static part of the id and write a locator(xpath or css)àAnd then use Startswith, contains, EndsWith 2) contains( ) -> //*[contains(@name=`btn`)] 3) startwith( ) -> //label[startwith(@id, `message`)] 4) text( ) -> //td[text() = `usedId`] 5) or & and -> //input[@type = `submit` AND @name = `login`]

What is the syntax for switching frame?

1) Frame is a html document inside another html document. 2) Web driver handles one page/html document at a time. To control another frame, we always need to switch 3)Driver.switchTo.frame(webelement) -> find the iframe and pass as a param 4) Driver.switchTo.frame(string) -> find the id or name of the iframe and pass as a param 5) Driver.switchTo.frame(int) -> find the index and pass as a param

ASSERT(hard assert) VS VERIFY(soft assert)

1) Hard assert throws an AssertException immediately when an assert statement fails, and test suite continues with next @Test. If Assert steps fails, execution of test stops at that point! and will go to next test if present! a) (Example: just simple Assert.assertTrue(boolean);) 2) Soft assert collects errors during @Test Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement. If Verify steps fails, it will report a fail but will continue execution! a) Example: SoftAssert soft=new SoftAssert(); //for soft create object b) soft.assertTrue(boolean); c) soft.assertAll(); //put at the end it will report what is failing!

How to handle Headless browser

1) Headless browser: browser that does not open, it runs as a background service / program. 2) Example is htmlunitdriver from selenium a) WebDriver = new htmlunitdriver() b) Not very stable 3) Phantonjsbrowser a) More stable b) browser = new phantomjsbrowser()

Talking about HTML reporting during the interview?

1) I use multiple methods of reporting in my framework, driver script writes pass/fail to the test cases excel sheet, 2) Reporter utility object writes to UFT report, also I have developed a custom HTML reporting engine. 3) It sends HTML code to the Notepad and creates a nice HTML report document that nontechnical people can easily understand and use.

How to work with drop down without the select tag?

1) If the dropdown list has no select tag, we cannot use the select class 2) Treat the dropdown list and its options as separate elements, locate every element separately 3) To select an option: a) Find and click on the list b) Find and click on the option

What is in the Selenium tool set?

1) Selenium IDE -> implemented as a Chrome and Firefox extension, and allows you to record, edit, and debug tests. 2) Selenium RC -> to write automated web application UI tests in any programming language 3) Selenium WebDriver -> execute your tests against different browsers 4) Selenium GRID -> run your tests on different machines against different browsers in parallel.

Difference between xpath and css selector?

1) with xpath, we can search elements backward or forward... while css works only in forward direction 2) Xpath can work with text, css cannot work 3) Xpath has more combination and can search by index css cannot search by index, but css is working faster than xpath.

In some cases, maximize() will not work > so what will be the way around?

Actions or change version.

Have you done any cross-browser testing?cross browser testing

Always mention that you have a control file for keywords like browser type, main url, username, password, environment.

How to handle multiple frames?

If there are 4 frames, you have to go through each from consecutively to reach certain frame. Can't jump to the 3rd frame from 1st frame.

What is fluentWait?

Let's say you have an element which sometime appears in just 1 second and some time it takes minutes to appear. In that case it is better to use fluent wait, as this will try to find element again and again until it find it or until the final timer runs out. Example is AJAX or JQuery *Subtype of explicit wait but you can override the conditions

How would you verify the position of the Web Element on the page?

1) element.getLocation(); 2) WebElement class has a get Location method with returns the top left corner of the element

How to check if element is present?

OR if(driver.findElement(By.xpath("value"))!= null){ System.out.println("Element is Present"); }else{ System.out.println("Element is Absent"); }

For Scroll down

OR, we can do as follows: jse.executeScript("scroll(0, 250);");

Use stored cookies to login information

OUTPUT: You are taken directly to the login success screen without entering the input user id and password *NOTE: Use hard refresh in case you see the login page after executing the above script.

Sometimes sendKeys/path does not work

Building a dynamic path for a file inside our project Path to the project location:

Explain me your test execution flow with cucumber.

Runner > Feature file > Scenario > Steps > Step def > Selenium code using POM

What is the syntax for double click action ?

To perform any actions against web element using actions class, we need to locate the element first:

What if there is a dynamic popup that comes up randomly

Use try/catch with alert

Sometimes sendKeys does not work

1) Robot or AutoIT 2) library==jar file==dependency

What is Keyword Driven Framework?

1) Keyword driven testing is a scripting technique that uses data files to contain the keywords related to the application being tested. 2) Keywords are written in some external files like excel file and Java code will call this file and execute test cases.

Why I cannot find element?

1) Locator changed 2) There is an iframe 3) Waiting time:: page is loading slowly or Element is dynamic:: locator 4) Page is not fully loaded/opened 5) Page changes and that element does not exist anymore

How to handle frames in Selenium?

1) Frames used to embed a html page into another 2) Steps a) Locate the iframe b) Switch to another iframe with driver.switchTo().frame(); .frame() -> takes string, Integer, webElement, name or id directly as parameter 3) Now you are in the 2nd frame, if you want to find an element outside of the 2nd frame (that you're currently on) throws NosuchElementException 4) If you need to switch back to previous frame a) driver.switchTo().parentFrame() -> Goes one level up b) driver.switchTo().defaultcontent() -> Goes to the very top 5) Can switch using count a) driver.switchTo(0) -> Counts anything that is not the default frame These methods might give you different results based on what browser you are using

What the verification point available in Selenium?

1) In selenium IDE, We use Selenium Verify and Assert Commands as Verification points 2) In Selenium WebDriver, There is no built-in features for verification points, it totally depends on our coding style. Some of the Verification points are a) to check for page title b) to check for certain text c) to check for certain element(text box, button, drop down, etc.)

What is framework?

1) In test automation, framework is the blueprint of test automation. 2) It includes your folder structures, where to save you function library, test results, test data, resources. 3) It is essential because when you are working on a automation project everyone will have a guideline to follow and our script will be easier to maintain.

What is Selenium Framework?

1) It is a code structure that helps to make code maintenance easy, code readability and code reuse. 2) There are mainly 3 type of frameworks created by Selenium WebDriver to automate test cases: a) Data Driven Framework b) Keyword Driven Framework c) Hybrid Driven Framework

What is Data Driven Framework?

1) It is one of the most popular automation frameworks in the market 2) All of our test data is generated from some external files; a) excel b) or scenario outline in feature file c) or TestNG Data Provider 3) Selenium WebDriver is a great tool to automate web-based applications. But it does not support read and write operations on excel files. Therefore, we use third party APIs like Apache POI

What is Selenium composed of?

1) Selenium IDE(Integrated Development Environment); a Firefox plugin that works for recording and playing back. 2) Selenium RC(Remote Control) (1.0) ; is a test tool and is used to work on JS to automate the web application. (2004) 3) WebDriver (2.0); is a web automation framework and allows you to execute your tests in different browsers. (2011) 4) Selenium Grid; allows tests to run in parallel across multiple machines.

What are various ways of locating an element in Selenium?

1) Selenium Locators -> Id & name 2) In selenium locator is a means of finding an element in the html: 3) Id, name, className, xpath, css, linkText, partialLinkText, tagName

How you handle windows/OS pop ups?

1) Selenium doesn't support windows-based apps, it is an automation testing tool that supports only web application testing. 2) We could handle windows-based popups in Selenium using some third-party tools such as AutoIT, Robot class 3) driver.getWindowHandle(); This will handle the current window that uniquely identifies it within this driver instance. 4) driver.getWindowHandles(); To handle all opened windows

What are the advantages of Selenium?

1) Selenium is open source and free to use without any licensing cost 2) It supports multiple languages like Java, Ruby, Python, C#... 3) It supports multi-browser testing 4) It has a good amount of resources and helping community 5) It supports many operating systems like Windows, Mac, Linux ... 6) Interact with the web application

How to handle multiple windows/tabs?

1) Selenium stays on one window 2) If you open a window and then 5 tabs popped open, selenium is focused on the first window 3) If you are on a new window and you tell selenium to print an element on the default window, it will still work even that user's focus is on the new window 4) Must switch to new window a)Use windowHandle() b)Driver.getWindowHandle() *Everytime Selenium opens a browser, it's going to give an index ID for the page called Handles *Returns the handle/id of current page (as a string) c) driver.switchTo().window(string handle) d) driver.getWindowHandles() for multiple windows *Returns a Set of window handles e) Switch using titles

What are the disadvantages of Selenium?

1) Selenium supports only web-based applications, does not support windows-based application 2) No built-in reporting tool, it needs third party tools for report generation activity 3) Cannot work with graphics, captchas, barcodes, shapes 4) It does not support file upload facility. 5) Hard to master, requires developer level knowledge 6) Hard to write good locators 7) Hard to synchronize

Absolute (/) and Relative (//) Xpath?

1) Syntax -> //tagname[@attribute=`value`] 2) Absolute xpath starts with single slash ( / ), starting from root element and all the way to the element. 3) Relative xpath starts with double slash ( // ), starting selection matching anywhere in the document.

Do you use JavaScriptExecutor?

1) This helps me write my own JavaScript. JS has way more control than selenium. 2) we can send JS commands to the browser with using this class: JavaScriptExecutor jsExecutor=(JavaScriptExecutor)driver; a) executeScript(); performs the command b) Inside the parameter is where you put JS code 3) jsExecutor.executeScript("alert('WARNING: This is a useless message');" -> This code will bring up a JS popup 4) You can also put 2 parameters is .executeScript("js code",element); a) Used for scrolling (selenium is not good with scrolling, you can say a challenge is when I was working on terms and condition page, where you have to read the page before clicking on continue. b) When I tried using selenium and actions class it didn't work, so i used javaexecutor ) and clicking an element;

What is the syntax for switching windows?

1) To handle separate tabs/windows we have to switch to that tab 2) Web driver handles one page/html document at a time. 3) To control another tab, we always need to switch 4) To be able switch we need to get the window handle first using

How to press ENTER key on text box in Selenium WebDriver?

1) To press Enter key using Selenium WebDriver, 2) We need to use Selenium Enum keys with its constant Enter 3)Driver.findElement(By.xpath("xpath")).sendKeys(Keys.ENTER);

How To resize browser Window Using Selenium WebDriver?

1) To resize the browser window to particular dimensions, we use 'Dimension' class to resize the browser window. 2) //Create object of Dimensions class Dimension d = new Dimension(480,620); 3) //Resize the current window to the give n dimension driver.manage().window().setSize(d);

What tools are you using to test UX and Restful webServices?

1) UX -> User Experience. First ensure UX is acceptable manually. 2) After that since it is UI testing, I use Selenium WebDriver to automate it. 3) RESTFul API Automation > RestAssured Library, PostMan for manual tests

How to test dynamic table?

1) Use custom xpaths and css locators a) Xpath: contains, starts with, ends with, contains text. b) By finding the element in relation to another stable element using parent, child, sibling relationships 2) I have utility methods that work with table. I have method that takes a table web element and returns all the column names. I have a method that takes a table, number and returns all the data in that row.

Verify text exists?

1) VerifyTextPresent -> returns TRUE if the specified text string was FOUND somewhere in the page; FALSE if otherwise. 2) VerifyTextNotPresent -> returns TRUE if the specified text string was NOT FOUND anywhere in the page; FALSE if it was found.

What are the limitations of Selenium?

1) We cannot test desktop application 2) We cannot test web services 3) Ewe have to use external libraries and tools for performing tasks like testing framework (TestNG, JUnit), reading from external files (Apache POI for excel) 4) Automating Captcha is not possible using Selenium 5) It does not support file upload facility.

What is the syntax for uploading a file?

1) We need to locate the upload button in html. 2) The element will have tag input. 3) Then we do sendKeys by passing the path to file which we want to upload

What types of testing you automate with Selenium?

1) functional tests (positive/negative, UI) 2) smoke tests 3) regression tests 4) integration tests 5) end to end testing 6) data driven

Difference between isDisplayed(), isEnabled(). AndisSelected() method inselenium WebDriver?

1) isDispalyed() -> verify the presence of a web element within the web page. If found -> true, If not found -> false 2) isDisplayed() -> check for the presence of all kinds of web elements available 3) isEnabled() -> verify if the web element is enabled or disabled within the web page. 4) isEnabled() -> is primarily used with buttons 5) isSelected() -> verifies if the web element is selected or not 6) isSelected() -> used with radio buttons, dropdowns and checkboxes.

How you handle browser pop ups?

1) void dismiss() -> clicks on the "Cancel" button as soon as the pop-up window appears. 2) void accept() -> clicks on the "Ok" button as soon as the pop-up window appears. 3) String getText() -> returns the text displayed on the alert box. 4) void sendKeys(String stringToSend) -> enters the specified string pattern into the alert box.

File download and upload

Download 1) Selenium itself cannot verify file downloads, can click on download link but can't go outside the browser and open the downloaded file 2) Other tools need to be used for that Robot and AutoIT Upload 1) Selenium handles the upload, but does it differently compared to actual user 2) Steps a) Find the element that triggers the upload window b) Find the path of the file you want to upload *Store into a String: **Ex: String -> file="C:\\Users\\Andy\\Desktop\\folder1\\file.key"; **Then driver.findElement(upload button).sendkeys(file);

Implicit Wait vs Explicit Wait?

Implicit wait is a wait which waits for a specified time while locating an element before throwing "NoSuchElementException". As by default selenium tries to find elements immediately without any wait. So, it is good to use implicit wait. This wait applied to all elements of the current driver instance. Explicit wait is a wait which is applied to a particular webelement until the ExpectedCondition specified is met. Implicit wait is simply; if condition is met before the timeout, it will continue to next step, if condition is not met within timeout throw "No Such Element" exception. Explicit wait sometimes we need to wait for a certain event/condition such as element is visible, clickable, enabled....

How to highlight an element?

Selenium WebDriver doesn't have highlight action. *But we can use JavaScript to do it

What is Selenium?

Selenium is a suite of tools for automated web testing.

How can we move to nth child element using xpath?

There are two ways: 1) using square brackets with index position *For ex: div[2] will find the second div element 2) using position ( ) method *For ex: div[position()=2] will find the second div element

How to test dynamic web page?

There is no one size fits all solution to this problem. We have to understand the application very well 1) Use explicit waits where necessary. o 2) Use custom xpaths and css locators a) Xpath: contains, starts with, ends with, contains text. b) By finding the element in relation to another stable element using parent, child, sibling relationships


Conjuntos de estudio relacionados

A&P 2 Test 2: Chapter 19 Blood Vessels and Chapter 20 Lymphatic System and Lymphoid Organs and Tissues

View Set

Ethical and Cultural Considerations in Counseling Research for Master's Students

View Set

Jean-Paul Sartre Existentialism Philosophy

View Set

Sociocultural Psychology - IB Psychology Unit 4

View Set

Chapter 21: The Lymphatic and Immune Systems

View Set

APES Renewable and Nonrenewable Resources

View Set