Explicit selenium waits in intern - selenium

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.

Related

a wait that stops the test till nothing is happening in the web page anymore

I am using Java and Selenium to write a test. Many times in my test i have to wait till the page or some part of it loads something. I want to wait till the load is finished. I found these two:
1) pageLoadTimeout
2) setScriptTimeout
But I don't know the exact difference between them or even if they are what I need.
The document says:
setScriptTimeout: Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.
and
pageLoadTimeout: Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
but I don't really get it.
what I need is a wait that stops the test till nothing is happening in the web page anymore.
Define "nothing is happening in the web page." Now define it in such a way that will satisfy every web page ever created, or that ever will be created. Did your definition include that no more network traffic is coming over the wire? Did your definition include that the onload event has fired? How about document.readyState returning a value meaning "complete?" Did you take JavaScript execution into account? How about JavaScript scheduled using window.setTimeout()? WebSockets? Service Workers? What about <frame> or <iframe> elements?
Now you know why WebDriver doesn't have a "wait for page complete" type of wait. The items mentioned above don't even begin to scratch the surface of the list of things a user could legitimately use in a definition of "nothing is happening on the page anymore." The correct approach would be to wait for the element you want to interact with on the next page to be available in the DOM. The WebDriverWait class is ideally suited for exactly this.

Page Factory - how does it work

I've tried to implement one of our app modules by using PageFactory (for iOS)
Most of the elements are located by name and others by classname
In general everything works (more or less) but the thing is that the appium server has tons of logs , it seems that each time I'm trying to use some page control , and all the declared controls within that page are being update (?) which cause to longer time execution.
In case and I'm trying to debug my test , it takes a lot of time to move step by step (the appium server works extra hours ...)
I do use "CacheLookup" whenever it possible ...
Where my mistake is, or it's just should be like that ?
Thanks
Updated
Not enough info provided to say for sure. If you have a bunch of cucumber steps and each step is creating a new page instance then yes, you could create a class variable to communicate between cucumber steps
Class variables get thrown out at the end of each scenario so no cross scenario contamination. However, if a single scenario leaves a page and comes back you would need to explicitly set the class page handle to nil/null so that it is reinitialized upon reentry to that page. You want to avoid stale element errors.

Intern Leadfoot WaitForAddedById functionality?

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.

Too much waitforelement

Is it really necessary using waitForElement or another wait... if I test javascript single page application with loaded by ajax states? I must precede every action (eg: click,type) by waitForElement.
yes, it is necessary for Ajax. But it is not a problem if you use "don't repeat yourself" principle. You should create method like this:
clickWithExplicitWait(lctr) {
waitForElementPresent(lctr)//uses ajax wait timeout
driver.click(lctr)//uses implicit wait timeout
}
driver.click() uses implicit wait. So you can specify a different timeouts for implicit wait and for explicit "element wait".
You can implement waitForElementPresent() or other similar methods using org.openqa.selenium.support.ui.ExpectedConditions package.
If you need to wait for another element to appear after action, use something like:
clickAndWait(lctrToClick, lctrToWait) {
driver.click(lctrToClick)
waitForElementPresent(lctrToWait)
}

How to use JMeter test component (i.e. sampler or assertion) twice in same test?

GUI mode is interesting.
At this moment I create one component (i.e. assertion) and then copy and paste it on every place where it's needed. But if I change assertion in some place I must manually change all same assertions in all other places where its used.
Reusability in Jmeter can be done in 4 ways:
include controller when you want to reuse a subset of test (login, logout)
module controller to reuse controller in existing plan
user defined variables that you can reuse everwhere
xxx defaults for some samplers ( Ftp, Http...)
But in your particular case you can do it as below.
Define your expression as a var in User Defined Variable then use it in your assertions:
http://jmeter.apache.org/usermanual/component_reference.html#User_Defined_Variables
For sampler use Http Request Defaults to factor what is common between them.
http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request_Defaults
Note that to find elements with same regexp expression yoy can use search feature which highlights results of search.
IMHO The cleanest way to reuse components is to use ModuleController with jMeter Plugins' ParametrizedController.
The ParametrizedController link above will explain you how it's done.