Selenium – Full Stack QE https://fullstackqe.org Just another WordPress site Thu, 01 Jul 2021 20:50:56 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.6 155680629 Optimize Selenium WebDriver Automated Test Scripts: Maintainability https://fullstackqe.org/optimize-selenium-webdriver-automated-test-scripts-maintainability/ Thu, 01 Jul 2021 20:50:34 +0000 https://fullstackqe.org/?p=741 Continue reading "Optimize Selenium WebDriver Automated Test Scripts: Maintainability"

]]>
[A must read for all SDETs and Automation Engineers].

This time Zhimin Zhan provides a number of code examples for improving test maintainability.

When you can run automated tests often, and the application changes all the time, it is important that test scripts are: Quick and easy to maintain. Easy to read.

The leading reason for test automation to fail is that the team fails to maintain its automated scripts. In this article, Zhimin Zhan helps to understand some simple and practical tips at the test steps level that can help you make your automated functional tests more maintainable. These techniques are:

  • One Test Script Line for One User Operation
  • Default Parameter Value
  • Extend function behaviour with optional Hashmap

Click here to Read complete article.

]]>
741
Uploading Files with Selenium Java – Test Automation Cookbook – via Applitools https://fullstackqe.org/uploading-files-with-selenium-java-test-automation-cookbook-via-applitools/ Sun, 11 Apr 2021 19:32:55 +0000 https://fullstackqe.org/?p=683 Continue reading "Uploading Files with Selenium Java – Test Automation Cookbook – via Applitools"

]]>
Angie Jones and Applitools has recently launched a new initiative – Automation Cookbook. It has free bite-size recipes related to JS (#Cypress) & Java (#Selenium).

Here is a tip from cookbook: Uploading files with Selenium Java:

Code:

package file_upload;

import base.BaseTests;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;

public class FileUploadTests extends BaseTests {

    @BeforeEach
    public void launchApp(){
        driver.get("https://kitchen.applitools.com/ingredients/file-picker");
    }

    @Test
    public void testFileUpload() {
        String filePath = "/Users/angie/workspace/recipes/resources/images/mac-n-cheese.jpg";
        driver.findElement(By.id("photo-upload")).sendKeys(filePath);
    }
}

You can practice above code in this file picker: https://kitchen.applitools.com/ingredients/file-picker

Find more Selenium and Cypress recipes over at the Automation Cookbook: https://applitools.com/cookbook/

Thanks to Angie and Applitools for making our life easy.

]]>
683
Top Selenium Commands Cheat Sheet https://fullstackqe.org/top-selenium-commands-cheat-sheet/ Sat, 13 Mar 2021 19:56:09 +0000 https://fullstackqe.org/?p=668 Continue reading "Top Selenium Commands Cheat Sheet"

]]>
Fetching a web page
Using Get method:
driver.get(“www.google.com”)

Using Navigate method:
driver.navigate().to(“https://google.com “);

Locating forms and sending user inputs
driver.findElement(By.id(“lst-ib”)).sendKeys(“selenium tutorials”);

Clearing User inputs
driver.findElement(By.name(“q”)).clear();

Fetching data over any web element
driver.findElement(By.id(“element567”)).getText();

Performing Click event
driver.findElement(By.id(“btnK”)).click();

Navigating backward in browser history
driver.navigate().back();

Navigating forward in browser history
driver.navigate().forward();

Refresh/ Reload a web page
driver.navigate().refresh();

Closing Browser
driver.close();

Closing Browser and other all other windows associated with
the driver
driver.quit();

Moving between Windows
driver.switchTo().window(“windowName”);

Moving between Frames
driver.switchTo().frame(“frameName”);

Drag and Drop
WebElement element = driver.findElement(By.name(“source”));
WebElement target = driver.findElement(By.name(“target”));
(new Actions(driver)).dragAndDrop(element, target).perform();

]]>
668
Difference between WebDriverlistener and TestNG listener? https://fullstackqe.org/difference-between-webdriverlistener-and-testng-listener/ Sat, 13 Mar 2021 19:15:16 +0000 https://fullstackqe.org/?p=666 Continue reading "Difference between WebDriverlistener and TestNG listener?"

]]>
You must have always craved for more logs from the Webdriver so that you can debug your scripts or may be log more information about your tests. 

Here is your answer to it, WebDriverEventListner and TestNgListner(ITestListener Interface.)

 In TestNg you can use Listeners in Annotation.

WebDriverEventListener – This is an interface, which have some predefined methods so we will implement all of these methods.

Difference:- TestNG Listener are triggered at test level such as before starting test after the test or when test fails etc; whereas WebDriver Listener are triggered at component level such as before click, after click etc

]]>
666
Selenium code to capture screenshot only when test fails. https://fullstackqe.org/selenium-code-to-capture-screenshot-only-when-test-fails/ Sat, 13 Mar 2021 18:50:05 +0000 https://fullstackqe.org/?p=656 ITestResult is an interface which give information about our current test case which is under execution
result variable will store all the details of @Test along with the pass or fail result.


