My Requirement: I want to capture screen video of tests while running selenium tests.
I am currently using Monte Media Library. But it capture all the actions that is taking place in screen. I want to capture only the test browsers.
Is there a way to do that?
Please help me.
Working solution, without using any extra libraries is to implement your own Recording functionality via TakesScreenshot interface. This is really helpful for HTML5 games automation. You still can run tests in parallel and record what happen per browser/test.
Simple use:
import static openqa.selenium.OutputType.*;
File screenshotFile = ((Screenshot)driver).getScreenshotAs(file);
String screenshotBase64 = ((Screenshot)driver).getScreenshotAs(base64);
The main Thread with the test will remain the same. In second Thread you run this snippet every 5 seconds (or as frequent you want and your machine can keep up) and store the frames in a Queue. So for example you need to keep only last 12 items (last minute). This data structure provides first in, first out (FIFO) operations for add, poll, and so on.
Apache Commons collections 4 has a CircularFifoQueue<> which is what you can use out of the box.
CircularFifoQueue is a first-in first-out queue with a fixed size that
replaces its oldest element if full.
Simple use:
import java.util.Queue;
import org.apache.commons.collections4.queue.CircularFifoQueue;
Queue<Integer> fifo = new CircularFifoQueue<Integer>(12);
fifo.add(1);
fifo.add(2);
fifo.add(3);
System.out.println(fifo);
// Observe the result:
// [2, 3]
Related
This code is part of my Scrapy spider:
# scraping data from page has been done before this line
publish_date_datetime_object = (datetime.strptime(publish_date, '%d.%m.%Y.')).date()
yesterday = (datetime.now() - timedelta(days=1)).date()
if publish_date_datetime_object > yesterday:
continue
if publish_date_datetime_object < yesterday:
raise scrapy.exceptions.CloseSpider('---STOP---DATE IS OLDER THAN YESTERDAY')
# after this is ItemLoader and yield
This is working fine.
My question is Scrapy spider best place to have this code/logic?
I do not know how to put implement it in another place.
Maybe it can be implemented in a pipeline, but AFAIK the pipeline is evaluated after the scraping has been done, so that means that I need to scrape all adds, even thous that I do not need.
A scale is 5 adds from yesterday versus 500 adds on the whole page.
I do not see any benefit in moving code to pipeline it that means processing(downloading and scraping) 500 adds if I only need 5 from it.
It is the right place if you need your spider to stop crawling after something indicates there's no more useful data to collect.
It is also the right way to do it, rising a CloseSpider exception with a verbose closing reason message.
A pipeline would be more suitable only if there were items to be collected after the threshold detected, but if they are ALL disposable this would be a waste of resources.
As we know, the android demo of tensorflow is multi-thread. So how can I change it to the single-thread mode?
There's no way to do this from Java right now. A value for intra-op parallelism is automatically picked in local_device.cc matching the number of cores detected on your device. If you just want to test, you could overwrite the value there.
Inter-op parallelism is currently always 1 on mobile -- only one op runs at a time.
More generally in native code intra and inter op parallism can be set when creating your Session object. e.g.:
tensorflow::SessionOptions options;
tensorflow::ConfigProto& config = options.config;
config.set_intra_op_parallelism_threads(num_threads);
Session session = tensorflow::NewSession(options);
This will override the automatically picked value. See benchmark_model.cc for an example.
If you want to set this from Java, you would have to add a parameter to TensorFlowInferenceInterface.initializeTensorFlow().
We're switching to the Java API soon, though, so it will be easier to access the SessionOptions to set the value then.
I'm writing a java tool which will create selenium scripts for end users. In case of frame switching, I cannot depend on end user to figure out the frame info. User can provide a locator value, but my tool needs to be able to figure out which frame it belongs to (it's hierarchy structure) and switch to the one before taking next action.
Is there any way I get my Selenium Web Driver to get that frame?
PS: I could hard code the workflow with frames known and do the switching.
One solution that I can think of is, check for presence of provided locator/element on current context (frame), if it throws NoSuchElementException exception, get all the available frames on the page - driver.findElements(By.tagName("iframe")) and in a loop try to switch to available frames based on WebElementdriver.switchTo().frame(<element>), now again check for the presence of provided locator/element. Once you found provided locator/element, break the loop and continue with further execution.
Worklight 6.1 on both Windows (colleague) and Mac (me), building an a Hybrid app destined for Android device but to speed up development we do initial testing as Mobile Web App in Chrome browser on desktop.
We get a weird symptom that I'm trying to fine-down to a reproducible test case. I think I see different behaviours when stepping in debugger and just letting it run. Want to check whether a certain coding pattern could be the cause of the symptom before I go any further.
Fundamental question: should we wait for the resolution of a promise returned by a JSONSTore request for an action on a collection before issuing another request? more explanation below.
The overall intent is to load some data into the JSONStore, with some intelligent replace/merge action if a record is already present. Pseudo code:
for each record retrieved from back-end
if ( record already present in Store )
do some data merging
replace record
else
add record
The application code actually works like this, just considering the add() case, the problem manifests when the store is empty, all records need to be added
for each record to add
addPromise = store.get().add(record);
listOfPromises.insert(addPromise);
examine the list of promises recording any errors
That is there is no "wait" for add to finish before issuing the next add request. Hence in effect we've initiated a set of adds "in parallel" whatever that might mean in JavaScript in Chrome.
The code appears to run just fine, no errors reported. On android device it works reliably. In Chrome under normal running (no stepping in debugger) we end up with no reported errors but only one record inserted - indeed as though a snapshot of the initial "empty" store had been taken and each add is working on that "empty" copy.
After writing this I'm now pretty convinced that the coding pattern described above is vulnerable to a kind of race and that the better approach is build a list of documents to be added and insert them in a single operation.
A more detailed answer will be coming later, but I now know that this
the coding pattern described above is vulnerable to a kind of race and
that the better approach is build a list of documents to be added and
insert them in a single operation.
is true. In the browser the JSONStore does require that we wait for the result of one request before issuing another one. The recommended approach is
var dataToAdd = buildArrayOfDataToAdd(responseFromServer);
var dataToReplace = buildArrayOfDataToReplace(responseFromServer);
jsonstore.add( dataToAdd ).then( function() { jsonstore.replace( dataToReplace); })
I have to make a firefox addon that searches the loaded page against a list of words (potentially 6500 words) and highlight matches and show synonyms on hover.
So i am using HightlightRegex.js that traverses the dom and searches based on a regex which is using the regex \bMyWord\b.
The main problem is when testing the addon on a page that has many occurrences of the search word, Firefox hangs for a while (5-6 sec) and then highlights are shown. This is happening for 1 word so one can just imagine what will happen if i search 6500 words.
So is there any way that i can run the pageMod in a background thread or asynchronously and highlight words as they are matched without freezing the UI?
You can have a look at the add-on at https://builder.addons.mozilla.org/addon/1042263/latest/
Currently the add-on is not tied to separate tabs and run as a whole on the browser but i doubt that would cause Firefox to hang.
I need to do this as efficiently as possible so suggestion are very welcome.
DOM is generally not thread-safe and you cannot access it from anything other than the main thread. The only solution would be breaking up the work into smaller chunks and using setTimeout(..., 0) to run next chunk asynchronously, without blocking everything.
One thing you could try is useing the page-worker module to load the page and process it:
https://addons.mozilla.org/en-US/developers/docs/sdk/1.6/packages/addon-kit/page-worker.html
And, as Wladimir suggested, only use asynchronous code to search the document text to avoid locking up firefox.
As canuckistani hinted, the better solution requires only two synced DOM operations: reading and writing. Rip the entire page (or, even better, only its <body>) and send it through to an async worker or thread which will perform the highlighting. When it's done, the worker emits an event and passes the highlighted content, which the addon can now insert back into the page.
That way, the only synchronous operations done are fast, inexpensive ones, while the rest is done asynchronously, away from the main thread. However, canuckistani suggested to load the page in a page-worker: there is no need to do that, as the page is already loaded in a tab. Just load up a fake page and insert the actual content.