Speeding up mouse with Selenium WebDriver - selenium

I've inherited some Selenium Webdriver code (Ubuntu 11.10, Xvfb + Selenium 2.19.0 & Firefox 10.0.2, because that's the only combination I've been able to hit upon in the time available that actually installs.)
Note: I am not using the old Selenium 1.0 system, which most documentation seems to be focussed at.
My tests are running very slowly. Simple mouse movements are taking over half a second.
Looking at the (undocumented?!) /tmp/native_ff_events_log file, I find that each mouse operation is being divided up into smaller parts:
D14:14:37:070 cpp/webdriver-interactions/interactions_linux_mouse.cpp(307) ---------- starting mouseMoveTo: 0x7fbad37546a0---------
D14:14:37:070 cpp/webdriver-interactions/interactions_linux_mouse.cpp(328) From: (39, 169) to: (350, 86)
D14:14:37:070 cpp/webdriver-interactions/interactions_linux_mouse.cpp(329) Distance: 321 steps: 64
D14:14:37:070 cpp/webdriver-interactions/interactions_linux_mouse.cpp(339) Moving to: (39, 169)
D14:14:37:070 cpp/webdriver-interactions/interactions_linux_mouse.cpp(231) Type: motion time: 401697248
D14:14:37:080 cpp/webdriver-interactions/interactions_linux_mouse.cpp(339) Moving to: (43, 167)
D14:14:37:080 cpp/webdriver-interactions/interactions_linux_mouse.cpp(231) Type: motion time: 401697258
D14:14:37:090 cpp/webdriver-interactions/interactions_linux_mouse.cpp(339) Moving to: (48, 166)
D14:14:37:090 cpp/webdriver-interactions/interactions_linux_mouse.cpp(231) Type: motion time: 401697268
D14:14:37:100 cpp/webdriver-interactions/interactions_linux_mouse.cpp(339) Moving to: (53, 165)
D14:14:37:100 cpp/webdriver-interactions/interactions_linux_mouse.cpp(231) Type: motion time: 401697278
D14:14:37:110 cpp/webdriver-interactions/interactions_linux_mouse.cpp(339) Moving to: (58, 163)
It appears like there is some deliberate slowing down, similar to the legacy Selenium's setMouseSpeed(pixels), which breaks up drag-and-drop operations into 10 pixel submovements.
I'm not using drag-and-drop. Also, I believe this method is no longer available to me.
I do not believe these submovements are necessary, and removing them might speed the run considerably.
Is there a way to increase the size of the mouse steps in Selenium 2's Webdriver?

Oddthinking, looking at source code I found two values that make mouseMoveTo() so slowly:
const int stepSizeInPixels = 5;
http://code.google.com/p/selenium/source/browse/trunk/cpp/webdriver-interactions/interactions_linux_mouse.cpp?r=13310#278
const int timePerEvent = 10 /* ms */;
http://code.google.com/p/selenium/source/browse/trunk/cpp/webdriver-interactions/interactions_linux_mouse.cpp?r=13310#270
Unfortunately, there is no way to change this values on runtime level, because are hardcoded.
When mouse needs to move from Point A to Point B, it does using a 5 pixel step with 10ms interval. One step from my testcase was taking about 1.2 seconds to do a simple click()
I recompiled the firefox extension changing stepSizeInPixels to 50 and timePerEvent to 5ms. Now my testcase is taking 18 seconds, 8 seconds less that original extension.

Related

Karate - Multi threaded access requested - issue

