Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 414695 - SWTWorkbenchBot method viewByTitle should not use withPartName but withTitle
Summary: SWTWorkbenchBot method viewByTitle should not use withPartName but withTitle
Status: RESOLVED FIXED
Alias: None
Product: SWTBot
Classification: Technology
Component: SWTBot (show other bugs)
Version: 2.1.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 2.2.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-08 14:29 EDT by Michal Borek CLA
Modified: 2013-12-20 07:02 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michal Borek CLA 2013-08-08 14:29:06 EDT
In SWTWorkbenchBot class there is viewByTitle(String title) which is treated as a shortcut for view(withPartName(title)).

In fact part's and it's title are two different things.

There should be two methods

viewByPartName(String partName) and viewByTitle(String title) where the second one is using a matcher that compares IWorkbenchPartReference#getTitle() not IWorkbenchPartReference#getPartName().

In my case partName and view title are two different things and there is no possiblility to check the former one.
Comment 1 Mickael Istria CLA 2013-08-19 07:13:16 EDT
That sounds like a good improvement/fix.
Would you mind to turn this request into a code contribution? http://wiki.eclipse.org/SWTBot/Contributing#Provide_a_contribution_using_Gerrit
Comment 2 Mickael Istria CLA 2013-08-19 07:16:23 EDT
Oh, I just noticed this: https://git.eclipse.org/r/#/c/15264/ ;)
It's generally a good think to add link to the Gerrit contribution in Bugzulla, so it can prevent readers with their heads in the cloud (like me) to add useless comments.
Comment 3 Michal Borek CLA 2013-08-19 07:31:53 EDT
Thanks Mickael, I'll remember that in future.

We're going to use SWTBots on Eclipse 4.3 so as soon as I find any other issue I'll try to investigate it and if possible provide some fix.
Comment 4 Mickael Istria CLA 2013-08-19 12:41:06 EDT
This change will be available in next SWTBot snapshot ( http://download.eclipse.org/technology/swtbot/snapshots ) when https://hudson.eclipse.org/hudson/view/SWTBot/job/swtbot-tycho/120/ is finished.
Comment 5 Roland Grunberg CLA 2013-08-20 11:03:03 EDT
The merged change doesn't contain viewByPartName. The workaround is pretty small, but just thought I'd comment in case anyone is confused by the non-existent method.
Comment 6 Mickael Istria CLA 2013-08-20 11:07:22 EDT
@Roland: feel free to reopen the issue and add a Gerrit patch if you want to add a viewPartName. It'll be welcome.
Comment 7 Michal Borek CLA 2013-08-20 12:03:00 EDT
Reopening, I'm gonna apply the proposal of Roland
Comment 8 Michal Borek CLA 2013-08-20 12:21:10 EDT
The fix is pushed to gerrit: https://git.eclipse.org/r/#/c/15659/
Comment 9 Mickael Istria CLA 2013-08-20 12:39:37 EDT
Thanks Michal. This second patch was merged as well.
Comment 10 Roland Grunberg CLA 2013-08-20 16:33:11 EDT
I'm not entirely sure if this is working as expected. The title isn't the actual title text visible in the view, but rather a combination of the part name and the content description. For a part name of 'foo' and content description of 'bar', the title is 'foo (bar)'.

I would think viewByTitle should just get the content description since that's what the user sees as the 'title'. Either way, I wrote a sample to allow the testing of viewByTitle specifically in the case where it's value is not the same as the part name :

http://rgrunber.fedorapeople.org/0001-WIP-Make-changes-to-test-viewByTitle.patch
Comment 11 Michal Borek CLA 2013-08-21 01:34:04 EDT
@Roland: In my case it is working exactly the same as it is implemented now. I'll double check that and maybe I'll find the reason of such differences.
Comment 12 Mickael Istria CLA 2013-08-21 04:05:11 EDT
@Roland: Maybe you can turn your sample into a Unit test in org.eclipse.swtbot.eclipse.finder.test . That would help everyone to agree on the best implementation for these new methods.
Comment 13 Roland Grunberg CLA 2013-08-21 10:40:26 EDT
Just as a note, I've been testing this with mvn clean install -Pkepler (from within org.eclipse.swtbot.eclipse.finder.test since the affected components would mainly be there)

When no content description is set, the title is assigned the value of the part name. When I run the tests through maven, and doing a setContentDescription at the bottom of createPartControl in SWTBotTestView causes all the tests in SWTBotViewTest using viewByTitle to fail since the value of the title is $partname ($content_description).

There's a sample test case in the patch and in particular contains :

SWTBotView view = bot.viewByTitle("SWTBot Test View (Test View Title)");

where "SWTBot Test View" is the part name and "Test View Title" is the content description (the text shown just below the part name). That passes for me, and I'd be ok with that. The only way I've found to avoid this issue is by using setTitle but it's deprecated in favour of setContentDescription.
Comment 14 Michal Borek CLA 2013-08-21 12:00:58 EDT
Thanks Roland, I'm gonna check the same on my project, and if it's also valid the solution is obvious and I'll change it to conform to this behavior.