我在CircleCI上运行了一个脚本文件,在那里我进行了UI单元测试,我需要解析来自Android的结果XML,然后找到成功的特定测试,将它们放在一个列表中,然后将失败放到另一个列表中.然后,我将遍历这两个列表并触发每个列表的API调用,用结果更新我们的测试用例.一次测试相当于一张测试用例罚单.到目前为止,在我的bash脚本中有以下内容:

totalTests=$(xmllint --xpath 'count(//testsuite/testcase)' $xml_file)
echo "Total tests = $totalTests"

# This is where I need help how to find the and grab the tag that has child tag of failure
failures=$(xmllint --xpath '//testsuite/testcase/????' $xml_file) 
echo "failures=$failures"

# This is where I need help how to find the and grab the tag that has no child tag of failure
successes1=$(xmllint --xpath '//testsuite/testcase/@name' $xml_file)
echo "successes1=$successes1"

IFS="$(printf '\nx')" && IFS="${IFS%x}";

for entry in $successes1
do
    number=`echo $entry | awk -F_ '{print $2}'`
    echo "CASE-$number"
done
...
# for loop for the failures ....
...

我的测试用例输出如下所示

<?xml version='1.0' encoding='UTF-8' ?>
<testsuite name="com.android.OnboardingBottomNavigation" tests="3" failures="1" errors="0" skipped="0" time="27.017" timestamp="2023-08-30T16:37:38" hostname="localhost">
  <properties>
    <property name="device" value="Pixel_4_API_33(AVD) - 13" />
    <property name="flavor" value="" />
    <property name="project" value=":app" />
  </properties>
  <testcase name="CASE_11447_Skip_Onboarding_Click_All_BottomNavs" classname="com.android.OnboardingBottomNavigation" time="5.483">
    <failure>java.lang.AssertionError: Expected value to be true.
at org.junit.Assert.fail(Assert.java:89)
at kotlin.test.junit.JUnitAsserter.fail(JUnitSupport.kt:56)
at kotlin.test.Asserter$DefaultImpls.assertTrue(Assertions.kt:648)
at kotlin.test.junit.JUnitAsserter.assertTrue(JUnitSupport.kt:30)
at kotlin.test.Asserter$DefaultImpls.assertTrue(Assertions.kt:658)
at kotlin.test.junit.JUnitAsserter.assertTrue(JUnitSupport.kt:30)
at kotlin.test.AssertionsKt__AssertionsKt.assertTrue(Assertions.kt:44)
at kotlin.test.AssertionsKt.assertTrue(Unknown Source:1)
at kotlin.test.AssertionsKt__AssertionsKt.assertTrue$default(Assertions.kt:42)
at kotlin.test.AssertionsKt.assertTrue$default(Unknown Source:1)
at com.android.OnboardingBottomNavigation.CASE_11447_Skip_Onboarding_Click_All_BottomNavs(OnboardingBottomNavigation.kt:39)</failure>
  </testcase>
  <testcase name="CASE_11445_Skip_Onboarding_Click_All_BottomNavs" classname="com.android.OnboardingBottomNavigation" time="15.353" />
  <testcase name="CASE_11446_Skip_Onboarding_Click_All_BottomNavs" classname="com.android.OnboardingBottomNavigation" time="2.513" />
</testsuite>

推荐答案

您可以在方括号中生成子查询,其计算结果可以为True:

xmllint --xpath '/testsuite/testcase[failure]'
<testcase name="CASE_11447_Skip_Onboarding_Click_All_BottomNavs" classname="com.android.OnboardingBottomNavigation" time="5.483">
    <failure>java.lang.AssertionError: Expected value to be true.
at org.junit.Assert.fail(Assert.java:89)
at kotlin.test.junit.JUnitAsserter.fail(JUnitSupport.kt:56)
at kotlin.test.Asserter$DefaultImpls.assertTrue(Assertions.kt:648)
at kotlin.test.junit.JUnitAsserter.assertTrue(JUnitSupport.kt:30)
at kotlin.test.Asserter$DefaultImpls.assertTrue(Assertions.kt:658)
at kotlin.test.junit.JUnitAsserter.assertTrue(JUnitSupport.kt:30)
at kotlin.test.AssertionsKt__AssertionsKt.assertTrue(Assertions.kt:44)
at kotlin.test.AssertionsKt.assertTrue(Unknown Source:1)
at kotlin.test.AssertionsKt__AssertionsKt.assertTrue$default(Assertions.kt:42)
at kotlin.test.AssertionsKt.assertTrue$default(Unknown Source:1)
at com.android.OnboardingBottomNavigation.CASE_11447_Skip_Onboarding_Click_All_BottomNavs(OnboardingBottomNavigation.kt:39)</failure>
  </testcase>

count个it:

xmllint --xpath 'count(/testsuite/testcase[failure])'
1

或者,你可以用not来否定它:

xmllint --xpath '/testsuite/testcase[not(failure)]'
<testcase name="CASE_11445_Skip_Onboarding_Click_All_BottomNavs" classname="com.android.OnboardingBottomNavigation" time="15.353"/>
<testcase name="CASE_11446_Skip_Onboarding_Click_All_BottomNavs" classname="com.android.OnboardingBottomNavigation" time="2.513"/>

count个it:

xmllint --xpath 'count(/testsuite/testcase[failure])'
2

Android相关问答推荐

垂直居中图标

我遇到了一个HashMaps对象没有存储在Firebase数据库中的问题.HashMap的一个对象put方法未被存储

懒惰的垂直网格中盒子的重量-Jetpack组合

泛型类型lambda函数参数作为函数参数

Jetapck Compose:将Compose BOM更新为最新版本&2024.01.00&Quot;CircularProgressIndicator后出现错误

原始mp3文件不显示与proguard

如何在Jetpack Compose中将对象的移动从一个路径平滑地切换到另一个路径?

如何将.txtassets资源 转换为ArrayList<;字符串>;kotlin格式?

没有打开历史记录的活动意向 Select 器完成调用活动

如何在Jetpack Compose中创建这个圆形?

有没有什么方法可以让Beeware在安卓手机上显示图片?

如何显示具体的商品数量?

Android Jetpack Compose全宽度抽屉优化

如何在 Jetpack Compose 中创建无限pager

如何将可重用的 ExtendedFloatingActionButton 与可重用的脚手架链接起来

房间创建三四表关系

Android Compose:LazyColumn 和 Column with verticalScroll 的区别

如何在jetpack compose中创建自定义rememberState?

更新应用程序是否会取消对应用程序特定文件的权限?

(Android) 如何在一对多关系中将子 ID 与父级匹配