You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make test and suite messages available as plain text and HTML separately #4068
Make it possible to tell that the merge message should be plain text.
Make it possible to convert any message from HTML to plain text.
Decide not to do anything and expect tools using Robot APIs to handle HTML to plain text conversion.
I'm not a big fan of option 1 because it's not too generic (also other messages can be in HTML), it would make messages in normal log less good, and I don't like this kind of configuration too much in general. Option 3 means doing nothing which isn't ideal either so let's concentrate on option 2. For that we have have several possibilities:
Add separate message_as_html and message_as_text attributes (actual names subject to change) to test and suite objects. message would be as it's nowadays and these new ones would be read-only properties generated based on it.
Make message always plain text and add new html_message (name, again, can be something else). Could be implemented so that there's separate _message that contains the actual message and these others are generated based on it. Both message and html_message would thus need to be settable properties (they'd set that _message).
Add new utility functions to convert message into plain text and HTML.
Option 2 above sounds best to me but has a problem that it's slightly backwards incompatible because message changes. That ought to be fine in a major release, though. Regardless the approach, we'd then need to have a way to convert HTML to plain text. I wouldn't like to have any external dependencies so we'd need to implement it ourselves. Probably just stripping HTML tags would be fine.
Converting HTML to text ought to be pretty easy with html.parser. We'd only need to implement handle_data go get the text but could also easily implement e.g. <b> to * conversion by adding handle_start/endtag methods. Should fine-tune the implementation so that it works well with our merge message.
changed the title [-]Make HTML in test status message field of merged test cases configurable [/-][+]Make test and suite messages available as plain text and HTML separately[/+]on Sep 1, 2021
After thinking this a bit more, I believe going with the option 2 discussed above is the best idea. I set the issue title and labels accordingly. Next we'd need someone to implement this. I know I have other more important tasks for the forthcoming RF 5.0 and won't have time for this. I'd obviously be happy to help anyone interested to get started, review pull requests, and so on. If @simonmeggle or someone else is interested, let me know!
Added a label indicating help would be appreciated. Although this is far from trivial to implement, I also added a label telling that this is ok for new contributors.
Design option 2 discussed in my earlier comment would in practice mean something like this:
Create html_to_text utility. It can utilize html.parser as discussed above.
Add code like this to handle setting and getting message:
def__init__(...):
...
self._message=''@propertydefmessage(self):
ifself._message.startswith('*HTML*'):
returnhtml_to_text(self._message[6:]) # html_to_text needs to be implementedreturnself._message@message.setterdefmessage(self, message):
self._message=message@propertydefhtm_message(self):
ifself._message.startswith('*HTML*'):
returnself._message[6:]
returnhtml_escape(self._message) # We already have html_escape@html_message.setterdefhtml_message(self, message):
self._message=messageself._message='*HTML* '+message
Instead of storing message internally in _message attribute as a string with possible *HTML* prefix, we could store it as a tuple containing the message and a Boolean telling should it be interpreted as HTML or not. Yet another solution would be making it an object that contains most of the logic so that the properties above could be simplified.
If we wanted to, we could make message itself and object that would have separate attributes for getting the message as plain text and HTML. The object itself should obviously have string representation as well so that it could be used as a string in formatting.
The reason I want to discuss about the design is that we have #2549 about making it possible to make specify test and suite documentation as HTML. There we probably needed to have documentation available both as plain text and HTML as well. These needs are similar so we should use the same design in both places. That also means that the aforementioned html_to_text could be used in both cases and possible objects containing logic for returning either plain text or HTML version could also be reused.
@simonmeggle@pekkaklarck So I'm investigating this, and was thinking about the HTML_to_text function. Would it be something like if the original message is "*HTML* Number is not my <b>MAGIC</b> number", then the output is "Number is not my MAGIC number"? If so, I played around with the html parser library and found the following code to work. What do you think? Maybe I can make a PR if you agree?
I'm also unsure about how to create the atests for this. How should I test the status message of rebot? Any ideas just to help me get started?
from html.parser import HTMLParser
class HTMLToText(HTMLParser):
def __init__(self):
super().__init__()
self._HTMLAsText = ''
def handle_data(self, data):
self._HTMLAsText = self._HTMLAsText + data
@property
def HTMLAsText(self):
return self._HTMLAsText
def html_to_text(HTML):
test = HTMLToText()
test.feed(HTML)
return test.HTMLAsText()
@makeevolution For the use within robotmk, I previously also used HTMLParser. But instead, i switched now to something simpler which also works. The HTML data are not arbitraty, but the RF log content; hence it is predictable what has to be replaced.
Now, I save the dependency from HTMLParser and do a simple replacement of all HTML tags which can occurr:
@simonmeggle what about if there is a bold or italics text? Your solution has the additional replacement of breaks or paragraphs with new line, is that for your own use?
@makeevolution Yes, this is completely for my own project which processes RF XML logs. This is not a perfect solution, don't take this as complete. :-)
I just wanted to point out that there is probably a simpler way without dependencies if the incoming HTML is well known.
This is still open. It hasn't had too high priority, but I see it would be useful. If you are interested to look at it, please explain briefly your planned design.
@pekkaklarck I saw your proposed idea in the previous comments, Which i would like to try.
Maintain backward compatibility for current behavior (message returns plain text).
Introduce a new html_message property to handle HTML representations.
Add a private _message attribute to store the raw data and provide logic for handling text/HTML transformations.
Implementation Steps
Create Utility Functions:
A function (html_to_text) to strip HTML tags and return plain text.
Use Python's built-in html.parser for efficient tag stripping.
Modify Test and Suite Objects:
Add a _message attribute to store the actual content.
Introduce new message and html_message properties:
message will return plain text (default).
html_message will return HTML, either by escaping the current plain text or as-is if the message is already HTML.
Activity
pekkaklarck commentedon Aug 27, 2021
Possible solutions:
I'm not a big fan of option 1 because it's not too generic (also other messages can be in HTML), it would make messages in normal log less good, and I don't like this kind of configuration too much in general. Option 3 means doing nothing which isn't ideal either so let's concentrate on option 2. For that we have have several possibilities:
message_as_htmlandmessage_as_textattributes (actual names subject to change) to test and suite objects.messagewould be as it's nowadays and these new ones would be read-only properties generated based on it.messagealways plain text and add newhtml_message(name, again, can be something else). Could be implemented so that there's separate_messagethat contains the actual message and these others are generated based on it. Bothmessageandhtml_messagewould thus need to be settable properties (they'd set that_message).Option 2 above sounds best to me but has a problem that it's slightly backwards incompatible because
messagechanges. That ought to be fine in a major release, though. Regardless the approach, we'd then need to have a way to convert HTML to plain text. I wouldn't like to have any external dependencies so we'd need to implement it ourselves. Probably just stripping HTML tags would be fine.pekkaklarck commentedon Aug 27, 2021
Converting HTML to text ought to be pretty easy with html.parser. We'd only need to implement
handle_datago get the text but could also easily implement e.g.<b>to*conversion by addinghandle_start/endtagmethods. Should fine-tune the implementation so that it works well with our merge message.[-]Make HTML in test status message field of merged test cases configurable [/-][+]Make test and suite messages available as plain text and HTML separately[/+]pekkaklarck commentedon Sep 1, 2021
After thinking this a bit more, I believe going with the option 2 discussed above is the best idea. I set the issue title and labels accordingly. Next we'd need someone to implement this. I know I have other more important tasks for the forthcoming RF 5.0 and won't have time for this. I'd obviously be happy to help anyone interested to get started, review pull requests, and so on. If @simonmeggle or someone else is interested, let me know!
pekkaklarck commentedon Sep 1, 2021
Added a label indicating help would be appreciated. Although this is far from trivial to implement, I also added a label telling that this is ok for new contributors.
simonmeggle commentedon Sep 1, 2021
pekkaklarck commentedon Sep 13, 2021
Design option 2 discussed in my earlier comment would in practice mean something like this:
Create
html_to_textutility. It can utilizehtml.parseras discussed above.Add code like this to handle setting and getting message:
Instead of storing message internally in
_messageattribute as a string with possible*HTML*prefix, we could store it as a tuple containing the message and a Boolean telling should it be interpreted as HTML or not. Yet another solution would be making it an object that contains most of the logic so that the properties above could be simplified.If we wanted to, we could make
messageitself and object that would have separate attributes for getting the message as plain text and HTML. The object itself should obviously have string representation as well so that it could be used as a string in formatting.The reason I want to discuss about the design is that we have #2549 about making it possible to make specify test and suite documentation as HTML. There we probably needed to have documentation available both as plain text and HTML as well. These needs are similar so we should use the same design in both places. That also means that the aforementioned
html_to_textcould be used in both cases and possible objects containing logic for returning either plain text or HTML version could also be reused.fixedforward commentedon Dec 5, 2021
@pekkaklarck Is someone already working on this? If not do you mind assigning me?
pekkaklarck commentedon Dec 7, 2021
Apparently @simonmeggle hasn't worked on this lately so go ahead @makeevolution!
fixedforward commentedon Dec 13, 2021
@simonmeggle @pekkaklarck So I'm investigating this, and was thinking about the HTML_to_text function. Would it be something like if the original message is "*HTML* Number is not my <b>MAGIC</b> number", then the output is "Number is not my MAGIC number"? If so, I played around with the html parser library and found the following code to work. What do you think? Maybe I can make a PR if you agree?
I'm also unsure about how to create the atests for this. How should I test the status message of rebot? Any ideas just to help me get started?
simonmeggle commentedon Dec 13, 2021
@makeevolution For the use within robotmk, I previously also used HTMLParser. But instead, i switched now to something simpler which also works. The HTML data are not arbitraty, but the RF log content; hence it is predictable what has to be replaced.
Now, I save the dependency from HTMLParser and do a simple replacement of all HTML tags which can occurr:
Perhaps this already does its job? Only a suggestion.
fixedforward commentedon Dec 14, 2021
@simonmeggle what about if there is a bold or italics text? Your solution has the additional replacement of breaks or paragraphs with new line, is that for your own use?
simonmeggle commentedon Dec 14, 2021
@makeevolution Yes, this is completely for my own project which processes RF XML logs. This is not a perfect solution, don't take this as complete. :-)
I just wanted to point out that there is probably a simpler way without dependencies if the incoming HTML is well known.
fixedforward commentedon Dec 14, 2021
@simonmeggle Ah okay thanks for the idea! I think it then depends on @pekkaklarck on how he wants to proceed...
hariharandakshnamurthy commentedon Nov 19, 2024
Is this issue Closed or open, Can i work on it?
pekkaklarck commentedon Nov 20, 2024
This is still open. It hasn't had too high priority, but I see it would be useful. If you are interested to look at it, please explain briefly your planned design.
hariharandakshnamurthy commentedon Nov 20, 2024
@pekkaklarck I saw your proposed idea in the previous comments, Which i would like to try.
Maintain backward compatibility for current behavior (message returns plain text).
Introduce a new html_message property to handle HTML representations.
Add a private _message attribute to store the raw data and provide logic for handling text/HTML transformations.
Implementation Steps
Create Utility Functions:
A function (html_to_text) to strip HTML tags and return plain text.
Use Python's built-in html.parser for efficient tag stripping.
Modify Test and Suite Objects:
Add a _message attribute to store the actual content.
Introduce new message and html_message properties:
message will return plain text (default).
html_message will return HTML, either by escaping the current plain text or as-is if the message is already HTML.