Intern Leadfoot WaitForAddedById functionality? - selenium

How can I simulate this feature? It seems like a conscious choice to have a WaitForDeletedById but not the reverse.
Upon an ajax load, how can I wait for the existence of a new element on the page, rather than the absence of one?

Use setFindTimeout to set how long the test should wait for an element to exist, then use the normal find methods. The only reason that a special waitForDeleted method exists is because it has to use a local polling method to efficiently respond to an element being deleted, whereas waiting for an element until it exists is functionality that is supported natively by the remote Selenium server.

Related

What is the difference between implicit wait and AjaxElementLocatorFactory?

Per definition,
An implicit wait is to tell Web Driver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.
See Implicit wait
Timeout for a WebElement will be assigned to the Object page class with the help of AjaxElementLocatorFactory
See AjaxElementLocatorFactory
From above, it's not clear what exactly the difference between implicit wait and AjaxElementLocatorFactory. Please explain.
Implicit Wait
An implicit wait is the approach to configure the WebDriver to poll the DOM for a certain amount of time when trying to find element/s if they are not immediately available within the HTML DOM. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.
You can find a couple of relevant discussions in:
Using implicit wait in selenium
selenium implicitly wait doesn't work
Python & Selenium: Difference between driver.implicitly_wait() and time.sleep()
AjaxElementLocatorFactory
AjaxElementLocatorFactory is one of the key advantage in implementing a waiter when using page-factory using the AjaxElementLocatorFactory Class.
AjaxElementLocatorFactory is basically the lazy-loading concept implemented with in Page Factory pattern to identify WebElements only when they are used in any operation i.e. a timeOut for a WebElement which can be assigned to the Object page class with the help of AjaxElementLocatorFactory.
An example:
AjaxElementLocatorFactory myFactory = new AjaxElementLocatorFactory(driver, 20);
PageFactory.initElements(myFactory, this)
Explaination:
In the above code block, when an operation is performed on an element the wait for its visibility starts from that moment only. If the element is not found in the given time interval, Test Case execution will throw NoSuchElementException exception.
You can find a relevant discussion in How to implement AjaxElementLocatorFactory through Selenium and Page Factory?
Implicit wait is something that is relevant to the entire driver object (and applicable to all lookups performed in the context of the driver). AjaxElementLocatorFactory is used when you initiate elements of your Page class. So that the waits are only be relevant to the elements which you describe within your Page class.
Since AjaxElementLocatorFactory utilizes the basic lookups but just wraps it with some more flexible logic, implicit wait that is applicable to all the lookups performed within your driver context might be added to the timeouts you have set up for your AjaxElementLocator (depending on the circumstances). Hence it is not recommended to mix them and in general it is recommended to avoid using implicit waits (it is set to 0 by default).

Best way to automate a page and check if it is loaded correctly

I am looking to verify if this page loads correctly - http://www2.hm.com/en_ca/women.html
These are the things I think it would be best to verify if the page is loaded correctly, please let me know if I am missing anything
1) Verify all the links on this page works?
2) Verify if the menu on the top is loaded correctly, Do I need to verify the menu names?
3) Check if the classes are loaded properly?
4) get/post request status 200 and other ajax calls?
As per your question a seperate test to check if the page is loaded correctly will be a complete overhead because the Client (i.e. the Web Browser) will never return the Execution Control back to the WebDriver instance until and unless 'document.readyState' is equal to "complete". Once this condition is fulfilled Selenium performs the next line of code.
You can find a detailed discussion on this topic in Selenium IE WebDriver only works while debugging
Next as you want to Verify if all the links on this page works or not , you can write a function() and invoke the function() whereever required.
Moving on to next question, there is no necessity to Verify if the menu on the top is loaded correctly or not as you can't test each and every aspect of each and every WebElement present on a WebPage. The best approach would be to verify and validate the attributes of only those elements with whom we need to interact.
Again Checking if the classes are loaded properly will be a overhead as JVM takes care of it in the best possible way.
Finally, to validate get/post request status 200 you have to write Tests as per your requirement.

Is it possible to combine multiple commands in single webdriver http call?

I'm using Selenium from Java with a remote grid. When I find an element on a page I would like to retrieve its text, multiple attributes from this element, check whether it is displayed and whether it is enabled.
As far as I can see each thing I retrieve triggers a new remote call (to http endpoint of the webdriver). Since I know beforehand which values I'm interested in I would like to combine them in a single http call (as the call can be quite slow). Is this possible in Selenium with Java? Or even with the webdriver protocol?
To be clear: my problem is not finding an element based on multiple criteria in one go, I know how to do that. But after I find the element I want to know the values of multiple properties, and I want to gather these efficiently.
As far as I can see the protocol requires a separate call for each attribute value, the text, whether the element is displayed and whether it enabled. For me this means for instance 6 round trips to the server, where one could suffice if I were able to 'multiplex' all data I would like to retrieve in a single call.
Is there a way to optimize retrieving multiple details/properties of an element once I found it?
On solution to have less calls between the driver and server could be to use some javascript in the context of the client side/window.
You can write something like
combinedObject = driver.executeScript("function(domelement) {
return { abc: domelement.getAttribute('abc'), efg: domelement.getAttribute('efg'), hij: domelement.getAttribute('hij') };
}",foundedElement);
This can reduce the number of calls between driver and server.
If it makes sense to mix some javascript functions with your java code is your decision.

DOM Element Load Time Benchmarking

I'd like to benchmark my web application. Specifically I'd like to measure the load time of a particular DOM element.
I can use webdriver's wait for visible to measure how long a an element took to load and save the result somewhere. However I'd also like to measure concurrency and other factors.
Is there a standard way to do this?
While I love WebdriverIO, I would recommend using a tool other than it for benchmarking. WebdriverIO uses HTTP requests to send commands to Selenium, and because of that isn't the most performant thing. Your stats could be way off simply because the request from WebdriverIO to Selenium takes longer than usual.
I'd suggest using a tool a little "closer to the metal", possibly CasperJS

Explicit selenium waits in intern

How can I use explicit waits using intern's leadfoot API for functional testing in intern?
There are multiple scenarios where I want to explicitly poll until a condition is met. For example, I want to wait until two or more elements exist in the DOM. Using findAllByCssSelector locks the execution for the whole implicit wait time instead of returning immediately after the condition is true.
All I can see that will help me is the pollUntil helper function, but it looks like this does not have access to any of the module dependencies defined in the test module.
How can I use something like jQuery within pollUntil?
findAllByCssSelector only waits for the implicit wait if no elements are found. If elements exist, the method finishes immediately with whatever it finds, so it's not ideal if you need to wait for a specific number of elements to appear.
pollUntil is the way to go for conditional waits. You are correct, though, that it doesn't have access to your module dependencies. Your dependencies are loaded in the context of Intern's test runner, while the pollUntil condition is going to run in the context of the browser. There are a couple ways to get the code you need into the browser. If you control the test page, you could just modify it to load whatever modules you need before the tests run. If you can't modify the test page, you could use an executeAsync call after loading the page in your test to inject whatever modules you need into the page context.