Selenium TestNG

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

what is the difference between checkBox and radioButton?

checkBox in selenium you may be able to select multiple ones at once and for radioButton you can only select one at a time.

what is Keys in selenium?

class with useful methods. it will basically allow you to use keyboard functions

Skill set of QA automation engineer

coding skills framework design skill knowledge of manual testing & QA knowledge of development methodologies logical and analytical skils

how can I search for specific elements when I inspect page?

command f for Mac users and control f will prompt search bar in html code page.

what is a configuration file in testNG and what is it used for?

configuration.properties you will use to store important data also changeable data commonly used for paths or environment details etc.

What is a drawback of using absolute xpath or con?

developer could change something in code making our xpath locator no longer working. its also very time consuming to follow from parent tag to child tag all the way down to element you're looking for

how do we maximize window in selenium?

driver.manage().window().maximize(); //remember we can call our object anything It doesn't have to be called driver in this example for logics sake we have called it driver.

what is a web element?

everything you see on a web page is a web element

what do I do if webElement im looking for is not unique in td?

find something that is unique in td and use parent child relationship to make your WebElement your looking for unique EX: //td[.='770000770000']//..//td[8]

how do I get text from a webElement on a webpage?

find the element using any of 8 locators then Store it in a WebElement and use .getText . EX:ActualHeader.getText() you may also store it as a string like so: String actualHeader=driver. findElement (By.className (' _8eso")) .getText ();

What is TestNG?

- TestNG is an open source testing framework. - Can configure and run test cases, easy to understand, to generate HTML report. TestNG is a unit testing tool that allows us create flow using Annotations. > First we create methods, then we use TestNG annotations to create running fLow. We decide which method is test by typing @Test

what is maven?

-maven is a built automation tool -it helps us create project it comes with ready pom.xml file

cons for selenium

-only used for web based apps -no image based testing -no tech support -no report supporting

pros of using selenium

-open source(free) -multi browser (compatible with Firefox etc.) -multi platform (brands of computers apple ,windows) -multi language -integration with different tools and frameworks -support parallel testing

how do you get url in selenium?

.get method and you can even do .getCurrentUrl method to print your url. this is one method to verify url in automation. by default before you navigate or move to any webPage using driver.get(webpage) webpage and url will be empty.

What can I add at the end of my xPath so it goes to parent tag? how do I go from parent to child?

/.. dash dot dot, this is useful when you've gotten xpath using child and it won't click or whatever function you're trying to accomplish. you can try using parent. this is one of the advantages of using x path rather than css /.. will take you to parent tag of whatever tag your element is in ->a//[@a to go from parent to child I/div[@id='hello'] --> this is locating the div //div[@id-'hello'1/a --> this is now locating the anchor tag using its parent forward slash and child tag

what is partialLinkText?

1 out of 8 locators used to locate webElements 3.Partiallinktext (contain the text) -this Locater allows us to locate links by their text -but it doesnt need exact match for text syntax: driver. findElement (By .partialLinktext ("amazon")) ; partial linkText is usually the text that follows referring to your linkText address example linkText= Gma would work. not as unique you should check always if it is

how many forms of dropDowns are their in selenium and how do you handle them?

1: Select dropDowns: are created by using <select> tag in HTML ‹select><option value="1"› option1 </option> ‹option value="2"› option2 </option> <option value="3"› option3 </option>< select> -use select class to locate them. if you see <select> in html code when you inspect then you can do the above using select class to locate if not then you cannot and deal with them the 2nd way/ 2- HTML dropdowns: these are the dropdowns that are created NOT USING <select>- These dropdowns are handled just like any other webElement you will see on the page. you'll use a locator to locate webElement and select them in your code.

What is iFrame in selenium and how do you switch between them?

> Iframes are basically <html> inside of another <html> > Selenium can only focus one thing at a time. So we need to SWITCH driver's focus to the inner frame to be able to perform any action with Selenium. -> There are 3 ways to switch to iframes 1- Locating as WabElement then using that webElement to switch. WebElement iframe = driver. findElement (LOCATOR); driver.switchTo. frame (iframe) ; 2- Switching by index. We pass the index number of the frame. -> if you have more than one frame on the page, indexes are used. <iframe> --> index 0 <iframe> --> index 1 <iframe> index 2 driver.switchTo. frame (0); 3- Switching by id or name attribute value driver.switchTo. frame ("IdValue"); driver.switchTo. frame ("nameValue");

What is Assert class in TestNG?

ASSERTIONS: > Assertions are coming from TestNG > Assertions allows us to do our verification for our test cases > You can pass an additional argument into assertion methods just provide additional information about what failed to be able to print on the console

what is implicit wait in selenium?

An implicit wait is telling webDriver to pull the html code for a certain amount of time when you're trying to find element --if page is loaded immediately it wont wait up to given second. basically waits until given time for element or before next action presents itself but if it loads or is present before your given time it wont wait the entirety of time you've passed it'll move to the next action as soon as its available or present. --type of selenium wait

What are annotations in TestNG?

Annotations are a way of controlling the flow of the test.

what exception do you get when your computer is not fast enough to catch your element?

Element not interactable exception

if we have multiple tests in what order will they run?

By default tests are running in alphabetical order. (Case sensitive capitals come first) priority => You can change the running order using priority. - We can change the priority which will change the running order of the tests.

what do I do if I want to change TestNG default order and name order?

I can use keyword priority to set a numerical order in which I choose each test case to run EX: @Test(priority=1)

what should your first option for locator be?

ID because the majority of the time it'll be unique. you should also check if it is static by refreshing the page meaning it won't change.

What is ID in html code when using selenium?

ID is one of 8 locators used to locate WebElements in html code. -id will locate by matching id attribute's value. -id is unique for the specific webelement -if if you have id and its not dynamic you should always use id. dynamic means (when you refresh if you see id value is changing that means id is dynamic) and you probably not use it. syntax : driver. findElement(By.id("id attribute value"));

What happens when your assertion fails in a test case?

If you assertion fails, it will stop running for the current test in the same line where it failed. it will not move to next line. It will move to the next test. And start running that one.

What is a pom.xml?

Project Object Model tells Maven which dependencies we need. comes with maven when you select it. we use it in our selenium testNG framework . we get our dependencies from maven repository and they go in pom.xml file and they go under dependencies <>. I am using bonigarcia latest version of dependencies

what kind of selenium are you using?

Selenium TestNG with maven built in tool

what does @BeforeMethod do in TestNG?

The annotated method will be run before each test method. Usually used for setting up conditions, getting browsers, and pages. whatever you have in here will run for all Test cases

What is automation?

The use of technology to ease human labor or to extend the mental or physical capabilities of humans. describes a wide range of technologies that reduce human intervention process.

how many types of alerts are there in selenium and how do we handle them?

There are two types of alerts. 1- HTML Alerts: > How do we handle: We just locate just as another web element on the page. > Then we click. 2- JavaScript Alerts: HOW DO WE HANDLE? > Using Alerts. > JS alerts are not part of the HTML structure. Therefore we need to switch the driver focus to the alert itself. Create an instance of Alert, then switch to alert.Alert alert = driver. switchTo() .alert () ; to accept, dismiss alert.accept(); alert.dismiss;

what is assertEquals?

This method expected two arguments to be passed: actual, expected. It compares these two values and if they are exact match, it will pass.

What is assertFalse?

This method expects you to pass a boolean value. If the boolean value is FALSE, IT WILL PASS. If not, it will fail.

What is assertTrue?

This method expects you to pass a boolean value. Or you have to pass a method that returns a boolean value. If the boolean value is TRUE, it will pass. If not it will fail.

what is manual testing?

Type of Software Testing where Testers manually execute test cases without using any automation tools.

What are window handles in selenium?

WINDOWS/TABS-> Selenium can only focus on one thing at a time.-> Selenium creates something called window handle for each tab or window.-> For selenium, there is no difference between a tab, and a window. It works same for both of the tab and window.What is a window handle : Randomly generated string that is unique to each window.example : CDwindow-7E6F9AEE107F13A24BF541182AEE2971How to get current window handle?-> driver.getWindowHandle() --> will store current window that you are working for one window.How to get all of the window handles of the currenly opened tabs/windows?-> driver.getWindowHandles() --> will return a SET of string that contains all the windows or tabs that you have.

How do we handle web tables using Selenium webdriver?

We create specific path locators to locate what we want to get from the table itself. By creating custom locators to get whatever I need to get from the table. > If I need to get the whole row, I create a locator that returns the whole row. > If I need to get 1 single cell, I need to create a locator that returns 1 single cell.

identify what is tag, attribute, and attribute value: <a href="https//www.amazon.com"> Text amazon </a>

a= tagName href=Attribute Attribute value= www.amazon.com

what is the difference between alertAccept and alertDismiss?

accept will click on "ok" and dismiss will click on cancel.

How do I ignore a Test case in TestNG?

add @Ignore annotation on top of a test when using @Ignore annotation it will not show up in result at all if you have 4 test and ignored 1 result will show it ran 3 cases along with pass or fail result.

in order to use TestNG in my framework what do I have to do?

add TestNG dependency from maven repository to my pom.xml file

What is .selectByIndex

allows us to select option in html code by using index. index will follow same rules as in java begins with 0 and so on.

What is .SelectByVisibleText?

allows us to select options on dropdown using exact text mach on html page

What does @Test annotation allow you to do?

allows you to run without a main method

What order does TestNG follow?

annotation order EX: before method after method etc.. but also how they are named if I name them 1, 2, and 3 they will follow that numeric order or if I name them a, b, and c they will follow alphabetical order. as opposed to Java where it reads from top to bottom. it is suggested to use same name and only change numeric number Test1 Test2 and so on.. or TestA TestB etc..

what is returned when using get attribute?

attribute value which is everything in orange in html code

why do we store certain things in a specified container EX: findElements Stored in List<WebElements>?

because they are defined in their methods as return type List, Set, String etc..

how can you verify an element is present using its text or by passing the webElement?

by using .isDisplayed method. it will check if element is displayed. you can also do .getText and verify using String expected and string actual string

how can I test multiple data for example for password and username without hard coding?

by using data provider annotation EX: @DataProvider and passing 2 dimensional object array which will take two objects at a time ex: {"Wualter," "Jennifer"} and since size is not fixed this can go on to test as many usernames and passwords as I want.

how do I find more than one element in a tag and store them?

by using findElementS plural with an s. then you use List<WebElement> Elements = driver.findElements()By.xpath("//body//a)); our list is storing webElement objects and our xpath is using body and a tag and it'll find all links in a tag and store them in our list. IF YOUR ELEMENTS ARE NOT FOUND, SELENIUM RETURNS EMPTY LIST AND NOT "NO SUCH ELEMENT EXCEPTION" return type is <List>

how do I locate an entire row or column in Table data (TD)?

first locate the webElement for whole table data . then search for tr EX: //table[@id='ctl00_MainContent_orderGrid']//tr and you can get specific data in your row using EX: //table[@id='ctl00_MainContent_orderGrid']//tr[4]. Remember that your table header will be included in number. if you want to get everything in your column which is up and down --> //table[@id='ctl00_MainContent_orderGrid']//tr//td[1] <--as this number changes so will the column you will essentially need both if you are looking for a specific row and column EX: row 2 column 3

how do you handle checkBox?

first locate webElement for checkBox then use click method to click then use if else statement with .isSelected method to verify its been selected.

What is the logic to storing windows handles and going through them one by one?

first you'll need to create a Set<String> name it allWindows or something relevant in this case window handles that will store all of your windows or tabs then create a List<String> empty container that will take your window handles and store them as they loop. once all in yor list you can switch between them EX: driver.swtichTo().windowWindowList.get(1); you'll use for each loop to to temporarily store allWindowHandles individually and add them to WindowList using windowList.add(window)

What is your util package for?

for repeating functions we can write out methods our variables we''ll repeatedly use so we don't have to write them out each time. makes our code reusable and easy to maintain. also if ever a need to change something we don't have to go to each class we can just change from our utilities class.

what is the difference between getUrl and .getTitle methods?

get url will get whatever https address is in your search bar and get title will be whatever your open tab reads

What can I use to verify something besides if else condition since this will not actually cause my test to fail?

if you want a fail result for a condition placed in TestNG you must use Assert class and .assertEquals method. this come from TestNG dependency. If you were to use conventional if/else condition your Test case would still pass

between thread.sleep implicit wait and explicit wait which ones are mostly used?

implicit and explicit wait are best used in the industry with thread.sleep being the least used.

Where can we store our webElements found on html code?

in WebElement object Ex: Web element searchBox= findElement(By.name(element value));

What is java faker?

is a class (library) with useful methods that help us create user info. you have to add it to your pom.xml file after you've downloaded dependency from maven repository

what is selenium?

is a free (open source) automated testing framework -selenium is used to validate web applications across different browser and platforms. -you can use multiple programming languages like java, c#, python etc. to create a selenium Test script. -simply it is a library that has classes and methods.

What is selectByValue?

it allows you to select options on dropdown html using value EX: value= "1"

What is .getFirstSelectedOption?

it is a method of Select class that will get you the first option in dropDown usually being default option.

how many locators are there in selenium and what are they called?

there are 8 locators in selenium and they are name className ID LinkText PartialLinkText tagName xPath css

what is name locator in selenium?

it is one of 8 locators in selenium used to locate elements 1. Name:This locator will be looking into the whole HTML code and returns the webelement with matching name attribute value this one will find and return the first webelent it finds. syntax : driver.findElement(By.name("name attribute value")); name locator may not always be unique there could be other elements under this name you have to be sure it is the only one .

what is locator linkText?

it is one of 8 locators in selenium used to locate webElements in HTML code. 2.Linktext (equals the text) -this Locater allows us to Locate Links by their text -this locater will only work if webelement has link. How do i understand if the webelemt has links ? <a href="https//www.amazon.com"> Text amazon </a> Tagname --> a Attribute --> href Atrribute Value https//www.amazon.com Link text --Text amazon this is what you would pass in findBy syntax : driver. findELement (By. Linktext ("Text amazon")); if you see href then a linkText will follow. this is not as unique you should check to see.

what is the name of the exception we get in selenium when it can't locate an element?

it'll throw NoSuchElement exception

what are dependencies in automation?

libraries or jar files that help us generate our code

what does BeforeClass annotation do?

makes the annotated method run ONCE before all of test, before methods in the class > Used for setting up environments, opening browsers etc.

What does @AfterClass do?

makes the annotated method run once after the tests in the class.

what does the after method annotation do?

makes the method run AFTER each @Test method. > Usually used to close things down such as closing the browser

Where do you get your webDriverManager dependency from?

maven repository and we get boniGarcia dependency

what is className locator?

one of 8 locators used to find elements in html code -className is not unique, thats why it might have multiple values of the same attribute -and it will return you the first one it finds syntax: driver, findELement (By. className ("class attribute value")) ; you can use html name and pass it as className that works as well

What is a CSS selector?

one of 8 locators used to find elements in html code it has own syntax, 3 ways of doing it as follows. common methods that you can use for css: 1.tagName[attribute='value'] 2.tagName.value--> .(dot) in css means locator className 3.tagName#value # means ID in css you can also go from parent to child EX: div[class='er4g']>a

What is XPath? how many types are there? which one is mostly used?

one of 8 locators used to find elements in html code there are two types of xpath absolute xpath and relative xpath. relative xpath being the most common, we tend to not use absolute xpath because of how time consuming it is. there are 3 ways to achieve relative xpath which allows you to locate element within anywhere in html code. 1. //tagname[@attribute='attributeValue'] looks for tagName, attribute, and value. 2. //tagname[contains(@attribute,'AttributeValue')] looks if it contains given value 3. //tagName[.='attributeValue'] when using dot it looks for exact match for any attribute . works only with text it'll be in white if you're using dark mode and black if you're using regular. for absolute xpath we start with one / and we need to start with parent beginning of html code to child EX: /html/body/div/div/a/html/body/div

what is tagName?

one of 8 locators used to find webElements in html code -you locate using tagname itself -we don't use this too often -it is good if you want to print same tag names for ex : if you wanna print all links in the page then you will use this method driver. findElements (By. tagName (a)) driver. findElements (By. tagName (div))

What happens when your attribute value has spaces?

selenium is liable to not read it correctly and take it as two webElements instead of one. solution= you can try to remove the space and see if it'll locate your element this way as one word.

What is td, th and tr in html code?

td- stands for table data tr -> stands for table row <td> stands for table data <th> -> stands for table header. just makes things centered and bold.

What are some of the steps before webPage gets passed to qa?

the developer will have url when its getting built EX: apple.come/dev when he is ready he will pass to QA and dev will change to QA and when QA is done QA will be passed down to end user.

When you open a new window or tab where is the driver or seleniums focus?

the driver focus will continue to be on the same tab or window you initiated with. in order for you to switch you must use driver.switchto method

what is the difference between cucumber BDD selenium TestNG?

the frame work differ, they are both UI frameworks webpage framework or used to test webpages . the structure or framework changes

What is a UI?

the point of human-computer interaction and communication in a device. This can include display screens, keyboards, a mouse and the appearance of a desktop. It is also the way through which a user interacts with an application or a website.

how many ways are there to use css selector? what does dot (.) and (#) mean in css selector?

there are 3 ways 1.the conventional way tagName[attribute=attributeValue] 2.using dot . and it means className EX:tagName--> input.classNameValue 3. hashTag # which means ID EX: tagName#IDValue

what is getText() method ?

this method will get the text of given webelemnt it will return the text of element as a String EX: <a id="ert" href="www.amazon.com">Amazon</a> get text method will return you Amazon. it will print text from html code everything in black is text

What is findElementBy method?

this method will return a single webElement hence return type is webElement

why do we need to automate?

time saving, reduces business expenses, faster feedback cycle, higher test coverage, reusability of test suite, improved accuracy, and eliminate human error.

how can we use isDisplayed() method?

to validate if certain elements are present in webPage. for example: if (SeleniumHeader.isDisplayed()){ System.out.println("selenium header is displayed");

What is the automation process ?

tool selection define the scope of automation what functions are going to be automated planning, design, and development automation strategy plan framework test execution maintenance

how can I go back and forward in my webpage using selenium?

using .navigate().back() or forward() and I can change my webpage also with navigate().to

if selenium is going too fast and you can't see process what is one way to slow it down?

using Thread.sleep(time) Thread being a static class we call with reference to class and sleep is method.

how do I create the connection between selenium and browser?

using WebDriverManager.ChromeDriver.setup() we establish connection then we must create the instance of webDriver to be able to use it to test but since it is an interface we must use polymorphism using child class to create the object or (instance).

since your getDriver method returns new browser how can you create the object?

using webDriver driver (whatever you choose to name your driver insurance) = WebDriverUtil.getDriver("chrome")

how do we do actions on the web?

we must first locate webElements wit selenium webDriver. we use findElement(By.locator)

What is dependsOnMethod in TestNG?

will either run or not depending on the pass or fail of another test case. Whenever you have a test that was not run because the dependency of another test case you'll see this in your skipped result after you've ran EX: skips: 1

what is the day to day life of a QA engineer?

write test scripts and handle test cases write documentation use tools and design frameworks

what is a different form of submit instead of using .click?

you can use .submit or you can do .sendKeys + Keys.Enter we are using keyboard option to click Enter and it comes from our dependencies EX: .sendKeys("njdfbjdbs"+Keys.ENTER);

what can you do to make your WebElment more unique if there is more than one?

you can use parentheses and specify which WebElement you swish to locate EX: (//span[.='Contact'])[1]

how do you create a configuration properties?

you use the Properties class to create the object of properties then you must create the path for properties to connect it to our code. to do this we use File class, create the instance of file inputStream and and use FileInputStream method and pass the path for our properties file. this allows code to load file and now we can use it to get useful information about our system 1- create properties object 2- get the path and store in String 3- open the file use FileInputStream method 4- Load the file to properties object by using load method from properties 5- close.file plus dont forget to handle exceptions

what is a script in automation?

your code written in your compiler


Set pelajaran terkait

Chapter 13 quiz asf kill me hdcnirjcdf

View Set

Texas Government Chapter 6: Interest Groups and Lobbying InQuizitive

View Set

Comprehensive Test Guide For ALL CHAPTERS Andrew's Edition

View Set

Chapter 5 - Life Insurance Underwriting and Policy Issue

View Set

Peds - Chapter 22: Nursing Care of the Child With a Neuromuscular Disorder

View Set