简体   繁体   English

使用Sikuli验证文本

[英]Using Sikuli to verify text

I am using the Sikuli IDE to test an application that returns data in a text box. 我正在使用Sikuli IDE来测试在文本框中返回数据的应用程序。 For example I search the name field for my test value 'FirstName01' the application returns the name and address in various text boxes. 例如,我在名称字段中搜索我的测试值'FirstName01',应用程序在各种文本框中返回名称和地址。

I then verify the data by using the exists() function in Sikuli. 然后我使用Sikuli中的exists()函数验证数据。 To do this I click on the exists function in the upper left of the IDE and use the + tool to select the text I want to verify. 为此,我单击IDE左上角的exists函数,然后使用+工具选择我要验证的文本。 In this case FirstName01 and Location01. 在这种情况下,FirstName01和Location01。 I then set the Similarity setting on the MatchingPreview tab to .98 (I find if I set it to 1.0 Sikuli fails the test even if I get the correct data back). 然后我将MatchingPreview选项卡上的Similarity设置设置为.98(我发现如果我将其设置为1.0,即使我得到正确的数据,Sikuli仍然无法通过测试)。

If I run the test searching for FirstName01 I get correct results back and Sikuli does not throw an error. 如果我运行测试搜索FirstName01,我得到正确的结果,Sikuli不会抛出错误。 My problem is if I search for and return FirstName02 in an attempt to generate the error condition the exists function passes it even though it is looking for FirstName01. 我的问题是,如果我搜索并返回FirstName02,试图生成错误条件,即使找到FirstName01,存在的函数也会传递它。 It seems Sikuli does not verify the last character of the data. 似乎Sikuli没有验证数据的最后一个字符。 It seems to verify other characters because if I search for FirstName21 the exists function throws an error as it should. 它似乎验证了其他字符,因为如果我搜索FirstName21,则exists函数会抛出错误。 Has anyone come across this problem and if so how did you solve it? 有没有人遇到这个问题,如果是这样,你是如何解决它的?

My code is below 我的代码如下

If exists(FirstName01):
   popup('passed')
else:
   popup('failed')

Is there another way to verify data? 还有另一种验证数据的方法吗?

Rather than using exists() to verify text (because the OCR in sikuli's IDE is pretty unreliable), if there is any way to get the text that you want to evaluate to the clipboard, you can use Env.getClipboard() to evaluate it with much more accuracy. 而不是使用exists()来验证文本(因为sikuli的IDE中的OCR非常不可靠),如果有任何方法可以将要评估的文本放到剪贴板中,则可以使用Env.getClipboard()来评估它准确度更高。

To get it to the clipboard, you could use several approaches: 要将其放到剪贴板,您可以使用以下几种方法:

  1. dragDrop() to highlight the text dragDrop()突出显示文本
  2. Perhaps tabbing into the text box will highlight the text for you automatically 也许在文本框中添加标签会自动为您突出显示文本
  3. Use doubleClick() on the text (depending on what you're trying to highlight, thus might not get it all) 在文本上使用doubleClick()(取决于您要突出显示的内容,因此可能无法完成所有操作)
  4. Perhaps the most reliable way to highlight it--tab into the text box or click() inside the text box and select all: 也许是最可靠的突出显示方式 - 在文本框中选项卡或在文本框内单击()并选择全部:

.

click(someImageNearTextBox).offset() #get your cursor inside the textbox
type("a",KeyModifier.CTRL) #select all to highlight the text

Once your text is highlighted, you can proceed like this: 文本突出显示后,您可以这样继续:

type("c",KeyModifier.CTRL) #copy selection to the clipboard
firstName = Env.getClipboard().strip() #assign contents of clipboard to a variable

Then you can use it for whatever comparisons you want: 然后你可以将它用于你想要的任何比较:

if firstName == "FirstName01":
    popup('passed')
else:
    popup('failed')

The weakness of this approach is that if you have any special characters in the textbox, it may not evaluate properly. 这种方法的缺点是,如果文本框中有任何特殊字符,则可能无法正确评估。

ok, fourth edition on this answer... sorry. 好的,关于这个答案的第四版......抱歉。 Today is my second day on Sikuli and i'm beginnig on Python to. 今天是我在Sikuli的第二天,我开始在Python上开始。

I adapted the autoKarma answer. 我改编了autoKarma的答案。 On my textbox (multiline) CTRL+A doesn't work to select all the text. 在我的文本框(多行)上,CTRL + A无法选择所有文本。 I use CTRL+Home to go to begin of the text box and CTRL+SHIFT+End to go the end selecting the text. 我使用CTRL + Home转到文本框的开头,按CTRL + SHIFT + End结束选择文本。

type(Key.HOME, KeyModifier.CTRL) type(Key.HOME,KeyModifier.CTRL)

type(Key.END, KeyModifier.CTRL | KeyModifier.SHIFT) 类型(Key.END,KeyModifier.CTRL | KeyModifier.SHIFT)

So i get a problem. 所以我遇到了问题。 It works doing by hand, but not on sikuli. 它可以手工完成,但不适用于sikuli。 Seaching the reason i found that: There is a bug on Sikuli (on Java in fact), but there is a workaroud. 找到我发现的原因:Sikuli上存在一个错误(实际上是Java),但有一个工作区。

keyDown(Key.SHIFT) not working on Win with Num-Lock on -- switch it off ;-) keyDown(Key.SHIFT)无法使用Num-Lock打开Win - 关闭它;-)

https://answers.launchpad.net/sikuli/+question/143874 https://answers.launchpad.net/sikuli/+question/143874

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM