Testcafe Selector to identify element inside the specific component of DOM Structure - dom

How to convert the below Relative path to TestCafe Selector?
//a[contains(#name,'indent')]/parent::div//span[contains(text(),'Follow')]
If I try the above one, it recognizes specific DOM Component which contains multiple elements and one of those is 'Follow'.
how to achieve this using TestCafe Selectors.
I did not succeeded with the below one :
Selector('a').withAttribute('#name','indent').parent('div').child('span').contains('Follow')
Selector('a').withAttribute('#name','indent').parent('div').child('span').withText('Follow')

I checked your code and found a couple of possible causes, which can lead to the issue.
TestCafe Selectors do not have the contains method so the first example is incorrect.
Though I don't know your html structure, I can currently assume that there is no need to pass the # char in the attribute argument.
Thus your second example looks valid excepting the # char.
If this recommendation does not help, please provide us with a working example that shows the issue and create a separate bug report in the TestCafe repository using the following form

Related

Node.CloneNode() not a function -dom-to-image.js

I want to create a .png file of a HTML page in angularjs and download it. For this I'm currently using dom-to-image.js and using the domToImage.toBlob function and passing the node element to it. But internally when it goes to dom-to-image.js it throws the error:
node.cloneNode() is not a function
Can anyone please assist me here?
Thanks
This error arises when you attempt to call cloneNode() on anything other than a single DOM node.
In this case, the error is coming from the dom-to-image library, which calls that method internally.
Note that without a code snippet, its hard to identify the precise issue with your code, but the point is, when you call domtoimage.toBlob(), you need to supply a single DOM node.
So double check what you are calling it with. If you are selecting by class, for instance, you could end up with more than one element.
Its best practice to be precise with which node you want to convert to a blob - use the id attribute, like this:
domtoimage.toBlob(document.getElementById('element')).then(...)
where element is the id of your target node.
Its also possible you're selecting with angular.element() or even using jQuery directly.
In both cases, this returns an Object -- which you can't call cloneNode() on.
Also note the following from the Angular docs for angular.element():
Note: All element references in AngularJS are always wrapped with jQuery or jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.
Which means you would observe the same behavior in both cases, e.g. both of these:
domtoimage.toBlob($('#element')).then(...)
domtoimage.toBlob(angular.element('#element')).then(...)
would result in the error you see. You can index the Object before supplying it to domtoimage.toBlob(), perhaps like this:
domtoimage.toBlob($('#element')[0]).then(...)
domtoimage.toBlob(angular.element('#element')[0]).then(...)
and that would also work.
Also check out this post about "cloneNode is not a function".

Difference between protractor locators

I was going through the protractor guide here: https://github.com/angular/protractor/blob/master/docs/api.md#api-protractor
It says in order to locate a element, I could use
var temp = element(by.css("someclass"));
or alternatively
var temp1 = ptor.findElement(protractor.By.css('someclass'))
Which kind of locator is to be used when ? Could someone pls clarify
They are the same. element is the preferred syntax because it is shorter and because you can chain locators and use some fancy protractor features. Protractor extends the webdriver api and that is why you can use the same functions that you would use in plain webdriver.
For example, the following expressions are equivalent:
ptor.findElement(by.css('.foo')).getText()
element(by.css('.foo')).getText()
$('.foo').getText()
To look for multiple elements use:
ptor.findElements(by.css('.foo'))
element.all(by.css('.foo'))
$$('.foo')
There are many examples in the api.md document:
https://github.com/angular/protractor/blob/master/docs/api.md#elementfinderprototypeelement
The difference between ptor.findElement and element is that the first should be used pages without Angular while the second is used on pages with Angular. This is related to how protractor syncs with Angular. The first returns a WebDriver WebElement, the second returns a Protractor ElementFinder.
However to address your question directly, there is no difference between the locators returned by by.css and protractor.By.css.
The two are equivalent. The object referenced by the global by object is the same as the the object referenced by protractor.By.
From Protractor's runner.js:
global.by = global.By = protractor.By;
There are two versions of the API. The old version used protractor.By, whereas the new version uses by. You may often see the old style but if you are in doubt, you can use the new style and be sure nothing unexpected will happen.

