robotframework with sencha extjs - extjs

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.

Related

selecting dynamic class names generated by react from a user script?

I tend to write my own user scripts (aka Violentmonkey / Tampermonkey scripts; formerly Greasemonkey scripts). I often end up selecting elements by class name while doing so - either using native javascript or having the script load jQuery and using that.
I've noticed that sometimes I see dynamically generated class names like "SeriesIndexFooter-footer-3WmRg" with the bolded bits appearing to be some randomly generated part (I think this gets generated by React? I haven't used React myself but have sometimes seen "React" in other element names when encountering these). Obviously, I can just hard-code these classnames in my script AS-IS and it will work... but my concern is that if a site / local server app gets updated later that this will break my user script.
e.g.
// #run-at document-end
var footer = document.querySelectorAll('.SeriesIndexFooter-footer-3WmRg');
//OR
// #run-at document-end
// #require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
var footer = jQuery('.SeriesIndexFooter-footer-3WmRg');
Is there a better solution that doesn't rely on hard-coding or avoiding class names entirely but also reduces the risk that my script will break because the random portion of the class name changes?
There is no way you can predict class suffix that you are talking about.
That is used for purpose of encapsulating styles so that it applies only for that specific element or group of elements.
What you can do in your case is to use few CSS selectors that relay on searching values in attributes.
In your case it would look something like this:
document.querySelectorAll('[class*=SeriesIndexFooter-footer]')
If you need to be more specific you can chain selectors. For example you can target a type of element div. There is no limit in chaining selectors to be more precise in selecting what you need.
document.querySelectorAll('div[class*=SeriesIndexFooter-footer]')
With this line you will select all elements where class attribute has a sub-string "SeriesIndexFooter-footer" and is div.
Here is W3Schools doc for that
You can find more selectors that suite your cases on W3Schools doc here
Other word searching CSS selectors that you can use are:
[attribute=value] [target=_blank] Selects all elements with target="_blank"
[attribute~=value] [title~=flower] Selects all elements with a title attribute containing the word "flower"
[attribute|=value] [lang|=en] Selects all elements with a lang attribute value equal to "en" or starting with "en-"
[attribute^=value] a[href^="https"] Selects every <a> element whose href attribute value begins with "https"
[attribute$=value] a[href$=".pdf"] Selects every <a> element whose href attribute value ends with ".pdf"
[attribute*=value] a[href*="w3schools"] Selects every <a> element whose href attribute value contains the substring "w3schools"

How to reuse elements while using appium

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.

Overview page of elements from a Typo3 page tree

I'm primarily a UI and graphic designer and, eventhough I have some experience with Typo3, I'm completely stuck at the following problem:
I have a large page tree with single pages for items from a catalogue (one item per page), the layouts for these items are built with Armin Vieweg's beautiful "Dynamic Content Elements" extension (DCE).
Now I want to create an overview page where I reference some of those items automatically - ideally I want to check a box in each element I want to display there (I would add a field catalogueItemPreview to the item DCE which authors can check or uncheck).
Unfortunately, I have no concrete idea of how the database is structured and how I could build a query (where would I even do that? in a custom-made plugin?).
This is how I imagine it could work: On the overview page I use a plugin/an extension in a Content Element that does the following:
search Typo3 DB for content elements with a field called "catalogueItemPreview"
return fields "catalogueItemTitle", "catalogueItemShortDescription", "cataloguePreviewImage"
use a template to render previews of all those elements on the overview page
I'm happy for ANY pointers towards a solution as currently I'm completely in the dark about where even to begin ...
Schematic screenshot from the Typo3 backend
thanks for using my DCE extension :)
Well the fields you have defined and their values in content elements are stored as XML, because the current version of DCE is based on Flexforms.
This makes it very very difficult to do MySQL queries using one of the field properties in WHERE clause. You could check for a xml string in the field pi_flexform but this is not recommended.
Instead I would use another property of content elements (tt_content) to mark the items as "Show on frontpage". For example you could create a new layout or section_frame value for that. Then it is very easy to just output the elements you want, using TypoScript.

Why using the this.$(selector).method() syntax with backbone?

I have seen this bunch of code in a tutorial:
var searchTerm = this.$('#searchTerm').val().trim();
I would like to understand the utility of the this. in front of the selector, it's the first time i see that.
In a Backbone.View, this.$ gives a scoped version of jQuery. It is in fact equivalent to using this.$el.find which is in turn equivalent to using $(this.el).find.
Anyhow, the reason it is a good idea to use it is that it will only access html elements from within the view's element/rendered template. Thus, you don't have to worry about the rest of the html page and you will always select the element you expect to.
Imagine that you have a view that spawns sub-views and that each of these have an editable field. If you don't use the scoped version of jQuery to get the right editable field, you will have to give a unique id to each of these html elements to make sure you will select the right one when retrieving it's content. On the other hand, if you use the scoped version, you will just have to give this editable field a class attribute and selecting this class will give you a unique element, the right one.
This is the same query as this.$el.find('#searchTerm').val().trim();
You haven't given any context to that code, but assuming it's a method inside a View, this refers to the View object.
this.$ is a shortcut to access jQuery from the View object, and is equivalent to the method this.$el.find.

Drupal 7 - How to create a contextual filter based on an aliased url

CASE:
I've created a content type 'Attorney', and have set a url alias pattern for all attorneys to be 'attorneys/[node:title]'. I'd like to create a view that uses the aliased path to display the information about the attorney. This view should have a 'page' display.
EXAMPLE:
When a user visits 'http://mydomain.com/attorneys/aaron-silber' the view returns data for the Attorney with the name Aaron Silber.
BACKGROUND:
I've searched high and low for a solution to this but can't seem to find one that works for me. Typically I'm asked to create a page view with a url of 'attorneys/%' and add a contextual filter with 'Content: Nid', choosing to provide a default value (type: Raw value from URL, path component 2).
The resources on the web for this case are aweful at best. Lets try to fix it here once and for all.
Thanks!
Use a Views block instead with the visibility set to "Only the listed pages" and supply "attorneys/*" in the textarea. Set the block to display in the main content region. Use the Content: Nid filter with a default value of path component 2, as you were previously attempting.
You can't have an attorney node page and a Views page occupying the same URL.

Resources