以下是我所讨论的表的XSL代码:
<table id="dataTable" border="1">
<thead>
<tr>
<th style="text-align: left;">Action</th>
<th>Element</th>
<th>Parameter</th>
<th>Pass/Fail</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="trace/step">
<tr>
<td id = "actionc" style="text-align: left;">
<xsl:value-of select="action"/></td>
<td id="elementc"><xsl:value-of select="element"/></td>
<td id="paramc"><xsl:value-of select="parameter"/></td>
<td id="passfailc"></td>
</tr>
</xsl:for-each>
</tbody>
</table>
这是我的javascript:
var textarea = document.getElementById('actionc');
var word = 'error:';
var textValue=textarea.value;
if (textValue.indexOf(word) != -1) {
$('#passfailc').append('X');
}
else {
$('#passfailc').append('O');
}
示例XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="output.xsl"?>
<testResults>
<testResult endTime="1409040996817" id="Test 1(hello)" result="PASS" startTime="1409040974962">
<trace>
<step id="1" timestamp="1409040983154">
<action>page action: click</action>
<element>Home Page: Search Button</element>
<parameter/>
</step>
<step id="2" timestamp="1409040983594">
<action>page action: set text</action>
<element>Home Page: Search Input Text</element>
<parameter>bike</parameter>
</step>
<step id="3" timestamp="1409040987677">
<action>page action: click</action>
<element>Results Page: Top Item</element>
<parameter/>
</step>
<step id="4" timestamp="1409040995052">
<action>page action: Get an attributes value from an element</action>
<element>Item Page: Price Text</element>
<parameter/>
</step>
</trace>
</testResult>
<testResult endTime="1409040827762" id="Test 2(com.thetestpeople.ebaydemo.mobileweb.test.SearchItemTest)" result="ERROR" startTime="1409040786110"><trace><step id="1" timestamp="1409040792321"><action>page action: navigate to</action><element/><parameter>http://www.buystuff.com/</parameter></step><step id="2" timestamp="1409040794466"><action>page action: set text</action><element>Home Page: Search Input Text</element><parameter>bike</parameter></step><step id="3" timestamp="1409040827687">
<action>error: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'Apeldoorn.local', ip: '10.0.1.7', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.7.0_45'
Driver info: driver.version: RemoteWebDriver
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'Apeldoorn.local', ip: '10.0.1.7', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.7.0_45'
Driver info: driver.version: RemoteWebDriver
</action>
<element/><parameter/></step></trace></testResult>
</testResults>
当我打开XML文件时,一切正常但是它没有在Pass / Fail列中放任何东西?我是Javascript和XML的新手,所以请放轻松我吧! 提前谢谢!
答案 0 :(得分:0)
如果单词“error”在“Action”列中,我想要输入“X” 如果它不存在则为“O”。
尝试:
<td id="passfailc">
<xsl:choose>
<xsl:when test="contains(action, 'error')">X</xsl:when>
<xsl:otherwise>O</xsl:otherwise>
</xsl:choose>
</td>