i18n in Symfony Forms

Is there any way I can use the format_number_choice function inside of a actions file. In fact I need to use it for a Form error message.
'max_size' => 'File is too large (maximum is %max_size% bytes).',
In English it's simply "bytes", but in other languages the syntax changes after a certain value (for example if the number is greater than 20 it's: "20 of bytes").
I can use parenthesis, of course, but if the framework offers support for doing this specific thing, why not to use it?!
The way it's currently implemented in the 1.4 branch, you can define only one translation per message using il18n XML files.
What you could do is create a custom validator which inherits the current validator (sfValidatorFile in your example) and does the size checking in the doClean method before calling its parent's method.
I suggest you take a look at the source to see how it works : sfValidatorFile
The correct way to handle number ranges for translation is explained here in the Definitive Guide. I won't reproduce it here as the documentation itself is clear and concise. Note however that the string is not extracted automatically by the i18n-extract task, so you need to add it manually - again, the documentation explains this.
So yes, you can use the format_number_choice() function inside an action - you just need to load the helper inside the action like this:
sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');

Drupal - dynamic options for text_list field

I have a custom node type for which I want to have a field that uses a special combobox based on list_text. When one chooses the type list_text it is normally possible to enter a static list of selectable texts, however, I want this list to be dynamic, i.e. based on the results of a db_query. What is the best way to do this using Drupal 7?
A simple example for clarification: A node of this custom type X contains a field that points to another node, so whenever a node of type X is created I want a combobox that contains all other nodes.
(Best solution would be to only display the combobox during node creation, and no longer during edit. But I could also live with it if the combobox was shown during the edit as well.)
I have tried to customize options_select by defining my own data type and implementing hook_options_list accordingly. The combobox was displayed during creation with the correct values, however, I could not save it.. I have no idea what went wrong there, but on the first submit it would change to a different theme, and when I tried again I got an internal server error. Am I on the right track at all with defining a completely new data type for the field? there surely must be a simpler way?
You're right in that you don't need a new datatype. Here's a good tutorial on how to do this. It's not specifically for D7 but I didn't see much that wasn't still applicable. There may be a better way to do it in D7 specifically but I would love to know it too if so :)
The tutorial linked by allegroconmolto sent me on the right way. Thanks for that.
Here's the simpler way of doing it: tutorial
Basically, it is, as I assumed, a common problem and hence a simple solution for it was included in the webform module by now. It provides a hook_webform_select_options_info which can be used to register a callback method. The callback method is then called each time a corresponding option select of a webform is shown, so that you can easily fill it with the results of a dbquery or anything else. Works like a charm and takes next to no time to implement.

Extracting function call list from DOxygen XML Output

I posted a question on the DOxygen forums and also am posting it here for a better response.
I have a moderately sized C project of about 2,900 functions. I am using DOxygen 1.5.9 and it is successfully generating a call graph for the functions. Is there a way to extract this out for further analysis? A simple paired list would be sufficient, e.g.
Caller,Callee
FunctionX, FunctionY
...
I am comfortable with XSLT but I must say that the DOxygen XML output is complex. Has anyone done this before and can provide some guidance on how to parse the XML files?
Thanks in advance!
Based on what I see in the contrived example that I created,
Parse files with a name similar to ^_(.+)\d+(c|cpp|h|hpp)\.xml$, if my regex-foo is right.
Find all <memberdef kind="function">. It has a unique id attribute. I believe the XPath for this is //memberdef[#kind='function'].
Within that element, find all <references>.
For each of those tags, the refid attribute uniquely refers to the id attribute of the corresponding <memberdef> that is being called.
The text node within each <references> corresponds to the <name> of the corresponding <memberdef> that is being called.
This seems like a nice, straightforward way to express call graphs. You should have no trouble using XSLT or any other sane XML-parsing suite to get the desired results.