8

Page Object and Selenium's PageFactory are distinct things in nature, usually the latter complement the former. Page Object is a design pattern aimed at solving the problem of separating the application interface from the HTML interface. Why do we separate these interfaces? Because web pages elements and functions, as saw by the user, differ from the HTML ...


7

I think the Page Factory is an extension of the Page Object Model. This Selenium documentation page describes with examples what the Factory adds. If you use the PageFactory, you can assume that the fields are initialised. If you don't use the PageFactory, then NullPointerExceptions will be thrown if you make the assumption that the fields are ...


3

Do you really want to test that the text Welcome is there? You say the identifiers are dynamic. In these situations, I always suggest to talk to the developers and make it better testable. Preferably developers and testers write and maintain the end-to-end tests together. Let them feel your pain. Now when in application developer change welcome to ...


3

Unfortunately, it's not possible to send arguments to annotation (reference) One possible solution would be to create a Page Object class for link and pass a WebElement based on its li node. Class Footer { @FindBy(css = "footer") WebElement baseElement; List<WebElement> links; Footer() { this.links = this.createLinks(); ...


3

Design pattern is not a magic ingredient which makes code perform better. It's goal is to make code easier to understand for a programmer (by pushing some effort to organize function calls/data/etc to computer). So by definition, your code using design pattern is more compact (easier to understand) but makes more calls (unless your original code before ...


2

Two key reasons to use a Page Factory: To centralize the code that creates the objects in one place instead of repeating the same code every time you need an object To use lightweight techniques to create objects, for example creating the object in memory but not in the database


2

I guess the "Login & Signup" button itself was not clicked and you would have got some error like, "Element is not clickable at point(x,y)..." Try this code, driver.findElementByXPath("//div[@class='_1jJkOg']/a").sendKeys(Keys.RETURN); driver.findElementByXPath("(//input[@type='text'])[2]").sendKeys("username"); driver.findElementByXPath("//input[@type=...


2

Try using the following code for login functionality in Flipkart: driver.findElement(By.linkText("Login & Signup")).click(); driver.findElement(By.className("_2zrpKA")).sendKeys(" YOUR USER NAME"); driver.findElement(By.class("_2zrpKA _3v41xv")).sendKeys("YOUR PASSWORD"); driver.findElement(By.className("_2AkmmA _1LctnI _7UHT_c")).submit();


2

I appreciate that author's contribution to the people's global knowledge sharing but I have doubt on how well he mastered his Java skills at least because of he doesn't adhere coding style convention that discourages snake_case style. Nobody also uses capitalized letters in package names. So I wouldn't rely on that or at least I would treat that with certain ...


2

If I have understood your question correctly, then following are the changes that you need to do: 1. The method setfirstname is not a Test method, so remove the @Test annotation. 2. The method valid under the Validdata class is a Test method so add the annotation @Test(dataProvider="first", dataProviderClass=CommonElements.class) So your test method looks ...


2

If I understand correctly - You want to check if some particular WebElement is missing. While doing so you get a NoSuchElementException. The solution here will be to create a function that returns a boolean value if an element is present. Something like this: public boolean isPresent(By locator) { try { webDriver.findElement(locator); ...


2

The PageFactory class is now considered deprecated in the Selenium binaries; that could be the issue. But, I would still try adding the following to your code to see if it will resolve. using OpenQA.Selenium.Support.PageObjects; Failing that, you could use NuGet to install this package in your project.


2

Here is the post where Jim Evans (the maintainer of C# Selenium binding) explains the issue you mentioned. In short: Its only now that I have started to write Selenium tests in C# that I understand why the implementation was described as deeply flawed. The reason for dropping support now is due to it using proxies that have been deprecated from dotnet, ...


1

If this is really what you need you can obtain the value of foundBy field of the RemoteWebElement using Java Reflection API Example code: java.lang.reflect.Field field = panel.getClass().getDeclaredField("foundBy"); field.setAccessible(true); String foundBy = field.get(element).toString(); But remember when you bypass Java encapsulation using reflection ...


1

Unfortunately you can not. You can see the WebElement interface here. The closest you can do is to call getAttribute and you could extract an ID or a specific class name. However, you can create a wrapper over WebElement that stores the locator: public class RefreshableWebElement implements WebElement { ... public RefreshableWebElement(Driver ...


1

Selenium will instantiate a WebElement object when you call PageFactory.initElements(driver, LaunchURLRepository.class) Before this statement, any interaction with the WebElement attributes will result in a NullPointerException. More details on the Selenium Wiki and the Javadoc of this method here.


1

Judging by this: Java.lang.NullPointerException at java.io.FileInputStream.(Unknown Source) at java.io.FileInputStream.(Unknown Source) at com.mercury.qa.base.BaseTest.(BaseTest.java:26) at com.mercury.qa.testcase.LoginPageTest.(LoginPageTest.java:18) ... 26 more } The properties file cannot be found - you should fix the path, or create a ...


1

The page object model is a design pattern that describes the best approach for modeling a test automation framework when it comes to web automation. The @FindBy() annotation is just a shortcut provided to developers by the PageFactory class. Use of the @FindBy() annotation is not mandatory for you to use the page object principles. You can still model your ...


1

It's been a long time since I worked with Java so my code suggestions are going to be more pseudo-code than full code. That said, the way to handle this situation is to have your page object methods return the next page object you require. So your clickLoginIBMButton() method would become more like the following pseudo-code: public AuthenticationScreen ...


1

You can have a static class called TestData, which will hold the test user. public final class TestData { @Getter private static String testUser; public static void resetTestUser() { this.testUser = String.format("test%s@demo.com", getTimeStamp()); } } And on BaseClass, you can have a @BeforeSuite method: @BeforeSuite public ...


1

If I got you right you have the case like this: If yes, then you can define all the items in the container in the way Selenium provides to define page objects and then iterate through the items from that container. Here is the sample PageWithSideNav class implementing the approach against https://www.w3schools.com/ page: package ar.test; import org.openqa....


1

From your question, it looks like applying the Dependency Injection (https://en.wikipedia.org/wiki/Dependency_injection) may solve the issue. That means that you will need to program against the abstraction, rather the concrete implementation of each PageObject (e.g. using the interfaces, that will provide contract for particular page within your tests) and ...


1

Test Executors have nothing to do with how you tell Selenium which objects to use. Personally I do not see any benefit of using PageFactory in the situation like yours. Having stuck to page objects you will have to maintain different sets of objects for each your site which means if the objects set will change you will have to amend all your Page classes. I ...


1

If you are up for using Ruby say, you could: store the name and locators as key-value pairs in a .yml file Create a Page Object class with an initialize method that read the YAML file and dynamically adds the methods to the new instance of the class. Make the initialize method go through each line of the file and dynamically add the method to the class. ...


1

It's possible. Depending on the language and implementation of cucumber you're using, how you do it will vary, but assuming the process you're looking at is all inside one test, it will go something like this: Enter details into the page Read the unique number from the page (it should be stored in a local variable of some flavor) Go to the next page Enter ...


1

A page object can contain more than just individual web elements and their corresponding functions. For example, a logon page would list the individual web elements through the FindBy's but would not necessarily need to have specific sendkey or click methods (for the button) individually unless you wish to provide those features for lower-level tests. It ...


1

PageFactory follows the LazyLoading design pattern where the variable initialization is delayed till the object is needed. So, once you do the PageFactory.initElements(driver, this) the variables will be wired. Now if you have have not done any operation(sendKeys etc.) on the element inputSearch prior to the page refresh then you the variable will be refer ...


Only top voted, non community-wiki answers of a minimum length are eligible