Android, Robotium - How to work with localized builds? - robotium

I'm using Robotium for some test automation for an Android application. It's great, but the maintenance is huge.
My application is localized into 20 languages, I'm compiling my application string resources into my test APK (that contains the logic for running my automated tests) and using the strings to find menu items etc. to click at run time. This is in line with an example I found on the Robotium project page on Google Code.
For example,
solo.clickOnText(res.getString(R.string.settings_menu));
The problem I'm having is that the strings may change daily in early builds of my product.
Is there any way I can use the string ID's as opposed to the actual strings in order to click on items? These would be unique across all languages, and I wouldn't have the high maintenance costs I currently have.
TIA.

You can use the resource ids of the views that you want to interact with. An example is:
Button button = (Button) solo.getView(R.id.x);
solo.clickOnView(button);

You should be able to use
String myLocalizedString = getActivity().getResources().getString(R.string.settings_menu);
solo.clickOnText(myLocalizedString);
No matter what you change your language to it should come up with the correct string. I am assuming you are using resource qualifiers.
res
values
strings.xml
values-fr
strings.xml

Use resource id from the test tested project(if you are testing APK only, import the R.java to your testing project).
Then use scripts like below:
View view = solo.getCurrentActivity().findViewById(R.id.resourceId);
solo.clickOnView(view);

Related

Bulk text2speech Generation with R

Is it possible to loop through a list of words in R that can each be generated into separate “speech” files using the speech2text website?
https://www.text2speech.org/
To make one file manually one has to type in the text one one page then submit it. A second page then opens with the option to download the file. Since I want to do many of these I would like to find a way to automate it. I have no idea how to approach this idea though.
EDIT
So I am using "say" on mac based on a the helpful comments. I am running it through R using a loop for all strings in a vector
for(i in 1:nrow(test[1:5])){
system("say", intern =F,input = test$English[i])%>%saveRDS(paste0("/Users/Desktop/tts/", test$English[i],".aiff"))
}
This creates the files as expected in the expected location but the .aiff files won't play in any media player. Does anyone see what I am doing wrong?
Consider using a CLI based solution for TTS, like espeak/espeak-ng (cross-platform), festival (linux), say (osx) or via powershell on windows (here's a script). Looks like the page you're referencing is using flite, which is a lightweight (and downloadable) version of festival.

Using Selenium IDE for a test-case which includes backend call?

I add a new category in the admin panel and want to ensure that the category is available in the dropdown on the user's part of the website. Recorded test in the Selenium IDE works fine. But the thing is, the task that I execute is of course not a pure frontend thing - the category is saved in the database and is loaded from it to show it to the user. So if something goes wrong on the database-side, the test will fail.
My question is: is it bad practice to do such tests that depend on backend-behavior ? Should I go for Selenium Webdriver ?
If you use Selenium Webdriver, your test will not change in a main thing. It still will check database side. Selenium Webdriver is just anouther tool for testing that is more flexible and allows to make more complex test then in Selenium IDE.
I don't think that it is bad practice, because it is just one of the tests that chould be executed to enshure you that this part of your project works correctly. In this case I would check back-end part(get all categories from DB or admin's panel and check that there is no extra or missing ones) and than check user's panel(all categories are the same as set in DB and admin's panel).

ID's Required for UI automation in selenium in all html pages

