The pattern you are trying to use selects root nodes named Test.
You could use the pattern (//text()|//@*)[contains(string(), "test")], that selects the attributes that contain the string test or the text nodes that contain it (i.e. not the elements).
But you want to select the elements, right? Using (//*|//@*)[contains(., "test")] does that, but it selects elements that contain the string test, even if it is through some child element, which is not what is wanted either.
So I guess you'll have to use something like (//*[contains(text(), "test")]|//@*[contains(., "test")]), which gives you what you want, but is not very pretty.