我在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>