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.)
Related
I'm using google mock as a framework for testing a real time system, I want to verify that the configuration to the sensors is being implemented correctly. To do that I am sending a new Frequency to said sensor and expecting my sensor data callback to be called x number of times.
Due to this I have to sleep the testing thread for a few seconds, so my callback can be called a few times.
Due to this the expected calls are not a set number, for example, if I expect my callback to be called once per second and I sleep the thread 5 seconds, it can actually be called between 4 and 6 times, otherwise the test would be too restrictive.
This is the problem, I haven't found a way to test if expect call is between 4 and 6, I tried the following:
EXPECT_CALL(*handler,Data_Mock(_,_)).Times(::testing::AnyNumber());
EXPECT_CALL(*handler,Data_Mock(_,_)).Times(::testing::AtMost(6));
EXPECT_CALL(*handler,Data_Mock(_,_)).Times(::testing::AtLeast(4));
And
EXPECT_CALL(*handler,Data_Mock(_,_)).Times(::testing::AnyNumber());
EXPECT_CALL(*handler,Data_Mock(_,_)).Times(::testing::AtLeast(4));
EXPECT_CALL(*handler,Data_Mock(_,_)).Times(::testing::AtMost(6));
Try Between from https://github.com/google/googletest/blob/master/googlemock/docs/cheat_sheet.md#cardinalities-cardinalitylist. It is exactly for the purpose of asserting that given call be called between m and n times.
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.
I am trying to run a function every 2 milliseconds but setting a timer to 2 milliseconds its not working it looks like it works every 50 milliseconds or so.. and when I try to use a While loop with Date.UtcNow.Ticks to compare 2 milliseconds then the CPU goes high. What options do I have here?
Depending on OS and Hardware configuration, system will allocate time slot to each process/thread,
You can try with on threading which will run full time and put statement thread.sleep(2); for delay and then run your code again in infinite while loop.
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.
i have a function it will take 3 to 30 secs time for execution depends on some calculations.
i want to stop if my function call takes more than 5 secs.
how to do this in Objective C.
You have to execute command in a separate thread (with performSelectorInBackground or with NSThread, for example), wait for 5 seconds (again, with unix sleep or NSThread methods) and then (depending on what is being done in the execution thread):
set some field in a class to "terminate", and check this field often in a "long" function
cancel IO operation, if there is a block
cancel a thread (you can read about it here: how to stop nsthread)
You can use a timer and put a condition like if the timer exceeds 5 seconds, do nothing.