I have 100+ tests being covered in 25+ feature files and I have the karate-config.js which has 3 "karate.callSingle" functions as below.
config.weatherParams = karate.callSingle(
"file:src/test/java/utils/AvailableForecasts.feature",
config
);
config.routingParams = karate.callSingle(
"file:src/test/java/utils/CalculationInput.feature",
config
);
config.vesselParams = karate.callSingle(
"file:src/test/java/utils/VesselStatus.feature",
config
);
Same issue when I use classpath inside callSingle.
When I run all the tests at once with parallel (tried randomly 1-100 threads) enabled, I get the following error:
org.graalvm.polyglot.PolyglotException: Multi threaded access requested by thread Thread[pool-2-thread-8,5,main] but is not allowed for language(s) js.
- com.oracle.truffle.polyglot.PolyglotEngineException.illegalState(PolyglotEngineException.java:132)
- com.oracle.truffle.polyglot.PolyglotContextImpl.throwDeniedThreadAccess(PolyglotContextImpl.java:727)
- com.oracle.truffle.polyglot.PolyglotContextImpl.checkAllThreadAccesses(PolyglotContextImpl.java:627)
- com.oracle.truffle.polyglot.PolyglotContextImpl.enterThreadChanged(PolyglotContextImpl.java:526)
- com.oracle.truffle.polyglot.PolyglotEngineImpl.enter(PolyglotEngineImpl.java:1857)
- com.oracle.truffle.polyglot.HostToGuestRootNode.execute(HostToGuestRootNode.java:104)
- com.oracle.truffle.polyglot.PolyglotMap.entrySet(PolyglotMap.java:119)
After playing around with multiple combinations- surprisingly, when I have only 2 "callSingle" functions in karate.config (commenting VesselStatus.feature) then it works fine.
All these 3 "callSingle" things calling 3 different services and sets the variable for other tests to run, so these 3 are critical.
Is there a way, we can re-optimize / bring a different approach to avoid the above issue?
This is a known issue that should be fixed in 1.1.0.RC2
Details here: https://github.com/intuit/karate/issues/1558
Would be good if you can confirm.
I faced this issue in my karate implementation #peter-thomas. I just got an easy workaround for this issue since we know that graalVM js engine doesnt support multithreading of karate-config.js
work around is - we can wait for a certain milliseconds and that milliseconds has to be genrated randomly.
below code inside karate-config.js have a look please -
function fn(){
// karate-config essential coding
var random_millis = Math.floor(Math.random() * 5000 - 1000 +1 )) + 1000;
java.lang.Thread.sleep(random_millis);
return something;
}
with above piece of code i tried my 100+ feature files running with 20 parrellal threads with karate 1.2.0.RC1 and it worked fantastically fine.
How its working - all the 20 threads will jump altogether , reaching karate-config at the same time. but if we apply some delay that too random between 1 to 5 seconds (in millis) , all threads will wait for different time avoiding multithreading issue.
I also know that between 1 to 5000 millisends , still there are suppose 1% chances that we get same numbers but till we get concrete solution of this issue i guess we can use this workaround.
Thanks,
Saurabh

Catchpoint pause vs. waitForNoRequest - What's the difference?

