What if my implicit wait is 10 secs and explicit wait is 5 secs, will it wait for 15 seconds in expected conditions - selenium

When i write some implicit wait like 10 sec and then for a element i give 5 seconds time in explicit wait...then will the implicit wait become zero and only wait for 5 sec or it will add the implicit wait time as well means will it wait for 15 secs

Let me answer you one by one:
Whenever you put an ImplicitlyWait Selenium will perform that wait after each action. So it becomes contagious.
When you put an Explicit Wait, those are defined as per certain conditions like "visibility of an element" within until block.
So each type of wait behaves in their own fashion just by the way you implement them.
Once you assign timeunits for each type of wait, they are followed in execution. They never gets added or substructed.
ImplicitlyWait is mentioned only once within​ your code. This instruction is for the Webdriver to follow. ImplicitlyWait have no effect on any element in particular.
Where as Explicit Wait is assigned to ask the Webdriver to wait for a defined time period (e.g. 5 seconds) with a until condition which specifies the state of an element (e.g. element_to_be_visible) the Webdriver should look for.
Now answering your question: 10 seconds ImplicitlyWait for a element is not a valid statement. Explicit Wait of 5 second you have to put for a certain state/behavior of the element (e.g. element_to_be_clickable). If the element doesn't shows that behavior within the defined time slot Selenium will throw an exception.
Let me know if this answers your question.

Related

Questions about implicit waits in Selenium Webdriver

I'm reading the docs on Implicit Waiting with Webdriver but I'm not sure I totally understand.
As I understand it,
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
This will put in place a timeout of 10 seconds whenever looking up any element.
What, exactly, does this do?
Does it mean that when looking up any element, I will wait 10 seconds every time, even if the element is present? Or, when looking up any element, will the driver give the browser a 10-second grace period to load the element before deciding the element missing?
Since this is applied to every element, am I correct in supposing that this is just executed only once for each instance of Webdriver?
This will look for the element up to 10 seconds, trying to locate it every 500 milliseconds (default timeout).
From the docs
Specifies the amount of time the driver should wait when searching for
an element if it is not immediately present.
When searching for a
single element, the driver should poll the page until the element has
been found, or this timeout expires before throwing a
NoSuchElementException. When searching for multiple elements, the
driver should poll the page until at least one element has been found
or this timeout has expired.
The locating algorithm is described in W3C specifications
The Find Element, Find Elements, Find Element From Element, and Find
Elements From Element commands allow lookup of individual elements and
collections of elements. Element retrieval searches are performed
using pre-order traversal of the document’s nodes that match the
provided selector’s expression. Elements are serialized and returned
as web elements.
When required to find with arguments start node, using and value, a
remote end must run the following steps:
Let end time be the current time plus the session implicit wait
timeout.
Let location strategy be equal to using.
Let selector be equal to value.
Let elements returned be the result of trying to call the relevant
element location strategy with arguments start node, and selector.
If a DOMException, SyntaxError, XPathException, or other error occurs
during the execution of the element location strategy, return error
invalid selector.
If elements returned is empty and the current time
is less than end time return to step 4. Otherwise, continue to the
next step.
Let result be an empty JSON List.
For each element in elements returned, append the serialization of
element to result.
Return success with data result.
implicitlyWait is defined once for the WebDriver and last its lifetime.
Defines a wait time globally in your project. Your telling your driver to wait for n number of seconds before selenium throws an exception. If element is found earlier then the n number of seconds you mentioned, webdriver will click it once its available and dont wait for the maximum n number of seconds. It does have to wait before it throws an exception.

What is the difference between ExpectedConditions.presenceOf and element.isPresent

