I am trying to port CookXml to codenameone so I can use it to define UI in xml. CookXml depends on w3c dom and javax parser. I am looking for a way to replace the javax document builder class with the XMLParser in codenameone. I am stumped by the fact that even though XMLParser is supposed to be a close port I don't seem to be able to identify what to use to get attributes or the Attr node. Is the element in XMLParser the same as the Attr node? Or is it not just supported? How would I for instance be able to get names of attributes for an element?
XMLParser unified the concepts of Node, Document, Element etc. into a single Element class.
Attributes are simplified when compared to the DOM attributes.
To get the attributes you can just call:
Hashtable<String, String> h = (Hashtable<String, String>)elem.getAttributes();
Then to get all the attribute names/values:
for(String key : h.keySet()) {
String value = h.get(key);
....
}
Related
I'm using HP UFT for functional tests.
Because of dynamic id definition of ExtJS, I can't use UFT Recording feature.
I've tried many ways for assigning dynamic IDs to staticly.
I tried to change id: function() in ext-all-debug.js file.
I tried to change Components getId() function in ext-all-debug.js file.
I tried override components with afterRender method to change ids aswell.
Sometimes I achieved to change id's using component's properties (text, fieldLabel, overflowText, etc.), but for some components I couldn't achieve to assign ID's since the components properties seem empty.
Above, I listed my actions to assign static ID. So, I want to know your opinions about my actions and if you found them incorrect or not sufficient, could you offer me new approaches for using HP UFT recording feature with ExtJS6.
You can't change the dynamic id of the dom elements which represents ExtJS components. That's really bad thing and I think you would break the whole app.
The easiest way to test ExtJS app is to use already created frameworks/tools like:
Siesta by Bryntum
Sencha Test by Sencha
The Siesta is free. It has some pro features which requires the license. But you can use it for free.
If you still insists on doing it your way. You need to dynamically get the IDs of the dom elements created by ExtJS components. Basically write your own API.
You need to execute the ExtJS JS code, which will return you the ID of the component. So you need to get the ExtJS component and call getId() function on it to get the dom id.
Here is the example code:
>Ext.ComponentQuery.query('checkbox')[0].getId()
"checkbox-1047"
You will definetely need: http://docs.sencha.com/extjs/6.5.3/modern/Ext.ComponentQuery.html#method-query
And keep in mind that the query can be pretty advanced and you can use all the configs which are set on the ExtJS elements such as name, xtype, etc
You can find some other info in my other anwser https://stackoverflow.com/a/41718879/1768843
My model consisted of the following example:
class Aggregate {
private SomeClassWithFields property;
}
Now I decided to introduce inheritance to SomeClassWithFields. This results in:
class Aggregate {
private AbstractBaseClass property;
}
The collection already contains a lot of documents. These documents do not contain a _class property inside the DB since they were stored before the inheritance was present.
Is there a way to tell Spring Data MongoDB to use SomeClassWithFields as the default implementation of AbstractBaseClass if no _class property is present?
The other solution would be to add the _class to all the existing documents with a script but this would take some time since we have a lot of documents.
I solved it by using an AbstractMongoEventListener
The AbstractMongoEventListener has an onAfterLoad method which I used to set the default _class value if none was present :) This method is called before any mapping from the DBObject to my domain model by spring so it works then.
Do note that I also needed to let spring data mongodb know the mappingBasePackage in order for it to be able to read an Aggregate before writing one. This can be done implementing the getMappingBasePackage method of the PreconfiguredAbstractMongoConfiguration class.
I was wonder how can I reuse an elements while I'm using appium.
An elementSerarch returns an ID which is generated by Appium , I was wonder if there a way to reuse the same element by it's id ?
If not , then what is the purpose of the element's id ?
Thanks
You can create Page Object Model (POM) is the best way for element re-usability, but these reused elements do not essentially have the same Id on different pages so you might get.
NoSuchElement Exception.
by separating out the reusable components will make your work more manageable.
Using POM You can store the elements into the variables, and pass them wherever you want.
WebElement element = driver.findElement(By.id("xyz"));
Also Preferred selector order should be : id > name > css > xpath,
id and name are often the easiest and sure way.
xpath are often brittle, css are the way to go in conjunction of id and name !
But sometimes because of Page Refresh/Loading these elements might not be available on later use so prefered way is to create Page Class and write methods to find these elements, like
public class LoginPage extends BasePage {
public void loginButton_Click() {
WebElement element = driver.findElement(By.id("xyz")).click();
}
}
Here you can list out all the methods to find the different elements on particular page, Now you just need to call the method whenever you want to use that element.
As far as Finding element by using it's Id is concern if you are using a tool such as uiautomatorviewer you will get the Developer generated Id's so you can use the same Id as many times as you want,
also if you are talking about the Id's generated by Appium such as: info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"1"},"status":0}
Here id : 1 is internal reference for appium to act, for future actions that we call for respective element in the test code. I preferred to use driver to find the elements,
Id Of an Element
Ideally the element.getId() method can be used to return a String, representing the ID of an element, But whenever I tried to use, It always returns 1 to me, You can also use,
WebElement element = driver.findElements(By.xpath("XOXOXOXO"));
element.getAttribute("id");
Finally You need this Id to perform Click/Swipe/long click and many other events you want for your Automation Testing, basically the process is like:
Get the Id/name/xpath of an Element (By using different methods or
Tools like uiautomatorviewer)
Find that element By Name/Id/xpath etc.
Perform necessary operation
So Id is just one way to find the element, and you can reuse it by your own way.
I will use robotframework to test an application that use the sencha extjs library,
my problem is that with this library the ids are generated dynamically every time
this add new components, therefore my robotframework script would change
constantly but this is a bad idea. somebody said me that other testing frameworks
it have plugins to this task but I cant found in robotframework.
thanks in advance.
There are many ways to access elements on the page, using the id is just one way. Assuming you're using Selenium2Library, you can use any of the following locators strategies (from the Selenium2Library documentation):
Strategy Example Description
--------------- --------------------------------------- ---------------------------------
identifier Click Element | identifier=my_element Matches by #id or #name attribute
id Click Element | id=my_element Matches by #id attribute
name Click Element | name=my_element Matches by #name attribute
xpath Click Element | xpath=//div[#id='my_element'] Matches with arbitrary XPath expression
dom Click Element | dom=document.images[56] Matches with arbitrary DOM express
link Click Element | link=My Link Matches anchor elements by their link text
partial link Click Element | partial link=y Lin Matches anchor elements by their partial link text
css Click Element | css=div.my_class Matches by CSS selector
jquery Click Element | jquery=div.my_class Matches by jQuery/sizzle selector
sizzle Click Element | sizzle=div.my_class Matches by jQuery/sizzle selector
tag Click Element | tag=div Matches by HTML tag name
default* Click Link | default=page?a=b Matches key attributes with value after first '='
Note that even though some examples (such as xpath) show the use of an id, an id may not be strictly required (except, obviously, for id= and identifier=). xpath is usually the strategy-of-last-resort, because you can reference pretty much anything in the document. For more about xpath you can start here: http://en.wikipedia.org/wiki/XPath
This is not a great solution, so hopefully someone else can find a plugin or something that is easy to implement. However, if you do not find a different way, you can give every one of your Ext.js elements an ID manually by setting the "id" property on every one of your elements to a unique ID yourself. It would not take too much work, and if you named them something actually related to what they are, it would make the ID's more human readable.
From the Sencha docs:
id : String
The unique id of this component instance.
It should not be necessary to use this configuration except for singleton objects in your application. Components created with an id may be >accessed globally using Ext.getCmp.
Instead of using assigned ids, use the itemId config, and ComponentQuery which provides selector-based searching for Sencha Components analogous to DOM querying. The Container class contains shortcut methods to query its descendant Components by selector.
Note that this id will also be used as the element id for the containing HTML element that is rendered to the page for this component. This allows you to write id-based CSS rules to style the specific instance of this component uniquely, and also to select sub-elements using this component's id as the parent.
Source: http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.AbstractComponent-cfg-id
With the release of Selenium2Library 1.7, users are now able to create their own custom locators. You could use this to create a location scheme based on ext's component query. So long as the overall structure of the app doesn't change that much, that may suffice. For more information on custom locators see the Selenium2Library docs.
I've started an add-on library for S2L on github that you can check out for reference, but it isn't completely finished yet.
Also, Ext lets you place unique ids on components by simply specifying the id attribute. I would recommend applying ids to all elements which you want to interact with through your tests, thereby eliminating any need for complex behavior to automate the interface.
Developing my custom Drupal's theme. it will contain custom node.tpl.php file.
How can i get and print related taxonomy names of selected node?
Tnx in adv!
EDIT: Doh, my apologies, I'm just now seeing the Drupal 7 tag, specifically. It appears this thread has some possible solutions: http://drupal.org/node/909968
With D6 (not 100% about D7) In the node's template .php files (and similarly, in a view or most anywhere you have access to a node's properties with custom PHP, like a View or Block), you can use the following:
// returns array of taxonomy objects for given node
$tax_terms = taxonomy_node_get_terms($node);
// prints each term name
foreach ($tax_terms as $tax) {
print $tax->name;
}
Also, there's a few useful Drupal functions for cases like this:
// print_r's all properties of a given node, similar to devel
dpr($node);
// using this in the above 'for' look will give you all properties of each taxonomy object
dpr($tax);
Here's a website that lists a few more of these functions.