机器人框架:FOR循环

时间:2016-02-18 12:16:40

标签: robotframework

我需要从邮件正文中获取“动态”(每封电子邮件具有另一个ID)许可证ID,并与附件中的许可证ID进行比较。他们应该匹配。

所以我写了一些代码:

Open Mailbox server=${mail_server} user=${mail_server_username}   password=${mail_server_password}
${latest_mail}= Wait for Mail fromEmail=${company_email}   toEmail=${registered_email} status=UNSEEN timeout=300
${parts} = Walk Multipart Email ${latest_mail}
:FOR   ${i}   IN RANGE   ${parts}
 \   Walk Multipart Email    ${latest_mail}
 \   ${payload}=   Get Multipart Payload   decode=True
 \   log   ${payload}

在$ {payload}中,我有附加邮件的正文和文本(ID在哪里)。日志是:

20160218 13:56:14.652 :  INFO : ${latest_mail} = 9
20160218 13:56:15.272 :  INFO : ${parts} = 3
20160218 13:56:15.272 :  INFO : ${payload} = None
20160218 13:56:15.273 :  INFO : None
20160218 13:56:15.275 :  INFO : 
${payload} = <p>Dear <span class="error">qa test</span>,</p>
<p>Thank you for purchasing iRAPP! <br /><br />Attached please find your license file for License ID # 2708c5de934c389165f5fa43f9581b71.<br /><br />If ...
20160218 13:56:15.275 :  INFO : 
<p>Dear <span class="error">qa test</span>,</p>
<p>Thank you for purchasing iRAPP! <br /><br />Attached please find your license file for License ID # 2708c5de934c389165f5fa43f9581b71.<br /><br />If iRAPP Server software is already installed, you can update your license <br /><span class="st">by </span>following the instructions below:<br /><br /> 1 - Open System Preferences &gt; iRAPP Server<br /> 2 - Authorize (unlock the menu)<br /> 3 - Select &ldquo;Admin Tools&rdquo;<br /> 4 - Select &ldquo;License Manager&rdquo;<br /> 5 - If you've used an existing license ID for this <br />&nbsp;&nbsp;&nbsp;&nbsp; purchase,&nbsp; select &ldquo;Update License&rdquo;.<br />6 - If license update is not applicable, select <br />&nbsp;&nbsp;&nbsp; "Load From File" and use attached license file.<br /><br /></p>
<p>To install iRAPP software, please follow the steps below:</p>
<p><strong>Step 1: Install iRAPP Server on your Mac.</strong><br /><br /> For OS X 10.10 Yosemite: <a class="external-link" href="http://www.staging.coderebel.com/download/iRAPP_Server_Mac_Setup_For_10.10.dmg" rel="nofollow">http://www.staging.coderebel.com/download/iRAPP_Server_Mac_Setup_For_10.10.dmg</a><br /> For OS X 10.9 Mavericks: <a class="external-link" href="http://www.staging.coderebel.com/download/iRAPP_Server_Mac_Setup_For_10.9.dmg" rel="nofollow">http://www.staging.coderebel.com/download/iRAPP_Server_Mac_Setup_For_10.9.dmg</a><br /> For OS X 10.8 Mountain Lion: <a class="external-link" href="http://www.staging.coderebel.com/download/iRAPP_Server_Mac_Setup_For_10.8.dmg" rel="nofollow">http://www.staging.coderebel.com/download/iRAPP_Server_Mac_Setup_For_10.8.dmg</a></p>
<p><strong>Step 2: Access your Mac remotely.</strong></p>
<p>You can use Microsoft RDP Client:<br /><br />For Mac: <a class="external-link" title="Follow link" href="https://itunes.apple.com/us/app/microsoft-remote-desktop/id715768417" rel="nofollow">https://itunes.apple.com/us/app/microsoft-remote-desktop/id715768417</a></p>
<p>For iOS: <a class="external-link" title="Follow link" href="https://itunes.apple.com/us/app/microsoft-remote-desktop/id714464092" rel="nofollow">https://itunes.apple.com/us/app/microsoft-remote-desktop/id714464092</a></p>
<p>For Android: <a class="external-link" title="Follow link" href="https://play.google.com/store/apps/details?id=com.microsoft.rdc.android" rel="nofollow">https://play.google.com/store/apps/details?id=com.microsoft.rdc.android</a></p>
<p>For Windows: <a class="external-link" title="Follow link" href="http://windows.microsoft.com/en-us/windows/search#q=Remote+Desktop+Connection" rel="nofollow">http://windows.microsoft.com/en-us/windows/search#q=Remote+Desktop+Connection</a><br /><br /> Or, you can use iRAPP Client:<br /><br />For Windows:&nbsp; <a class="external-link" href="http://www.staging.coderebel.com/download/iRAPP_Client_Win_Setup.exe" rel="nofollow">http://www.staging.coderebel.com/download/iRAPP_Client_Win_Setup.exe</a> <br />For Mac OS X: <a class="external-link" href="http://www.staging.coderebel.com/download/iRAPP_Client_Mac_Setup.dmg" rel="nofollow">http://www.staging.coderebel.com/download/iRAPP_Client_Mac_Setup.dmg</a><br /><br /><br />More download links: <a href="http://www.staging.coderebel.com/downloads/">http://www.staging.coderebel.com/downloads/</a><br /> Help with installation: <a href="http://www.staging.coderebel.com/support/documentation-overview/">http://www.staging.coderebel.com/support/documentation-overview/</a><br /><br />Feel free to contact us if you have any questions. We&rsquo;re happy to help!<br /><br />Kind regards,<br />Code Rebel team</p>
#my_comment: id from attached file:
20160218 13:56:15.278 :  INFO : ${payload} = TEST_MODE license. ID:2708c5de934c389165f5fa43f9581b71
20160218 13:56:15.279 :  INFO : TEST_MODE license. ID:2708c5de934c389165f5fa43f9581b71

如何将来自邮件正文的ID与我从附件中获取的ID进行比较?

1 个答案:

答案 0 :(得分:0)

所以我以另一种方式做到了:

   # connect to mail server:
   Open Mailbox   server=${mail_server}   user=${mail_server_username}   password=${mail_server_password}
   # wait and save activation mail to variable 'latest_mail':
   ${latest_mail}=   Wait for Mail   fromEmail=${coderebel_reg_email}   toEmail=${registered_email}   #status=UNSEEN   timeout=300
   ${parts} =    Walk Multipart Email    ${latest_mail}

   #ignore part 1
   Walk Multipart Email    ${latest_mail}
   ${part_1} =   Get Multipart Payload   decode=True

   #body
   Walk Multipart Email    ${latest_mail}
   ${part_2} =   Get Multipart Payload   decode=True
   ${part_2} =   Fetch From Right   ${part_2}   ${l_marker_body}
   ${part_2} =   Fetch From Left   ${part_2}   ${r_marker_body}

   #attachment
   Walk Multipart Email    ${latest_mail}
   ${part_3} =   Get Multipart Payload   decode=True
   ${part_3} =   Fetch From Right   ${part_2}   ${l_marker_file}

   Should be equal   ${part_2}   ${part_3}

但我还有一个问题。如何实现使用:FOR循环???当我尝试使用以下方法时,我遇到了很多问题:FOR循环