There is a project where we are going to automate the UI but the Automation team is suggesting that we have to use ID's all over the page so that it will be easy to automate there script.
My Question here is why we will use ID's everywhere ? hampering the Html and Css structure.
The webpage can be automated without ID's in html yes or no ?
Yes, a web page can be automated without ID's. For example, you can play with cssSelectors here https://www.w3schools.com/cssref/trysel.asp (note that example page has elements with and without ids)
Using ids for element's lookup in automation is generally considered as a best practice. If you use ids your automation tests will become independent of html structures which basically will make them more stable.
For example, in the first version of your app you may have some text implemented as
<p id="someTextId" class="someClass">Hello world</p>
but at some point may decide to rewrite it as (change the tag and even apply different class name)
<div id="someTextId" class="anotherClass">Hello world</div>
In case you rely on id #someTextId to locate an element your test will still be able to access necessary element and interact with it properly. If you use p or .someClass your automation test will fail to find an element even though from the ui perspective the same text will be displayed in a browser.
We faced several downsides of using id:
Some frameworks do not recommend using them or generate them automatically. (Potential issues with ids described here https://www.javascriptstuff.com/use-refs-not-ids/, https://www.quora.com/Are-IDs-a-big-no-no-in-the-CSS-world, https://dev.to/claireparker/reasons-not-to-use-ids-in-css-4ni4, https://www.creativebloq.com/css3/avoid-css-mistakes-10135080, https://www.reddit.com/r/webdev/comments/3ge2ma/why_some_people_dont_use_ids_at_all/)
Some other logic may rely on them, so changing/adding them for the need of automation may somehow affect other app logic unexpectedly.
What you can use instead of id is some other attribute. For example in our projects, we have switched from id to a specific attribute named dataSeleniumId. It clearly shows that the attribute is selenium tests usage only. As a next step, you can add a rule in your team when someone changes or removed dataSeleniumId attribute he should inform automation testing team about it. As changing/removing this attribute will lead to test failures and to avoid any false failures it is better to fix it in advance.
For an automation developer its much easier to browse trough the html code and see the id of specific button/text field/etc.. to implement the relevant locator inside the automated test.
In most cases, the project start to receive duplication of classes or complicated nested elements. This make the life of automation dev harder, because of writing xpath or css selectors, verify that they work and this locator finds only 1 unique element.
Its up to the team and code style suggested from the team leader.
Back on the question, yes the website can be written without id's but if the goals is to automate large part of the website, id's would be great helper to the automation dev team.

For Arabic Language Translation which is better way to take it and do

We developing Hybrid mobile application using Worklight 7.1 and Jquery mobile 1.4.5.
These Application supported right now two langues only i.e(Arabic and English).We are thinking two ways which way best to take to develop the application we don't no because of we are developing first time for the multi language.
1.Take it separate(English & Arabic) Html pages.
2.Taking one html and NSL budiles(en,ar).
We have few doubts, Assume let's we take it first option their lot of html pages are increasing and Css and functionality also increase. May be here file size will be going to increase or execution speed going to less or application performance is going to slow etc.
Let's take it second option we take it single html page and less functionality but we don't no how to align the positions for the Arabic language like tabular form data,default icons position and etc. May be here execution speed going to less or application performance is going to slow etc.
Please any one tell me which way is best and how to resolve the above issues.
If anybody have sample application for multi langue worklight application using NSL buddile please provide US it will so help.
MobileFirst Platform Foundation 7.1 provides a translation mechanism where you can set system strings in different languages as well as applicative strings.
You can find the messages.js file, which is intended for application strings, in the common\js folder.
Messages = {
headerText: "Default header",
actionsLabel: "Default action label",
sampleText: "Default sample text",
};
Application messages that are stored in the messages.js file can be referenced in two ways:
As a JavaScript object property. For example: Messages.headerText
As an ID of an HTML element with class="translate": <h1 id="headerText" class="translate"></h1>
For system strings, you can find these here: You can find a full list of system messages in the www\default\worklight\messages\messages.json
To update a string, for example: You can find a full list of system messages in the www\default\worklight\messages\messages.json
You can find additional information in this tutorial: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/7.1/advanced-client-side-development/enabling-translation/

Need your ideas to automate

In my project we have a web based tool where it collects all the exceptions that occur in log. The list of exceptions will be displayed in table and a icon will be displayed in a column to get the stack trace. Some one needs to check all those exceptions and we need to assign to different teams based on the keywords.
Eg : If the stacktrace contains "DB Connection error" it has to be assigned to DB team, if it contains code error like "classcast exception" in particular file then it has to be assigned to individual owning the module. Currently some one has to open each n every row in the table displayed and open the stack trace and do Ctrl + F and if any of those keywords are found assign it to respective team.
We don't have any access to the tool's database and it's web based. I need some good ideas to automate it. Please suggest me with which technology and idea to automate it.
Sounds like selenium + programming language of your choice is a good fit (even without a selenium).
You need to:
download source code of the page containing exceptions table.
Use any of these: wget, curl, selenium, urllib for python, etc.
put it into variable and extract exceptions list in convenient to you format.
Use any xpath-powered tool, like selenium, lxml for python, etc.
do your thing with the extracted exceptions list: search for keywords, assign tickets, etc.
Use programming language of your choice.
Definitely you can achieve this using selenium.
Following are the steps to follow.
Supply date criteria with type command to the boxes text boxes element.
click search button.
store the required text in variable using storeValue(locator, variableName).
click on image link if you are able to keep track of popup window else you have to use
$second=$sel->getAttribute("//html/body/.../a#href"); and now your $second has link address $sel->openWindow($second,"MyWindow2"); now select that new window $sel->selectWindow("MyWindow2"); and do operation of storing required data from the popup.
Now agian for selection of previous window use `$sel->selectWindow("null"); // hear $sel is object of selenium (i.e. $this).
Select your required option using select(selectLocator, optionLocator).
Use selenium RC for above steps so that you have more manipulation with the data stored and as per requirement operations.
In above steps syntax are of PHPUnit.
Please try the steps may help you.
Regards.