Automation Testing with Ranorex - php

I am testing my PHP web application using the Ranorex automation tool. Whenever I record my test case, it is recording perfectly but when I play my test case it stops (sometimes it hangs) at the middle and fails my test case.
What is the reason that is creating this issue?

The good way to automate is to write code without using recorder.
There are some reasons of it:
recording unnecessary steps
saving elements to repository by wrong
attribute. As usual there are automation id and regex of text or
caption of element. For dynamically changeable elements this doesn't
fit.
different types of elements requires different types of methods
to wait and validate them.
In this way, I recommend you to watch the screencast of Ranorex Team.
There are 5 videos about everything you should know about UI Mapping.
According to you exceptions and errors in comments:
"...ATagPrintReport3' does not match the specified value (actual='False', expected='True')"
It means that Ranorex recorded element ATagPrintReport3 with value of some bool attribute. Of cource, the value of element will change, so the right way is to identify element with the attribute that will never change (uniqueId, name, class and other).
Failed to find item 'updtaed_cpt_imsRepository.OpeningInventoryStockValueJpg.ButtonOK'. No element found for path '/form[#title~'^Opening\ Inventory\ Stock\ V']/button[#accessiblename='OK']' within 1m.
This error can be the result of very fast dynamically changeable element, the wrong path of element, it could be presented in dom but could not be visible.
The best way to know what's wrong is to use breakpoints and step-to-step debuging.
In my opinion the path for ButtonOK will be better if it looks like:
'/form[#title~'Opening\ Inventory\ Stock']/button[#name='OK']'
No element found for path '/form[#title='Reading Untagged Document']/?/?/button[#text='&Cancel']' within 1m.
It is the same to p.2
In this example, the path will be better:
'/form[#title='Reading Untagged Document']//button[#name='&Cancel']'

I am sure there is a error message in the report.
What does this message say?
I suggest checking if the elements can be recognized uniquely by Ranorex and if the webpage is fully loaded.
You can use the following code snippet in order to wait until the webpage is fully loaded.
WebDocument webDocument = "/dom[#caption='Your Test Page']";
webDocument.WaitForDocumentLoaded();
Concerning your second question, a video how to work with data connector can be found on the Ranorex website directly:
Data-Driven Test Automation with Ranorex

Related

Bring result of PHP-Script to accepted field in TYPO3 FORM

So, it's my first question here - i found a lot of hints which all working for itself but im struggling now with the final step to get solved.
Guess it's very specific pointed to TYPO3-CMS V9 and higher.
I can also support with all of the Codes, for the moment i guess this will be better on request.
Task: Create a simple Productorderform for logged-in-users pointing just there specific products form the specific price-lists. -> solved by using PHP-Script working with a CSV-File, grabbing also some functions from TYPO3 itself to get needed parameters.
This PHP creates a DATALIST on runtime for the INPUT-Field producing the needed HTML-Code -> solved and working as expected.
Tricky part.
As TYPO3 offers a CORE-Extension called FORM and the Option to - REPEAT - the fieldset.
Also for TYPO3 there is an extension which allows to put PHP-Code directly to TYPO3 as a Content-Element.
FORM itself allows to put Content-Element to a form.
Working so far, but as described, the field (its value) is not recognized when i fire the send button.
So for some reason i have to predefine the trigger also.
I tried step for step to extend the predefined field in the php with the tags of an empty one, all(?) the surrouding DIV etc. to make FORM recognize this field as a "native" field, just extend in the main tag with ... list="prodlist" ...
Well, as you might see, i'm not a developer or programmer, i might have some skills and experiences to know where and how to go with the level (and timeframe) i have.
So i guess the final step might not be that far, but as we say here, i can't see wood because of trees...
The FORM structure by the way is saved to a YAML-file which might be also manipulated, but as i have seen, it gets the triggers -what- to parse in some way from the FORM created.
Many thanks for hints, ideas an hopefully noone was falling to sleep reading this question... ;)

Value of a href in php does not add up [duplicate]

