Selenium sample java project

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

This project comes to help other new QAs in web automation, bringing examples of how to use Selenium Webdriver with Java.

willysalazar/selenium-webdriver-java-example

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

UI Automation Example Project

Example project developed to perform automated tests on the website The-Internet

To collaborate with The Internet: https://github.com/saucelabs/the-internet

This project can be read in: Brazilian Portuguese

 $ git clone https://github.com/willysalazar/selenium-webdriver-java-example.git 
 $ cd /diretorio/selenium-webdriver-java-example 

Execute the command to run all tests in the project

Execute the command to run only one test class in the project

  • A/B Testing (✅)
  • Add/Remove Elements ( ✅ )
  • Basic Auth (✅)
  • Broken Images ( ⚠️ )
  • Challenging DOM ( ⚠️ )
  • Checkboxes ( ⚠️ )
  • Context Menu ( ⚠️ )
  • Digest Authentication (user and pass: admin) ( ⚠️ )
  • Disappearing Elements ( ⚠️ )
  • Drag and Drop ( ⚠️ )
  • Dropdown ( ⚠️ )
  • Dynamic Content ( ⚠️ )
  • Dynamic Controls ( ⚠️ )
  • Dynamic Loading ( ⚠️ )
  • Entry Ad ( ⚠️ )
  • Exit Intent ( ⚠️ )
  • File Download ( ⚠️ )
  • File Upload ( ⚠️ )
  • Floating Menu ( ⚠️ )
  • Forgot Password ( ⚠️ )
  • Form Authentication ( ⚠️ )
  • Frames ( ⚠️ )
  • Geolocation ( ⚠️ )
  • Horizontal Slider ( ⚠️ )
  • Hovers ( ⚠️ )
  • Infinite Scroll ( ⚠️ )
  • Inputs ( ⚠️ )
  • JQuery UI Menus ( ⚠️ )
  • JavaScript Alerts ( ⚠️ )
  • JavaScript onload event error ( ⚠️ )
  • Key Presses ( ⚠️ )
  • Large & Deep DOM ( ⚠️ )
  • Multiple Windows ( ⚠️ )
  • Nested Frames ( ⚠️ )
  • Notification Messages ( ⚠️ )
  • Redirect Link ( ⚠️ )
  • Secure File Download ( ⚠️ )
  • Shadow DOM ( ⚠️ )
  • Shifting Content ( ⚠️ )
  • Slow Resources ( ⚠️ )
  • Sortable Data Tables ( ⚠️ )
  • Status Codes ( ⚠️ )
  • Typos ( ⚠️ )
  • WYSIWYG Editor ( ⚠️ )

To contribute to this project follow the steps below

  • Option 1
    • 🍴 Fork this repository!
  • Option 2
    • Clone this repository to your local machine using: https://github.com/willysalazar/selenium-webdriver-java-example.git
Читайте также:  background-attachment

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A Java implementation of a selenium project using the Factory Pattern to manage the WebDrivers.

juniorerico/selenium-template-java

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A Java implementation of a Selenium Project using the developing Factory Pattern to manage the WebDrivers, containing Utility Functions and using TestNG to execute the tests. This project intends to be in constant evolution and help other tester to create their own test framework using the best developing practices as possible.

Feel free to fork it and suggest any improvement!

Читайте также:  Java developer and web developer

In class-based programming, the factory method pattern is a pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created.

The purpose of using this pattern in this project is to help us to create the WebDriver object without worrying about the creation logic every time.

This enum defines how each browser is initialized or instantiated.

public abstract WebDriver initialize(DesiredCapabilities capabilities);

To handle a new browser, just create a new Browser Enum field and implement the initialize method that return a WebDriver.

CHROME < @Override public WebDriver initialize(DesiredCapabilities capabilities) < synchronized (BrowserProvider.class) < WebDriverManager.chromedriver().setup(); ChromeOptions options = new ChromeOptions(); options.merge(capabilities); return new ChromeDriver(options); > > >

Instantiating a WebDriver

After implementing the initialize logic behind the scenes, in order to help us to instantiate a new WebDriver, just call the method createDriver of the class BrowserProvider passing a Browser Enum.

WebDriver driver = BrowserProvider.createDriver(Browser.CHROME);

The Page Object Model (POM)

Page Object Model is a design pattern which has become popular in test automation for enhancing test maintenance and reducing code duplication. A page object is an object-oriented class that serves as an interface to a page of the system under test.

In this framework, the Page Objects do not use the Page Factory concept in order to let the project more flexible and also to avoid slowness.

All Page Object is class that extends the PageBase class. This class don’t have much utility now, but let us add functionalities in the future, if necessary.

Declaring the Web Elements

The elements of the Page Object are Strings containing their xpath. In order to keep everything organized and easy to read, the elements must be declared following the pattern bellow:

Читайте также:  List add reference java
Web Element Type Prefix Examples
Text Box txt txtEmail , txtPassword
Button btn btnRegister , btnLogin
Drop down dd ddCountry , ddYear
Select Drop Down sdd sddMonth , sddYear
Check Box cb cbGender, cbSalaryRange
Header hdr hdrPrint, hdrUser
Table tbl tblBooks, tblProducts
Label lbl lblUserName, lblPassword
Image img imgProfile, imgCart
public class GoogleHomePage extends PageBase < private WebDriver driver; private String txtSearch = "//input[@name='q']"; private String btnSearch = "//input[@name='btnK']";

If we want to use the Web Elements out of the class or even inside of it, we must find them on the page. For this, we can create get methods for the elements we want to access. There are a bunch of Utility Methods to help us in this task, but it will be more explained later.

/** * Get the WebElement of the 'txtSearch'. * * @return */ public WebElement getTxtSearch() < return SeleniumUtils.waitForElement(driver, txtSearch); >

It is common in some projects do not give public access to the elements in order to avoid messing the project, but it depends on your purposes. In some cases, it is better to create methods to perform actions inside the class, for example, if we need to search for something in google page, is much better call a method giving the query we want, instead of doing it outside of the class.

/** * Performs a simple google search and return the next page. * * @param query */ public GoogleResultsPage searchFor(String query) < SeleniumUtils.waitForElement(driver, txtSearch).sendKeys(query); SeleniumUtils.waitForElementToBeClickable(driver, btnSearch).click(); return new GoogleResultsPage(driver); >

Utility Classes are very useful to provide reusable methods. The main utility class in this project is the SeleniumUtils one. This class intends to provide methods to help us to find elements, wait for certain conditions, manage checkboxes, radio buttons and more.

SeleniumUtils.findElement(driver, xpath); SeleniumUtils.findElements(driver, xpath); SeleniumUtils.waitForElement(driver, xpath); SeleniumUtils.waitForElementToBeClickable(driver, xpath); SeleniumUtils.waitForElementToBeVisible(driver, xpath); SeleniumUtils.waitForElementToBeInvisible(driver, xpath);

About

A Java implementation of a selenium project using the Factory Pattern to manage the WebDrivers.

Источник

Оцените статью