——————-
@AfterMethod
public void tearDown(ITestResult result) throws IOException
{
if(ITestResult.FAILURE==result.getStatus())
{
UtilityScrnSht.ScreenShot(Page.driver, result.getName());
//user created method
}
}
——————–

]]>
656
Simplest Guide to XPath Axes in Selenium Webdriver by Codoid https://fullstackqe.org/simplest-guide-to-xpath-axes-in-selenium-webdriver-by-codoid/ Mon, 14 Dec 2020 12:38:14 +0000 https://fullstackqe.org/?p=587 Continue reading "Simplest Guide to XPath Axes in Selenium Webdriver by Codoid"

]]>
Simplest guide to XPath Axes by Codoid. Must Read:

To use XPath effectively in Selenium WebDriver, you should be familiar with XPath Axes and HTML. There are thirteen axes available for XPath. As per the definition in Mozilla Web Docs – “An axis represents a relationship to the context node, and is used to locate nodes relative to that node on the tree.”

As an automation tester, if you are familiar with XPath Axes, you can write robust locators for dynamic WebElements.

Let’s look into all the XPath Axes which are useful for test automation scripting.

Let’s say you want to select a parent node using its child node. You first write XPath to pick the child node and the parent node using XPath parent axis.

Read More at: https://codoid.com/how-to-use-xpath-axes-in-selenium-webdriver/

Read More at: https://codoid.com/how-to-use-xpath-axes-in-selenium-webdriver/

]]>
587
Selenium – Python – Get all child elements https://fullstackqe.org/390-2/ Wed, 01 Jul 2020 18:50:46 +0000 https://fullstackqe.org/?p=390 <body> <form id=”loginForm”> <input name=”username” type=”text” /> <input name=”password” type=”password” /> <input name=”continue” type=”submit” value=”Login” /> </form> </body> <html> The form element can be located like this: login_form = driver.find_element_by_id(‘loginForm’) More references here]]> There are various ways to find child elements:

  • find_elements_by_name
  • find_elements_by_xpath
  • find_elements_by_link_text
  • find_elements_by_partial_link_text
  • find_elements_by_tag_name
  • find_elements_by_class_name
  • find_elements_by_css_selector

For instance, consider this page source:

<html>
<body>
<form id=”loginForm”>
<input name=”username” type=”text” />
<input name=”password” type=”password” />
<input name=”continue” type=”submit” value=”Login” />
</form>
</body>
<html>

The form element can be located like this:

login_form = driver.find_element_by_id(‘loginForm’)

More references here

]]>
390
Most Exhaustive WebDriver Locators Cheat Sheet. https://fullstackqe.org/most-exhaustive-webdriver-locators-cheat-sheet/ Thu, 09 May 2019 04:53:05 +0000 https://fullstackqe.org/?p=213 Continue reading "Most Exhaustive WebDriver Locators Cheat Sheet."

]]>
Download the most extensive Selenium WebDriver Locators cheat sheet. All you need to to know- the most basic locators to the most advanced ones. Contains:

  • full list of the most used CSS selectors
  • complete list of the most used XPath selectors
  • CSS and XPath locators about parent and child relations
  • most widely used XPath axes selectors
  • CSS pseudo-classes locators
  • selectors for working with HTML tables

Click here to download.

Cheatsheet provided by www.automatetheplanet.com.

]]>
213
[Tip] How to Speed up the UI Automation tests? https://fullstackqe.org/how-to-speed-up-the-ui-automation-tests/ https://fullstackqe.org/how-to-speed-up-the-ui-automation-tests/#comments Sat, 15 Dec 2018 04:20:12 +0000 https://fullstackqe.org/?p=12 Continue reading "[Tip] How to Speed up the UI Automation tests?"

]]>
When we ran our scenarios through the UI using Selenium it made our test suite slow.
What could you do to speed it up?

Often, the best way to speed up a UI test is to remove it, or rather, refactor it to a domain layer test that doesn’t go through the UI, but talks directly to the domain layer.
If you’re unable to do that, there are still things you can do to speed up UI tests. Start by
identifying what steps and hooks are slow.

Are you starting your web app in a Before hook for every scenario? Try starting your app only once, for all scenarios.

Are you launching a new browser for every scenario? Try reusing the browser instance.
Do your scenarios need to go through a lot of pages before you get to the UI you really want to test? Try to go directly to the page you need to test, and set up the data you need “underneath” the UI.

Many of these optimisations introduce a new problem – you might have state leaking between scenarios. When state leaks between scenarios they might pass when run in a certain order, but they might fail when run in a different order. This can make it very difficult and time consuming to fix failing scenarios. To avoid this we recommend you use Before hooks to explicitly clear state that might have been left over from the previous scenario.

Source/References: https://cucumber.io/

]]>
https://fullstackqe.org/how-to-speed-up-the-ui-automation-tests/feed/ 1 12