I have a test that was alerting because it was taking extra time for an asset to load. We changed from waitForNoRequest to a pause (at Catchpoint's suggestion). That did not seem to have the expected effect of waiting for things to load. We increased the pause from 3000 to 12000 and that helped to allow the page to load and stop the alert. We noticed some more alerts, so I tried to increase the pause to something like 45000 and it would not allow me to pause for that long.
So the main question here is - what functionality does both of these different features provide? What do I gain by pausing instead of waiting, if anything?
Here's the test, data changed to protect company specific info. Step 3 is where we had some failures and we switched between pause and wait.
// Step - 1
open("https://website.com/")
waitForNoRequest("2000")
click("//*[#id=\"userid\"]")
type("//*[#id=\"userid\"]", "${username}")
setStepName("Step1-Login-")
// Step - 2
clickMouseAndWait("//*[#id=\"continue\"]")
waitForVisible("//*[#id=\"challenge-password\"]")
click("//*[#id=\"challenge-password\"]")
type("//*[#id=\"challenge-password\"]", "${password}")
setStepName("Step2-Login-creds")
// Step - 3
clickMouseAndWait("//*[#id=\"signIn\"]")
setStepName("Step3-dashboard")
waitForTitle("Dashboard")
waitForNoRequest("3000")
click("//*[#id=\"account-header-wrapper\"]")
waitForVisible("//*[#id=\"logout-link\"]")
click("//*[#id=\"logout-link\"]")
// Step - 4
clickAndWait("//*[text()=\"Sign Out\"]")
waitForTitle("Login - ")
verifyTextPresent("You have been logged out.")
setStepName("Step5-Logout")
Rachana here, I’m a member of the Technical Service Team here at Catchpoint, I’ll be happy to answer your questions.
Please find the differences below between waitForNoRequest and Pause commands:
Pause
Purpose: This command pauses the script execution for a specified amount of time, whether there are HTTP/s requests downloading or not. Time value is provided in milliseconds, it can range between 100 to 30,000 ms.
Explanation: This command is used when the agent needs to wait for a set amount of time and this is not impacted by the way the requests are loaded before proceeding to the next step or command. Only a parameter is required for this action.
WaitForNoRequest
Purpose: This commands waits for a specified amount of time, when there was no HTTP/s requests downloading. The wait time parameter can range between 1,000 to 5,000 ms.
Explanation: The only parameter for this action is a wait time. The agent will wait for that specified amount of time before moving onto the next step/command. Which will, in return, allow necessary requests more time to load after document complete.
For instance when you add waitforNoRequest(5000), initially agent waits 5000 ms after doc complete for any network activity. During that period if there is any network activity, then the agent waits another 5000 ms for the next network activity to end and the process goes on until no other request loads within the specified timeframe(5000 ms).
A pause command with 12000 ms, gives exactly 12 seconds to load the page. After 12 seconds the script execution will continue to next command no matter the page is loaded or not.
Since waitForNoRequest has a max time value of 5000 ms, you can tell the agent to wait for a gap of 5 seconds when there is no network activity. In this case, the page did not have any network activity for 3 seconds and hence proceeded to the next action. The page was not loaded completely and the script failed.
I tried to increase the pause to something like 45000 and it would not allow me to pause for that long.
We allow a maximum of 30 seconds pause time hence 45 seconds will not work.
Please reach out to our support team and we’ll be glad to connect you with our scripting SMEs and help you with any scripting needs you might have.

frame rendering time measurement anomaly

I draw 2d content on GlSurfaceView using VBO/IBO with following function:
override fun onDrawFrame(gl: GL10?) {
val renderTime= measureTimeMillis {
GLES20.glClearColor(bgComps[0], bgComps[1], bgComps[2], 1f)
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT or GLES20.GL_COLOR_BUFFER_BIT)
bindAttributes()
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo)
//draw half of the polygons
val pieces = GameDataLoader.GameData.piecesByDiff(gameData.diff)
piecesProgram!!.setUniforms(projMatrix,imageTextureId,maskTextureId,PointF(4f,4f),0f)
GLES20.glDrawElements(
GLES20.GL_TRIANGLE_STRIP,
pieces * MeshBuilder.INDICES_PER_PIECE,
GLES20.GL_UNSIGNED_SHORT,
0
)
//draw another half
piecesProgram!!.setUniforms(projMatrix,imageTextureId,maskTextureId,PointF(10f,10f),sin(frame.toFloat() / 60 * 2 * PI).toFloat())
GLES20.glDrawElements(
GLES20.GL_TRIANGLE_STRIP,
pieces * MeshBuilder.INDICES_PER_PIECE,
GLES20.GL_UNSIGNED_SHORT,
pieces * MeshBuilder.INDICES_PER_PIECE * MeshBuilder.BYTES_PER_SHORT
)
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0)
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0)
}
val newFrameTS=System.currentTimeMillis()
if (lastFrameTS!=-1L)
println("frame time:${newFrameTS - lastFrameTS},render time:$renderTime")
lastFrameTS=newFrameTS
frame++
}
There are about 5.6K polygons on the screen.When I run this code I see in the console frame time: ~33ms,render time: 0-2ms(!).In most cases render time=0.If I comment everything except glClearColor and glClear render time jumps to 30ms.How can it be that the short code executes faster than long one?
UPD:The question relates to android OS.I observe such behavior on both emulator and real device.
The question is not why onDrawFrame call occurs too often or too seldom(in fact time between 2 last onDraw calls is measured ok.The question is how can I measure time for opengl calls within onDrawFrame function?How can these calls take 0ms?
This is usually caused by V-sync. The driver waits at the end of every frame until the next image can be presented on the monitor and delays execution of your program.
Depending on your hardware, you can force enable/disable this. Most PC hardware allows the application to choose if it wants to wait. On others, especially on mobile devices, you cannot.

Selenium + Chrome Driver drag and drop not working properly

I am using Selenium 3.14 and ChromeDriver 2.42 with Chrome 69.0. I was always using this code to drag and drop, which worked until recently, when tests started failing:
$driver->action()->clickAndHold()->moveByOffset(100, 0)->release()->perform();
After some Chrome update, it just stopped dragging. I also tried dragAndDropBy() function, with no luck. (dragAndDrop() is not an option because I need to move inside one element).
After hours of experimenting I was able to narrow the issue down to this weird thing, when using moveByOffset with bigger number, like 100 in my example fails, it just weirdly bounces in place. But when I tried to move it only by couple of px, it worked.
This is the code I ended up with:
$driver->action()->clickAndHold()->perform();
for($i = 0; $i < 10; $i++){
//moving this 10 times by 10 px instead of once by 100px
$driver->action()->moveByOffset(10, 0)->perform();
}
sleep(1);
$driver->action()->release()->perform();
I just want to share this, if somebody encountered similar issue.

LabVIEW driver - Bertan 225 - HV won't turn on

I'm trying to use the Bertan 225 driver. However, using the driver I cannot turn on the voltage (it does not produce any errors and the code it puts out seems to match the user manual).
Does anyone have any experience with this? Or any ideas?
I can put the codes in
L00.500K
L1.0000M
OC1OE1OE2
SE1SC1
P0.05000K
And I can turn the instrument to local and it goes to 50 V (0.05 kV). Then I can put in
L00.500K
L1.0000M
OC1OE1OE2
SE1SC1
P0.10000K
And I can turn the instrument to local and it goes to 100 V (0.1 kV).