Selenium

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

How to assert title of the web page?

//verify the title of the web page assertTrue("The title of the window is incorrect.",driver.getTitle().equals("Title of the page"));

Testing Types that can be supported by Selenium

1. Functional Testing 2. Regression Testing

Why Selenium should be selected as a test tool

1. is free and open source 2. have a large user base and helping communities 3. have cross Browser compatibility (Firefox, chrome, Internet Explorer, Safari etc.) 4. have great platform compatibility (Windows, Mac OS, Linux etc.) 5. supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.) 6. has fresh and regular repository developments 7. supports distributed testing

Difference between assert and verify commands

Assert: Assert command checks whether the given condition is true or false. Let's say we assert whether the given element is present on the web page or not. If the condition is true then the program control will execute the next test step but if the condition is false, the execution would stop and no further test would be executed. Verify: Verify command also checks whether the given condition is true or false. Irrespective of the condition being true or false, the program execution doesn't halts i.e. any failure during verification would not stop the execution and all the test steps would be executed.

Behavior Driven Development Framework

Behavior Driven Development framework allows automation of functional validations in easily readable and understandable format to Business Analysts, Developers, Testers, etc.

What is a framework?

Framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar automation testing.

Get a text of a web element

Get command is used to retrieve the inner text of the specified web element. The command doesn't require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc displayed on the web pages. Syntax: String Text = driver.findElement(By.id("Text")).getText();

Different types of waits available in WebDriver

Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command. Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only.

When should I use Selenium Grid?

Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably.

How to retrieve css properties of an element?

The values of the css properties can be retrieved using a get() method: Syntax: driver.findElement(By.id("id")).getCssValue("name of css attribute"); driver.findElement(By.id("id")).getCssValue("font-size");

Type in a textbox using Selenium

User can use sendKeys("String to be entered") to enter the string in the textbox. Syntax: WebElement username = drv.findElement(By.id("Email")); // entering username username.sendKeys("sth");

Select value in a dropdown

Value in the drop down can be selected using WebDriver's Select class. Syntax: selectByValue: Select selectByValue = newSelect(driver.findElement(By.id("SelectID_One"))); selectByValue.selectByValue("greenvalue"); selectByVisibleText: Select selectByVisibleText = new Select (driver.findElement(By.id("SelectID_Two"))); selectByVisibleText.selectByVisibleText("Lime"); selectByIndex: Select selectByIndex = newSelect(driver.findElement(By.id("SelectID_Three"))); selectByIndex.selectByIndex(2);

Find if an element in displayed on the screen by:

WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc. 1. isDisplayed() 2. isSelected() 3. isEnabled() Syntax: isDisplayed(): boolean buttonPresence = driver.findElement(By.id("gbqfba")).isDisplayed(); isSelected(): boolean buttonSelected = driver.findElement(By.id("gbqfba")).isDisplayed(); isEnabled(): boolean searchIconEnabled = driver.findElement(By.id("gbqfb")).isEnabled();

How can we handle web based pop up?

WebDriver offers the users with a very efficient way to handle these pop ups using Alert interface. There are the four methods that we would be using along with the Alert interface. • void dismiss() - The accept() method clicks on the "Cancel" button as soon as the pop up window appears. • void accept() - The accept() method clicks on the "Ok" button as soon as the pop up window appears. • String getText() - The getText() method returns the text displayed on the alert box. • void sendKeys(String stringToSend) - The sendKeys() method enters the specified string pattern into the alert box.

Difference between driver.close() and driver.quit command?

close(): WebDriver's close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does is return any value. quit(): Unlike close() method, quit() method closes down all the windows that the program has opened. Same as close() method, the command neither requires any parameter nor does is return any value.

How to click on a hyper link using linkText?

driver.findElement(By.linkText("Google")).click(); The command finds the element using link text and then click on that element and thus the user would be re-directed to the corresponding page. driver.findElement(By.partialLinkText("Goo")).click(); The above command find the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element with the specified substring and then clicks on it.

When do we use findElement() and findElements()?

findElement(): findElement() is used to find the first element in the current web page matching to the specified locator value. Take a note that only first matching element would be fetched. Syntax: WebElement element =driver.findElements(By.xpath("//div[@id='example']//ul//li")); findElements(): findElements() is used to find all the elements in the current web page matching to the specified locator value. Take a note that all the matching elements would be fetched and stored in the list of WebElements. Syntax: List <WebElement> elementList =driver.findElements(By.xpath("//div[@id='example']//ul//li"));

Different types of navigation commands

navigate().back() - The above command requires no parameters and takes back the user to the previous webpage in the web browser's history. Sample code: driver.navigate().back(); navigate().forward() - This command lets the user to navigate to the next web page with reference to the browser's history. Sample code: driver.navigate().forward(); navigate().refresh() - This command lets the user to refresh the current web page there by reloading all the web elements. Sample code: driver.navigate().refresh(); navigate().to() - This command lets the user to launch a new web browser window and navigate to the specified URL. Sample code: driver.navigate().to("https://google.com");

What is Object Repository?

the collection of web elements belonging to Application Under Test (AUT) along with their locator values. Thus, whenever the element is required within the script, the locator value can be populated from the Object Repository. Object Repository is used to store locators in a centralized location instead of hard coding them within the scripts.

Different types of Drivers available in WebDriver

• FirefoxDriver • InternetExplorerDriver • ChromeDriver • SafariDriver • OperaDriver • AndroidDriver • IPhoneDriver • HtmlUnitDriver

Different types of selectors in Selenium

• ID • ClassName • Name • TagName • LinkText • PartialLinkText • Xpath (Never) • CSS Selector • DOM

Advantages of Automation framework

• Reusability of code • Maximum coverage • Recovery scenario • Low cost maintenance • Minimal manual intervention • Easy Reporting


संबंधित स्टडी सेट्स

Statistics Do Nows - Mr. Flanders

View Set

Gastrointestinal System Level 1 & 2

View Set

Chapter 1: Financial Markets & The Economy - Multiple Choice

View Set

CJ-230 1-2 Quiz: Identifying Discretion

View Set