Logo QF-Test

Finding valuable answers
in the Mailing List Archive.

 

Free Trial  Download  Buy

Thomas Max, QF-Test training and support

Use the full-text search on our web site to find helpful tips on the mailing list.

Thomas Max, 
Sr. Software Engineer & Trainer, QFS

2017 up to now  | 2016 | 2015 | 2014 | 2013 | 2012 | 2011 | 2010 | 2009 | 2008 | 2007

(older archive entries before 2007 are not shown here, but included in the onsite-search)

Mailing List - Entries of 2014


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [QF-Test] Extracting/checking text from JEditorPane


  • Subject: Re: [QF-Test] Extracting/checking text from JEditorPane
  • From: Gregor Schmid <Gregor.Schmid@?.de>
  • Date: Mon, 30 Jun 2014 15:28:53 +0200

Hello Michael,

besides the position of the id attribute, the alignment also appears
different.

But that's not the point, of course. I agree that it would be useful
to have two different kinds of text checks for the JEditorPane, one
for the HTML and one for the displayed text.

I'll see to it to get this implemented before the final release of
QF-Test 4.0. Below you can find a script that implements a "Plain
text" Checker for a JEditorPane which you can use in the meantime (and
also after the QF-Test 4.0 release, of course).

As for the check performance problems you reported: Can you please
send a .qzp run-log to our support for further analysis? Thank you.

Now, here's the promised Checker as Jython SUT script. Just place the
SUT script node after the 'Wait for client to connect' node and you'll
get the "Plain text" check as the default check when left-clicking and
as the first item in the menu when right-clicking in check recording
mode.

----------------------------------------------------------------------
from de.qfs.apps.qftest.extensions import ResolverRegistry
from de.qfs.apps.qftest.extensions.checks import CheckerRegistry, \
    Checker, DefaultCheckType, CheckDataType
from de.qfs.apps.qftest.shared.data.check import StringCheckData
from de.qfs.lib.util import Pair
from java.lang import String
import jarray

componentClass = "javax.swing.JEditorPane"
plainTextCheckType = DefaultCheckType("plaintext",
    CheckDataType.STRING_LIST,
    "Plain text")

class PlainTextChecker(Checker):
    def __init__(self):
        pass

    def getSupportedCheckTypes(self, com, item):
        return jarray.array([plainTextCheckType], DefaultCheckType)

    def getCheckData(self, com, item, checkType):
        if plainTextCheckType.getIdentifier() == \
                checkType.getIdentifier():
            doc = com.getDocument()
            text = doc.getText(1, doc.getLength()).strip()
            return StringCheckData(checkType.getIdentifier(), text)
        return None

    def getCheckDataAndItem(self, com, item, checkType):
        data = self.getCheckData(com, item, checkType)
        if data is None:
            return None
        return Pair(data, None)

def unregister():
    try:
        CheckerRegistry.instance().unregisterChecker(
            componentClass, plainTextChecker)
    except:
        pass

def register():
    unregister()
    global plainTextChecker
    plainTextChecker = PlainTextChecker()
    CheckerRegistry.instance().registerChecker(
        componentClass, plainTextChecker)

register()
----------------------------------------------------------------------

For further information about Checkers and other classes used in this
script, please see the QF-Test manual section 39.3:

http://www.qfs.de/qftest/manual/en/tech_checkers.html#sec_checkers

Best regards,
    Greg

Michael Theurich <Michael.Theurich@?.int> writes:

> I have a problem checking the displayed text in a swing JEditorPane component. The HTML text is
> generated by my SUT code in one go, then submitted to the component, and looks like this:
>
> <html>
>   <head>
>
>   </head>
>   <body>
>     <h2>
>       Minimum Report Detail <a href="file://entryDetail.html#10,3,0,80"><font size="small">show
>       help info...</font></a>
>     </h2>
>     <table id="detail" rules="cols">
>       <tr id="normalrow" currentrow="0">
>         <td id="label" border="1" cellspacing="0" align="left">
>
>         </td>
>         <td id="value" border="1" cellspacing="0" align="right">
>           Raw
>         </td>
>         <td id="value" border="1" cellspacing="0" align="right">
>           Calibrated
>         </td>
>         <td id="value" border="1" cellspacing="0" align="right">
>           Unit
>         </td>
>       </tr>
> and so on...
>
> This (expected) text has been put into the “expected text” field of a Check-txt node in my test,
> by way of the check recording feature of qft (this is exactly how the text looks in a debugger
> prior to throwing it at JEditorPane). But when the test runs and the check is executed, it fails,
> and the following actual text is displayed:
> <html>
>   <head>
>
>   </head>
>   <body>
>     <h2>
>       Minimum Report Detail <font size="small"><a href="file://entryDetail.html#10,3,0,80">show
>       help info...</a></font>
>     </h2>
>     <table id="detail" rules="cols">
>       <tr currentrow="0" id="normalrow">
>         <td border="1" cellspacing="0" align="left" id="label">
>
>         </td>
>         <td border="1" cellspacing="0" align="right" id="value">
>           Raw
>         </td>
>         <td border="1" cellspacing="0" align="right" id="value">
>           Calibrated
>         </td>
>         <td border="1" cellspacing="0" align="right" id="value">
>           Unit
>         </td>
>       </tr>
>
> As you can see, the position of the id attribute has changed, although not in all cases. Also the
> relative order of the a and the font element have changed. Of course with this text, the test
> fails.
> But it also sometimes occurs that the text is extracted unaltered. Component identification is
> never an issue.
>
> Strange, isn’t it? I also noticed that qftest becomes VERY slow when a check_txt contains a large
> text field with many line breaks.
>
> Maybe qftest has to employ special logic to retrieve the HTML from the component. The normal
> copy-to-clipboard handler e.g. only retrieves the plain text and strips any tags. Have I spotted a
> bug? Is this non-deterministic behaviour of JEditorPane (or it’s instrumentation by qftest) or of
> qftest?
>
> Another solution for me would be to retrieve the plain text from the contents of JEditorPane and
> base the comparison on that. Is that supported by qftest in any way?
>
> I am currently using qftest-3.5.6 for evaluation.
>
> Thanks for any help,
> Michael
>
> ---------------------------------------------------------------------------------
> Michael Theurich
> Monitoring Application Tools SW Engineer
>
> Telespazio VEGA Deutschland GmbH
> Provision of Engineering Support Services
>
> EUMETSAT
> Eumetsat-Allee 1
> 64295 Darmstadt
> Tel +49 6151 807-7530
> email michael.theurich@?.int
>
> _______________________________________________
> qftest-list mailing list
> qftest-list@?.de
> http://www.qfs.de/mailman/listinfo/qftest-list

--
Gregor Schmid

E: gregor.schmid@?.de
T: +49 (0)8171 38648-11
F: +49 (0)8171 38648-16

Quality First Software GmbH | www.qfs.de
Tulpenstr. 41 | 82538 Geretsried | Germany
GF Gregor Schmid, Karlheinz Kellerer
HRB München 140833



Videos Downloads Documentation Buy Free Trial