如何从失败的堆栈中提取确切的api调用

时间:2016-05-25 16:41:36

标签: bash shell awk

我需要处理类似于下面的堆栈,它有一个字符串“oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver”,但我需要确切的方法调用失败。例如在这种情况下,确切的一个是“oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver.attachFile”。我有多个堆栈作为html页面的一部分,我需要处理,并且会有多种方法失败。我怎么能在shell脚本中做到这一点?整个堆栈在一行html条目中,这导致grep返回整个堆栈本身。我尝试了很多东西,但没有任何工作清楚我想awk或类似的正则表达式工具可能是一种方法,但不确定。

at oracle.adf.view.rich.automation.test.selenium.RichWebDriverTest.getElement(RichWebDriverTest.java:1414)
at oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver.attachFile(ApplcoreWebdriver.java:1460)
at oracle.apps.fnd.applcore.attachments.ui.util.accessor.FndManageAttachmentsPopupAccessor.attachFile(FndManageAttachmentsPopupAccessor.java:1475)
at oracle.apps.fnd.applcore.attachments.ui.util.accessor.FndManageAttachmentsPopupAccessor.updateRowFileAttachment(FndManageAttachmentsPopupAccessor.java:550)
at oracle.apps.fnd.applcore.attachments.ui.AttachmentsBaseSelenium.testLMultiFileAdd_22108390(AttachmentsBaseSelenium.java:1782)
at oracle.javatools.test.WebDriverRunner.run(WebDriverRunner.java:122)

2 个答案:

答案 0 :(得分:2)

我无法保证它是最有效的解决方案,但我能够满足需求。使用所有grepsed组合在一起。

使用html&将单个大cat个文件拆分为多行tr

cat file | tr ' ' '\n' | grep -w "$search_string" | sed 's/(.*)//'

出于测试目的,使用您在OP中共享的堆栈片段。

$ cat file
at oracle.adf.view.rich.automation.test.selenium.RichWebDriverTest.getElement(RichWebDriverTest.java:1414)
at oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver.attachFile(ApplcoreWebdriver.java:1460)
at oracle.apps.fnd.applcore.attachments.ui.util.accessor.FndManageAttachmentsPopupAccessor.attachFile(FndManageAttachmentsPopupAccessor.java:1475)
at oracle.apps.fnd.applcore.attachments.ui.util.accessor.FndManageAttachmentsPopupAccessor.updateRowFileAttachment(FndManageAttachmentsPopupAccessor.java:550)
at oracle.apps.fnd.applcore.attachments.ui.AttachmentsBaseSelenium.testLMultiFileAdd_22108390(AttachmentsBaseSelenium.java:1782)
at oracle.javatools.test.WebDriverRunner.run(WebDriverRunner.java:122)

为搜索字符串oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver

运行上述命令
$ cat file | tr ' ' '\n' | grep -w "oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver" | sed 's/(.*)//' 
oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver.attachFile

欢迎任何简化它的建议。

答案 1 :(得分:0)

好吧,我想我找到了一个有效的解决方案:

for stack in $all_stacks
do
        words=`echo $stack | tr ' ' '\n'`
        for word in $words
        do
                search_string="oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver"
                if [[ $word == *${search_string}* ]];
                then
                        echo $word
                fi
        done
done

我们的想法是将行(堆栈)拆分为由空格分隔的单词,并通过匹配所需的字符串来处理每个单词。然后匹配的单词最后打印所需的值(包括api调用)

根据来自@Inian的回复更新

下面更新了一个命令,通过处理包含要处理的错误堆栈的多个html文件来实现此目的。

find . -name '*-errors.html' | xargs cat | tr ' ' '\n' | grep -w "oracle.apps.fnd.applcore.test.selenium.ApplcoreWebdriver" | sed 's/(.*)//' | cut -d '<' -f1 | sort -u