Selenium Cucumber Java BDD Framework Class 7: Page Factory
Page Factory:
-------------
1 - What is Page Factory
2 - How to implement Page Factory
What is Page Factory:
- A simple and easier implementation of Page Object Model in Selenium
- Selenium’s inbuilt and optimized Page Object Model concept
- As POM, has separation of objects and tests
- Uses annotation @FindBy to find WebElements
@FindBy can use id, name, css, xpath, tagName, linkText, partialLinkText etc
- Uses method initElements to initialize web elements
on calling initElements method all objects on that page gets initialized
Demo How to implement Page Factory Model
Step 1 - Create a class for each page
Step 2 - Create locators of all objects to be used in that page using @FindBy
Step 3 - Create methods or actions to be performed on the objects
Step 4 - Create constructor to get driver instance and
initialize Elements using method initElements
public LoginPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, LoginPage.class);
}
Step 5 - Update Test Scripts to refer methods from PageFactory class
Step 6 - Run and validate
--------------------------------
@CacheLookup
CacheLookup can be used to instruct the InitElements() method to cache the element once its located and so that it will not be searched over and over again whenever calling it from any method
@FindBy(id = "name")
@CacheLookup
WebElement txt_username;
This works well with a basic web application, but not recommended if you have Ajax applications where DOM changes on user actions.
In case you get StaleElementExceptions, avoid using this.
Useful Tips 2
In Ajax applications to handle loading time for element and to avoid
‘No Element Exception’, we can use
AjaxElementLocatorFactory Class
timeout for a WebElement can be assigned to the Object page class with the help of AjaxElementLocatorFactory
AjaxElementLocatorFactory factory = new AjaxElementLocatorFactory(driver, 30);
PageFactory.initElements(factory, this);
The above code will wait for maximum of 30 seconds until the elements specified by annotations is loaded.
If the element is not found in the given time interval, it will throw ‘NoSuchElementException' exception.
Useful Tips 3
With PageFactory, you can also locate a list of Elements
@FindBy(partialLinkText = "raghav")
List<WebElement> myLinks;
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Selenium Cucumber Java BDD Framework Class 7: Page Factory», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.