I recently saw a html page, that i thought the id of several html tags was the same, then I realized the ids are unique but it raises the question that what could have happened if the page actually used several tags
As i have heard id attribute of every html tag(if it has one) must be unique,
now i wonder what happens if it is not the case??
what possible errors can it cause?
does different browsers show different reactions for this issue?
does javascript and jquery codes that use duplicated ids run on both tags or what?
Duplicate ids can have various different effects. Which you experience will depend on the method you use to try to access them (and possibly also from browser to browser).
You'll affect all of them
You'll affect the first one
You'll affect the last one
You'll get a collection instead of an element, try to treat it like an element and get an error
Duplicate ids are not allowed in HTML. Don't make trouble for yourself. Use classes for groups and ids for unique identifiers.
Change them as soon as possible, to save a lot of headache in the future. For elements with same property use classes
About your queries,
Now i wonder what happens if it is not the case??
Well, the HTML is not a valid one anymore. Now a days it doesn't hurt much but still not preferred.
What possible errors can it cause?
Errors are little bit hard to predict. But with jQuery you are going to get many.
Does different browsers show different reactions for this issue?
Not sure.
Does javascript and jquery codes that use duplicated ids run on both tags or what?
jQuery will give you trouble. Consider a case where you have two input fields with same ID.
and you try to select second one with out noticing. jQuery('yourID').val() and you'll be selecting the firs value instead. Like this there are a lot of possibilities.
As you said, HTML id, per specs, must be unique. If one where to put duplicated id, the js behavior relative to those ids will be unpredicatable, and could even change between 2 calls.
Any js call on one id (jquery or not) will point to one of the id but without guarentee that :
It will be the same every call
It will have the same order between 2 page refresh
It will have the same behavior beween 2 different browser
It will have the same behavior betwween 2 time the same browser
The problems that could emerge depend on how toghtly the js code is coupled to the underlying element DOM structure anw could mostly point to a undefined exception and stop the js execution.

Convert xml to MAP in php using simplexml, NOT json

I'm trying to figure out how to take a simple custom xml file (its actually an EML file, but simpeXML works with it anyway) and take tagnames and the text that follows (i think simpleXML calls them children) and put them into a MAP, with key/value pairs. I've looked at some examples on this site and others about converting to arrays and such but they all seem extremely complicated for my needs. I should note that my custom xml does not contain ANY attributes and this conversion only needs to work with MY custom xml file and not any others ever.
So a simple example of my eml file is here
<lesson>
<unit>4</unit>
</lesson>
So then basically what I would want is a MAP, or whatever a key/value collection is called in php that would give me:
Map[0](lesson,null)
Map[1](unit,4)
It's important that I get the null values (or an empty string is ok too), so I can verify that the eml file is valid. I need to validate it with php, not using a namespace validator or a dtd file or however that is done. So the first key/value pair, or the root tag, HAS to be lesson, and then ill also verify that there is a unit tag, then a title tag, then at least one other type of tag etc...I can do that easy if i can get everything into a key/value collection. Also, there are many tagnames that are the same, so keys should be not-unique. However for the value, they should be unique, but only to the tag name. So unit can only one one "4", but another tag, lets say imageID could also have "4". This is not a requirement but a "nice to have" and I can probably figure that out if its not simple. But if its REALLY hard then I will skip it all together.
I hope this makes sense.
And no, I don't think Im allowed to use json. I'm sure it can be done in simpleXMl but if its impossible, then please provide a method to do it in json (assuming that json is included with PHP and not an extension that has to be loaded).
This is university homework, so I can't use extensions or anything else that would require anything beyond what comes with the XAMPP basic package (php, mysql, apache etc...).
Really surprised I got no votes or views or answers or anything on this. I did figure this out in the end. Oh yeah...got the tumbleweed badge for this too!
Anyway the answer was actually quite simple. I used the simplexml_load_file function in PHP which actually supports any kind of xml-style. So after running this,
$eml = simplexml_load_file("unit.eml");
I then did things like this
foreach ($eml->children() as $child)
$tag = $child->getName();
$tagInfo = $child;
And used $tag and $tagInfo to iterate through my eml and get everything I needed.

Trouble with implementation of download code redeemer

