Ans:@Test@BeforeSuite,@AfterSuite,@BeforeTest,@AfterTest, @BeforeClass, @AfterClass, @BeforeMethod, @AfterMethod, @BeforeGroups, @AfterGroups
Q2. What is a hub in Selenium Grid?
Ans: A hub is a server or a central point that controls the test executions on different machines.
Ans: FileInputStream fis = new FileInputStream (“path of excel file”);
Workbook wb = WorkbookFactory.create (fis);
Sheet s = wb.getSheet (“sheetName”)
String value = s.getRow (rowNum).getCell (cellNum).getStringCellValue ();
Ans: Node is the machine which is attached to the hub. There can be multiple nodes in Selenium Grid.
Ans: Soft Assert: 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
Hard Assert: Hard Assert throws an Assert Exception immediately when an assert statement fails and test suite continues with next @Test
Ans: In Selenium IDE, we use Selenese Verify and Assert Commands as Verification points
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
To check for page title
To check for certain text
To check for certain element (text box, button, drop down, etc.)
Ans: Page Object Model is a design pattern for creating an Object Repository for web UI elements. Each web page in the application is required to have it’s own corresponding page class. The page class is thus responsible for finding the Web Elements in that page and then perform operations on those Web Elements. The advantages of using POM are: Allows us to separate operations and flows in the UI from Verification – improves code readability Since the Object Repository is independent of Test Cases, multiple tests can use the same Object Repository Reusability of code
Ans: WebDriver is an Interface. We create Object of a WebDriver Interface.
<2.53 – no geckodriver
3.x – geckodriver for FF
To launch Firefox Driver: WebDriver driver = new FirefoxDriver();
To launch Chrome Driver: WebDriver driver = new ChromeDriver();
To launch Internet Explorer Driver: WebDriver driver = new InternetExplorerDriver();
Ans: FirefoxDriver is a Java class, and it implements the WebDriver interface.
Ans: SearchContext.
Ans: Page Factory gives an optimized way to implement Page Object Model. When we say it is optimized, it refers to the fact that the memory utilization is very good and also the implementation is done in an object oriented manner. Page Factory is used to initialize the elements of the Page Object or instantiate the Page Objects itself. Annotations for elements can also be created (and recommended) as the describing properties may not always be descriptive enough to differentiate one object from the other. The concept of separating the Page Object Repository and Test Methods is followed here also. Instead of having to use ‘FindElements’, we use annotations like: @FindBy to find WebElement, and initElements method to initialize web elements from the Page Factory class. @FindBy can accept tagName, partialLinkText, name, linkText, id, css, className & xpath as attributes. Since the Object Repository is independent of Test Cases, multiple tests can use the same Object Repository Reusability of code
Ans: ‘WebDriver‘ is an interface and we are creating an object reference of type WebDriver instantiating an object of FirefoxDriver class.
Ans: WebDriver driver = new FirefoxDriver();
instead of creating
FirefoxDriver driver = new FirefoxDriver();
What is the purpose of doing this way?
f we create a reference variable driver of type WebDriver then we could use the same driver variable to work with any browser of our choice such as IEDriver, SafariDriver etc.,
//FirefoxDriver driver = new FirefoxDriver();
ChromeDriver driver = new ChromeDriver();
driver.get(“http://www.google.com”);
WebDriver driver = new FirefoxDriver();
Ans: WebDriverException
TimeoutException
NoAlertPresentException
NoSuchWindowException
NoSuchElementException
StaleElementReferenceException
IllegalStateException
Ans: We can handle special keyboard and mouse events by using Advanced User Interactions API. The Advanced User Interactions API contains the Actions and the Action Classes that are needed for executing these events. Most commonly used keyboard and mouse events provided by the Actions class are in the table below: Method Description clickAndHold() Clicks (without releasing) the current mouse location. dragAndDrop() Performs click-and-hold at the location of the source element, moves. source, target() Moves to the location of the target element, then releases the mouse
Ans: To do this we pass username and password with the URL
http://username:password@url
e.g. http://admin:admin123@xyz.com
Ans: In Selenium we could see three types of waits such as Implicit Waits, Explicit Waits and Fluent Waits.
Implicit Waits –
Explicit Waits –
Fluent Waits –
PageLoadTimeOut
Thread.sleep() – static wait
Ans: Implicit waits tell to the WebDriver to wait for a certain amount of time before it throws an exception. Once we set the time, WebDriver will wait for the element based on the time we set before it throws an exception. The default setting is 0 (zero). We need to set some wait time to make WebDriver to wait for the required time.
Ans: WebDriverWait is applied on a certain element with defined expected condition and time. This wait is only applied to the specified element. This wait can also throw an exception when an element is not found.
Ans: These are the different drivers available in WebDriver: FirefoxDriver InternetExplorerDriver ChromeDriver SafariDriver OperaDriver AndroidDriver IPhoneDriver HtmlUnitDriver
Ans: FluentWait can define the maximum amount of time to wait for a specific condition and frequency with which to check the condition before throwing an “ElementNotVisibleException” exception.
Ans: By using sendKeys() method
WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
driver.findElement(By.xpath("xpath")).sendKeys("test");
Ans: // To initialize js object
JavascriptExecutor JS = (JavascriptExecutor)driver;
// To enter username
JS.executeScript("document.getElementById(‘User').value=test.com'");
Ans: By using clear() method
WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
driver.findElement(By.xpath("xpath_of_element1")).sendKeys("Software Testing Material Website");
driver.findElement(By.xpath("xpath_of_element1")).clear();
Ans: We can use isSelected () method.
Syntax – driver.findElement (By.xpath (“xpath of the checkbox/radio button”)).isSelected ();
If the return value of this method is true then it is checked else it is not.
Ans: By using getText() method
Ans: By using getAttribute(value);
Ans: We use click() method in Selenium to click on the hyperlink
driver.findElement(By.linkText(“Software Testing Material Website”)).click();
Ans: We use “submit” method on element to submit a form
driver.findElement(By.id("form_1")).submit();
Alternatively, you can use click method on the element which does form submission
Ans: To press ENTER key using Selenium WebDriver, We need to use Selenium Enum Keys with its constant ENTER.
driver.findElement(By.xpath("xpath")).sendKeys(Keys.ENTER);