I have been testing with element.IsPresent(), for some reason my test start failing when trying to do browser.wait(element(by.id('id').IsPresent()). It never get away from the wait, even the element being present.
I started using the code with protractor.ExpectedConditions and it start working. just want to know what is the difference between one and the other.
Here is the code with the Expected Conditions.
const EC = protractor.ExpectedConditions;
const ele = element(by.id('id'));
return browser.wait(EC.presenceOf(ele));
What is the main difference between one and the other? I have search in google but haven't found a proper answer.
If you take a look at this answer on another question you will see that both presenceOf() and isPresent() are almost entirely the same. The primary difference being that presenceOf() wraps around isPresent() and returns a Function rather than a Promise.
So why is this important? Well it has to do with how browser.wait() works. If we take a look at the docs we can see that it:
Schedules a command to wait for a condition to hold or promise to be resolved.
This means that if you pass a Promise to browser.wait() it will only wait until that Promise is resolved before continuing on and executing further commands (it doesn't necessarily matter if it resolved true or false). Whereas if you pass a Function to it, it will wait until that condition "holds" before continuing.
Additionally, you can specify a custom timeout parameter for the browser.wait() method. If you do not specify a timeout it will default to 30 seconds according to the docs. I believe this is why you felt that the wait never resolves when using isPresent() (it was likely just taking 30 seconds).
What I would suggest to do is use isPresent() when you expect an element to be present at a specific moment in time and use presenceOf() when you want to wait for an element to be or become present.
Here's an example of how I would use the two:
const EC = protractor.ExpectedConditions;
const ele = element(by.id('id'));
browser.wait(EC.presenceOf(ele), 5000); // Waits a maximum of 5000 milliseconds (5 seconds)
expect(ele.isPresent()).toBe(true); // Expects this element to be present **right now**

Sleep in Smalltalk Squeak

I'm dealing with N*N queens problem and gui of it.
I want to sleep for a few seconds each move so the viewer can see the process.
How do I put smalltalk to sleep?
Thank you
Instead of sleeping you can just wait.
5 seconds asDelay wait.
e.g. if you select and print it the following, it will wait 5 seconds before printing the result (2)
[
5 seconds asDelay wait.
1 + 1
] value
The comment of the Delay class explains what it does.
I am the main way that a process may pause for some amount of time. The simplest usage is like this:
(Delay forSeconds: 5) wait.
An instance of Delay responds to the message 'wait' by suspending the caller's process for a certain amount of time. The duration of the pause is specified when the Delay is created with the message forMilliseconds: or forSeconds:. A Delay can be used again when the current wait has finished. For example, a clock process might repeatedly wait on a one-second Delay.
A delay in progress when an image snapshot is saved is resumed when the snapshot is re-started. Delays work across millisecond clock roll-overs.
For a more complex example, see #testDelayOf:for:rect: .
Update: (based on comment)
wait will pause the execution flow, which means that in the example earlier, the 1 + 1 will get executed (execution flow resumed) only after the wait period has ended.
So in your class you can have...
MyBoard>>doStep
self drawBoard.
5 seconds asDelay wait.
self solve.
5 seconds asDelay wait.
self destroyBoard.

What if Implicit and Explicit wait, both are used in Framework [duplicate]

This question already has answers here:
Combining implicit wait and explicit wait together results in unexpected wait times
(2 answers)
Closed 8 years ago.
I understand both waits and use of it. But one thing that I could not figure out is : If I put implicit wait for 5 seconds at top and then use explicit wait for an element. Then how selenium will behave. Tried but could not get satisfactory answer on net.
First understand the concepts of Explicit and Implicit wait
Implicit Wait: An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.
For Example:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));
Explicit Wait:
An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code.
There are some cases where the explicit wait is functionally equivalent to implicit wait, means
a) Where waiting time is not predefined like below (please note they were distinct by method category they belong explicit or implicit)
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
b) Cases where the webdriver has a time to wait 10 seconds but at the 5 second the element was found then the webdriver will proceed.
Answer of your Question:
1) Suppose you have defined 10 seconds then driver waits for 10 maximum but at minimum it can wait for 0.001 seconds means in cases of implicit wait we have to give maximum limit for wait while minimum limit depends on the finding the element or getting the condition done.
2) While in explicit wait except some case webdriver has to wait for maximum limit.
So, as a answer your webdriver first will follow the implicit wait and then follow the explicit wait since browser behavior will be sequential like other programing languages due single thread usage.
Reference :
Selenium Explicit and Implicit wait

What is the difference between Thread.Sleep() and selenium.setSpeed("2000")?

What is the difference between Thread.Sleep() and selenium.setSpeed("2000")?
setSpeed : Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation). By default, there is no such delay, i.e., the delay is 0 milliseconds.
Thread.sleep : It causes the current thread to suspend execution for a specified period.
So the main difference between them is setSpeed sets a speed while will apply delay time before every selenium operation takes place. But one thread.sleep() will set up wait only for once. So, if we have 3 selenium operations written like below:
Opeartion 1
Opeartion 2
Opeartion 3
and we want to set a delay time 2000 for each of these, defining setSpeed() method once will accomplish the task something like below:
selenium.setSpeed("2000");
Opeartion 1
Opeartion 2
Opeartion 3
But if we use Thread.sleep(), it will be something like below:
Thread.sleep(2000);
Opeartion 1
Thread.sleep(2000);
Opeartion 2
Thread.sleep(2000);
Opeartion 3
Thread.sleep() will stop the current (java) thread for the specified amount of time. It's done only once.
Selenium.setSpeed() will stop the execution for the specified amount of time for every selenium command. It is useful for demonstration purpose (you will see thing moving in your browser) or if you are using a slow web application (there are better technique to handle slow applications but that's off topic.)