I'm designing a website for a small indie record label and they've dropped a bombshell asking if I could implement a function where a user can enter a code to receive a digital download.
Is there a simple solution to doing this? I was thinking all I would need is an input field where the user can enter a code, it gets verified and then allows a download but it sounds too simple. Is this even possible with something like .php (complete beginner)?
I'm willing to learn or I would've packed it in already so any advice would be great. Thanks.
Edit:
Thanks to some great advice I was able to create this!
If you wanted to do it at a very simple level, it is not much more than you describe it to be. You would need to familiarize with PHP and MySQL or some other database, but it isn't too difficult to create.
You need to figure a few things out, such as how do you want to limit the codes, 3 downloads in the first 24 hours to allow for failed downloads, restrict it to IP, or strictly one full download. Since you have the list of the 1000 codes given, you will probably want to base your system around having codes pre-generated and inserted in the database, rather than having an algorithm that can validate the codes on the fly and then check for already used codes.
You would want to store the download(s) in a directory that is not accessible from the web, and the php script would validate the code, and if valid serve the download to the user.
You can probably look to the wordpress plugin's database structure for other ideas, but I think at the very least you would need:
download_code (the code itself, probably primary key or at least index)
download_file (optional, the name/path of the file this code allows them to download)
redeemed (0 if not redeemed, 1 if redeemed)
redemption_time (timestamp of the first, or last redemption based on your requirements)
download_count (how many times downloaded if allowing more than 1)
ip_address (ip address of the redeemer)
email_address (email address if you want to collect it, or give user the option)
download_url (the unique string for the download url. this could be one way to implement download verification beyond the code, but is not necessary)
You would then need to create an html page with the text box for entering the code, and any other optional data you wish to collect. The form would submit to your PHP script.
When the PHP script receives a form post, it would validate all of the data (i.e. email address if you were collecting it). Once all data is valid, you read from the database looking for a code matching what the user entered.
If no data was found with the code, send them back to the form to try re-entering it. If a record is found, you can check the redeemed value from the database and see if the code has been used or not. If it has, this is where you can use custom logic to decide if they are still within their download window, the ip address is the same, or whatever criteria you want to use to allow re-downloads.
If it has been redeemed, show an error message. If it is still okay to download, you can serve a download by reading the file and sending it to the browser see example #1 here.
At some point you will have to update your database to set the redeemed flag to 1 and update the other values such as timestamp and download count. You can either run this code before you serve the download, or you can run it after the download is served. In some cases if the download was cut off, the last portion of your script won't run and therefore won't update redeemed or download_count. This may or may not be what you want, so you can decide where you want to do the updating.
Eventually you can update it to include an administration panel, but in the beginning all configuration could be done within the php script or config file. And eventually you could update it to use flash or some other technology to download the file and show progress bars etc.
Hopefully that will give you some idea on whether or not you want to try to implement it. Otherwise you could always search php on Hotscripts to see if there is an already rolled standalone version of what you want.

Is it always bad practice to start an ID with a number? (CSS)

In my project I have submissions and comments, each with an ID. Currently the ID's are just numeric and correspond to their database ID's. Everything is working fine but when I run it through the W3 validator I get the error:
value of attribute "id" invalid: "1" cannot start a name
I suppose instead that I could just precede all ids with some sort of string but then whenever I was using or manipulating the id in JQuery or PHP I have to do a id.replace('string', '') before using it. This seems rather cumbersome. Any advice?
Yes, using numbers as HTML element IDs is bad practice.
It violates W3C specification.
You noted this in your question, and it is true for every HTML specification except HTML5
It is detrimental to SEO.
Search-engine optimized HTML element IDs SHOULD reflect the content of the identified element. Check out How To Compose HTML ID and Class Names like a Rockstar by Meitar Moscovitz. It provides a good overview of this concept.
There can be server-side scripting issues.
Back when I first started programming in ASP classic, I had to access submitted form fields by a syntax like Request.Form("some_id"). However, if I did Request.Form(1) it would return the value of the second field in the form collection, instead of the element with an Id equal to 1. This is a pretty standard behavior for working with collections. Its also similar with javascript, and could make your client side scripting more complicated to maintain as well.
I suggest you to use prefixes "comment-ID" or "post-ID".
If you need the id in JavaScript, you just have to id.substring(8) (for "comment-")
The HTML 5 Specification lifts this restriction. If you're worried about validity you might simply consider changing the DTD to HTML5's.
http://www.w3.org/TR/html5/elements.html#the-id-attribute
If you're manipulating the element then you can just use $(this).jQueryOperation() - therefore you can have a prefix without having to replace anything!
The best way for your need is having the prefix for your class, I mean something like item-x and x is the number that you need.
But from my personal experience, it is better to use classes for your elements, and you know that you must use classes if the item is not unique in the page

Categories