eclipse - How to remove Switch Workspace in File menu - - java

When my application loads up I don't want the File menu to have switch workspace option I am trying with hideActionSet() method but till now I am unable to find which plugin shall I write in that so that it hides switch Workspace option.

Goto Window > Perspective > Customize Perspective
Select Menu Visibility tab
Expand File
Uncheck Switch Workspace
And you can save it as a new perspective tagged with name -
Window > Perspective > Save Perspective as...

The following way this can be resolved:
for (int i = 0; i < menuManager.getItems().length; i++) {
IContributionItem item = menuManager.getItems()[i];
if (item instanceof MenuManager) {
hideSwitchWorkSpace((MenuManager) item);}
private void hideSwitchWorkSpace(MenuManager manager) {
if (manager.getMenuText() != null && manager.getId() != null
&& manager.getMenuText().equals("&File") && manager.getId().matches("file"))
{
for (int i = 0; i < manager.getItems().length; i++) {
IContributionItem item = manager.getItems()[i];
if (item.getId() != null
&&(item.getId().matches("openWorkspace"))) {
item.setVisible(false);
}
}
}

Related

Below code is not woking with Chrome browser

I have created a reusable function which clicks the check box of a particular row and returns the text of that row.
CheckBoxXpath-> private static final String XPATH_JOBRATECATEGORIES_CHECKBOX_LIST = "//kendo-grid-list//table/tbody/tr/td[1]/label";
RowXpath -> private static final String XPATH_JOBRATECATEGORIES_LIST = "//kendo-grid-list//table/tbody/tr/td[2]//div//div";
count-> 0 (I want to click only first row check box)
public String Select_CheckBox_Return_SelectedText(String CheckBoxXpath,String RowXpath, int Count) {
List<WebElementFacade> listOfCheckBox = findAll(By.xpath(CheckBoxXpath));
List<WebElementFacade> listOfrow = findAll(By.xpath(RowXpath));
if(listOfCheckBox.size()>Count) {
for (int i = 0; i <= Count; i++) {
listOfCheckBox.get(i).click();
String Actual=listOfrow.get(i).getText();
}
}else {
Assert.fail("Need to have more rows to fullfill the requirement");
return null;
}
return Actual;
}
This is working fine with Firefox browser, but not working with Chrome browser.
On debugging code is throwing exception on -> "listOfCheckBox.get(i).click();"
I am not able to understand why it is behaving so weired.
Need help. Thanks in advance.
You need to target the checkboxes, not the labels in your xpath:
//kendo-grid-list//table/tbody/tr/td[1]/input[#type='checkbox']

Cached elements do not exist in DOM anymore

Like in similar issue, I use appium + java. Trying to select elements
In mobile application I am go to page, and after that, have many elements android.widget.ImageView(0), I need to select 6 (for example) such elements and go with other steps. Byt can select only one element and then get such exception:
org.openqa.selenium.StaleElementReferenceException: Cached elements 'By.id: com.company:id/selector_view' do not exist in DOM anymore
public GalleryPage choosePhotosFromAlbum(int count) {
List<MobileElement> photos = driver.findElementsById(elements.get("photo from gallery album selector"));
for (int i = 0; i < count; i++) {
photos.get(i).click();
}
return new GalleryPage(device);
}
I had the same issue. I think this happens because every time you click on a photo, the DOM changes. So, when you try to click on the second photo, the cached elements are not on the DOM anymore.
Try putting the photos inside the for cycle, like this:
public GalleryPage choosePhotosFromAlbum(int count) {
for (int i = 0; i < count; i++) {
List<MobileElement> photos = driver.findElementsById(elements.get("photo from gallery album selector"));
photos.get(i).click();
}
return new GalleryPage(device);
}
This way the list of photos is retrieved from the refreshed DOM on every cycle.
And by the way, you're not checking if the count is bigger than the photos list size, which can result in an OutOfBounds exception or similar.
You can use explicit wait to solve this problem.
public GalleryPage choosePhotosFromAlbum(int count)
{
List<MobileElement> photos = driver.findElementsById(elements.get("photo from gallery album selector"));
for (int i = 0; i < count; i++)
{
new WebDriverWait(driver,10).until(ExpectedConditions.presenceOfAllElementsLocatedBy("Your object property"));
photos.get(i).click();
}
return new GalleryPage(device);
}
Try enableMultiWindows appium capability set to true https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/settings.md
Or you can try finding elements via WebDriverWait. In Appium (C#), when the driver tries to find native elements, it can sometimes throw a StaleElementReferenceException. Thus you can ignore this exception and wait until elements exist in DOM:
public ReadOnlyCollection<IWebElement> WaitElements(By selector)
{
var wait = new WebDriverWait(this.Driver, new TimeSpan(0, 0, 10));
ReadOnlyCollection<IWebElement> results = null;
try
{
wait.Until(driver =>
{
try
{
var elements = driver.FindElements(selector);
if (elements.Any())
{
results = elements;
return true;
}
}
catch (StaleElementReferenceException)
{
// ignore
}
return false;
});
}
catch (WebDriverTimeoutException)
{
throw new NoSuchElementException("Elements not found");
}
return results;
}

How to Hide and Unhide Column with Custom Menu in Google Sheets using Google Script

I would like to "TOGGLE" between two functions (hide & unhide of a specific column - allocated to a specific month), by clicking on a custom item (monthName) in a menu that I created in Google Sheets (using the Ui).
Currently only the first function (hiding of a column) works. The second function (unhiding that same column), does not work.
Would you please be so kind to help.
Here follows the code:
var month = "Month-YY";
function onOpen() {
var ui = SpreadsheetApp.getUi()
ui.createMenu('Show/Hide Columns')
.addItem(month, 'toggleMonth')
.addToUi();
};
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheets()[0];
var count = 0;
function toggleMonth() {
count++;
var isEven = function(someNumber) {
return (someNumber % 2 === 0) ? true : false;
};
if (isEven(count) === false) {
sh.hideColumns(2, 3)
} else if (isEven(count) === true) {
sh.unhideColumn(sh.getRange('B:D'))
}
};

Programatically open a menu from menubar(Simulate the menu click programmatically for UI automation test)

MenuManager and MenuContribution items has been already created.
For the input Menu Item id/label, I need to problematically drop-down/open/display a menu item from menubar in Eclipse. I think I may need to fire some event.
This is requirement for UI Automation that Menu should be drop down automatically.
Can you please help at the earliest. I'm trying following, but here not sure how to set the x & y co-ordinates where mouse click event should be fired.
Code:
String toCompare = "File";
Menu menu = window.getShell().getMenuBar();
if(menu!=null && !menu.isDisposed()){
MenuItem[] items = menu.getItems();
for(int i=0;i<items.length;i++){
String menuText = LegacyActionTools.removeMnemonics(items[i].getText());
if(toCompare.equalsIgnoreCase(menuText)){
Event event = new Event();
event.doit = true;
event.widget = items[i];
event.type = SWT.MouseDown;
event.button = 1;
boolean success = items[i].getDisplay().post(event);
System.out.println("Could we generate the event ? "+success);
}
}
}
Why don't you use dedicated tools for UI testing, such as SWTBot. It seems typicall matche what you would do

Creating a dynamic eclipse "Welcome" page button

i am wondering, whether the code to create the buttons shown at the eclipse "Welcome" page can be found somewhere.
When you create a new workspace in eclipse, a "Welcome" page is shown at the very beginning. The page shows different type of buttons like, "What is new", "Tutorials", ...
I want to use these type of buttons, but was not able to find the source code inside eclipse.
Does somebody know how to create such a button, with hide composites and dynimic components.
You can try and explore the org.eclipse.ui.internal.WorkbenchIntroManager class, in charge of building a ViewIntroAdapterPart, based on informations found in the ViewIntroAdapterSite
From getViewIntroAdapterPart():
* #return the <code>ViewIntroAdapterPart</code> for this workbench, <code>null</code> if it
* cannot be found.
*/
/*package*/ViewIntroAdapterPart getViewIntroAdapterPart() {
IWorkbenchWindow[] windows = this.workbench.getWorkbenchWindows();
for (int i = 0; i < windows.length; i++) {
IWorkbenchWindow window = windows[i];
WorkbenchPage page = (WorkbenchPage) window.getActivePage();
if (page == null) {
continue;
}
IPerspectiveDescriptor[] perspDescs = page.getOpenPerspectives();
for (int j = 0; j < perspDescs.length; j++) {
IPerspectiveDescriptor descriptor = perspDescs[j];
IViewReference reference = page.findPerspective(descriptor)
.findView(IIntroConstants.INTRO_VIEW_ID);
if (reference != null) {
IViewPart part = reference.getView(false);
if (part != null && part instanceof ViewIntroAdapterPart) {
return (ViewIntroAdapterPart) part;
}
}
}
}
return null;
}
Each perspective contributes to the IntroPart, based on its IPerspectiveDescriptor, if it includes a ViewIntroAdapterPart.
The ViewPart will create IIntroPart, which contains the graphical visible elements.

Categories