Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement workaround for Go to Definition feature HappyPath scenario #14570

Merged
merged 10 commits into from
Sep 22, 2019
3 changes: 1 addition & 2 deletions e2e/driver/ChromeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class ChromeDriver implements IDriver {
.addArguments('--no-sandbox')
.addArguments('--disable-web-security')
.addArguments('--allow-running-insecure-content');

// if 'true' run in 'headless' mode
if (TestConstants.TS_SELENIUM_HEADLESS) {
options = options.addArguments('headless');
Expand All @@ -56,8 +55,8 @@ export class ChromeDriver implements IDriver {
if (TestConstants.TS_SELENIUM_REMOTE_DRIVER_URL) {
builder = builder.usingServer(TestConstants.TS_SELENIUM_REMOTE_DRIVER_URL);
}
Copy link
Contributor

@dmytro-ndp dmytro-ndp Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looked more readable with empty line 59.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it wasn't fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant empty line between return builder;.


return builder;

}

}
2 changes: 2 additions & 0 deletions e2e/driver/ContainerInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { OcpLoginPage } from '../pageobjects/openshift/OcpLoginPage';
import { OcpWebConsolePage } from '../pageobjects/openshift/OcpWebConsolePage';
import { OcpLoginByTempAdmin } from '../pageobjects/login/OcpLoginByTempAdmin';
import { OpenWorkspaceWidget } from '../pageobjects/ide/OpenWorkspaceWidget';
import { ContextMenu } from '../pageobjects/ide/ContextMenu';
import { ITestWorkspaceUtil } from '..';

export function getContainer(): Container {
Expand All @@ -54,6 +55,7 @@ export function getContainer(): Container {
e2eContainer.bind<ICheLoginPage>(TYPES.CheLogin).to(SingleUserLoginPage).inSingletonScope();
}

e2eContainer.bind<ContextMenu>(CLASSES.ContextMenu).to(ContextMenu).inSingletonScope();
e2eContainer.bind<DriverHelper>(CLASSES.DriverHelper).to(DriverHelper).inSingletonScope();
e2eContainer.bind<Dashboard>(CLASSES.Dashboard).to(Dashboard).inSingletonScope();
e2eContainer.bind<Workspaces>(CLASSES.Workspaces).to(Workspaces).inSingletonScope();
Expand Down
29 changes: 15 additions & 14 deletions e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@ export { inversifyConfig };
export * from './inversify.types';
export * from './TestConstants';

export * from './driver/ChromeDriver';
export * from './driver/IDriver';
export * from './driver/ContainerInitializer';
export * from './driver/IDriver';
export * from './driver/ChromeDriver';
export * from './utils/ScreenCatcher';
export * from './utils/DriverHelper';
export * from './utils/NameGenerator';
export * from './utils/workspace/ITestWorkspaceUtil';
export * from './utils/workspace/WorkspaceStatus';
export * from './utils/workspace/TestWorkspaceUtil';
export * from './pageobjects/openshift/OcpLoginPage';
export * from './pageobjects/openshift/OcpWebConsolePage';
export * from './pageobjects/login/OcpLoginByTempAdmin';
export * from './pageobjects/login/ICheLoginPage';
export * from './pageobjects/login/MultiUserLoginPage';
export * from './pageobjects/login/IOcpLoginPage';
export * from './pageobjects/login/ICheLoginPage';
export * from './pageobjects/login/SingleUserLoginPage';
export * from './pageobjects/dashboard/NewWorkspace';
export * from './pageobjects/dashboard/Workspaces';
export * from './pageobjects/dashboard/workspace-details/WorkspaceDetails';
export * from './pageobjects/dashboard/workspace-details/WorkspaceDetailsPlugins';
export * from './pageobjects/dashboard/Workspaces';
export * from './pageobjects/dashboard/Dashboard';
export * from './pageobjects/dashboard/NewWorkspace';
export * from './pageobjects/ide/Terminal';
export * from './pageobjects/ide/TopMenu';
export * from './pageobjects/ide/RightToolbar';
export * from './pageobjects/ide/OpenWorkspaceWidget';
export * from './pageobjects/ide/Ide';
export * from './pageobjects/ide/Editor';
export * from './pageobjects/ide/OpenWorkspaceWidget';
export * from './pageobjects/ide/ProjectTree';
export * from './pageobjects/ide/PreviewWidget';
export * from './pageobjects/ide/GitHubPlugin';
export * from './pageobjects/ide/QuickOpenContainer';
export * from './pageobjects/ide/RightToolbar';
export * from './pageobjects/ide/ContextMenu';
export * from './pageobjects/ide/Ide';
export * from './pageobjects/ide/DebugView';
export * from './pageobjects/ide/GitHubPlugin';
export * from './pageobjects/ide/TopMenu';
export * from './pageobjects/ide/WarningDialog';
export * from './pageobjects/ide/QuickOpenContainer';
export * from './pageobjects/openshift/OcpWebConsolePage';
export * from './pageobjects/openshift/OcpLoginPage';
export * from './pageobjects/ide/PreviewWidget';
3 changes: 2 additions & 1 deletion e2e/inversify.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const CLASSES = {
ScreenCatcher: 'ScreenCatcher',
OcpLoginPage: 'OcpLoginPage',
OcpWebConsolePage: 'OcpWebConsolePage',
OpenWorkspaceWidget: 'OpenWorkspaceWidget'
OpenWorkspaceWidget: 'OpenWorkspaceWidget',
ContextMenu: 'ContextMenu'
};

export { TYPES, CLASSES };
39 changes: 39 additions & 0 deletions e2e/pageobjects/ide/ContextMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'reflect-metadata';
import { injectable, inject } from 'inversify';
import { DriverHelper } from '../../utils/DriverHelper';
import { CLASSES } from '../../inversify.types';
import { WebElement, Button, By, Key } from 'selenium-webdriver';
import { TestConstants } from '../../TestConstants';



@injectable()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken formatting in file.

Copy link
Contributor

@dmytro-ndp dmytro-ndp Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is absent line before async invokeContextMenuOnActiveElementWithKeys() method definition, and redundant line after it.

export class ContextMenu {
private static readonly SUGGESTION_WIDGET_BODY_CSS: string = 'ul.p-Menu-content';

constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) { }


async invokeContextMenuOnTheElementWithMouse(elementLocator: By, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) {
const webElement: WebElement = await this.driverHelper.waitVisibility(elementLocator, timeout);
await this.driverHelper.getAction().click(webElement, Button.RIGHT).perform();
this.waitContextMenu(timeout);
}
async invokeContextMenuOnActiveElementWithKeys(timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) {
this.driverHelper.getDriver().switchTo().activeElement().sendKeys(Key.SHIFT + Key.F10);
this.waitContextMenu(timeout);
}


async waitContextMenuAndClickOnItem(nameOfItem: string, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) {
const itemLocator: string = `//div[@class='p-Menu-itemLabel' and text()='${nameOfItem}']`;
await this.waitContextMenu();
await this.driverHelper.waitAndClick(By.xpath(itemLocator), timeout);
}

async waitContextMenu(timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) {
await this.driverHelper.waitVisibility(By.css(ContextMenu.SUGGESTION_WIDGET_BODY_CSS), timeout);
}


}
40 changes: 38 additions & 2 deletions e2e/pageobjects/ide/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ import { injectable, inject } from 'inversify';
import { DriverHelper } from '../../utils/DriverHelper';
import { CLASSES } from '../../inversify.types';
import { TestConstants } from '../../TestConstants';
import { By, Key, error } from 'selenium-webdriver';
import { By, Key, error, ActionSequence, Button } from 'selenium-webdriver';
import { Ide } from './Ide';


@injectable()
export class Editor {
private static readonly SUGGESTION_WIDGET_BODY_CSS: string = 'div.visible[widgetId=\'editor.widget.suggestWidget\']';

private static readonly ADDITIONAL_SHIFTING_TO_Y: number = 19;
private static readonly ADDITIONAL_SHIFTING_TO_X: number = 1;


constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper,
@inject(CLASSES.Ide) private readonly ide: Ide) { }

Expand Down Expand Up @@ -278,7 +283,8 @@ export class Editor {
}
}

private async getLineYCoordinates(lineNumber: number): Promise<number> {

async getLineYCoordinates(lineNumber: number): Promise<number> {
const lineNumberLocator: By = By.xpath(`//div[contains(@class, 'line-numbers') and text()='${lineNumber}']` +
`//parent::div[contains(@style, 'position')]`);

Expand All @@ -296,6 +302,36 @@ export class Editor {
return lineYCoordinate;
}

async clickOnLineAndChar(line: number, char: number) {
const yPosition: number = await this.getLineYCoordinates(line) + Editor.ADDITIONAL_SHIFTING_TO_Y;
const xPosition: number = char + Editor.ADDITIONAL_SHIFTING_TO_X;

new ActionSequence(this.driverHelper.getDriver()).
mouseMove({ x: xPosition, y: yPosition }).
click().
perform();
}

async goToDefinitionWithMouseClicking(line: number, char: number) {
const yPosition: number = await this.getLineYCoordinates(line) + Editor.ADDITIONAL_SHIFTING_TO_Y;

new ActionSequence(this.driverHelper.getDriver()).
keyDown(Key.CONTROL).
mouseMove({ x: char + Editor.ADDITIONAL_SHIFTING_TO_X, y: yPosition }).
click().
keyDown(Key.CONTROL).
perform();
}

async mouseRightButtonClick(line: number, char: number) {
const yPosition: number = await this.getLineYCoordinates(line) + Editor.ADDITIONAL_SHIFTING_TO_Y;

new ActionSequence(this.driverHelper.getDriver()).
mouseMove({ x: char + Editor.ADDITIONAL_SHIFTING_TO_X, y: yPosition }).
click(Button.RIGHT).
perform();
}

private getTabWithUnsavedStatus(tabTitle: string): By {
return By.xpath(`//div[text()='${tabTitle}']/parent::li[contains(@class, 'theia-mod-dirty')]`);
}
Expand Down
25 changes: 19 additions & 6 deletions e2e/tests/e2e_happy_path/HappyPath.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import { Terminal } from '../../pageobjects/ide/Terminal';
import { OpenWorkspaceWidget } from '../../pageobjects/ide/OpenWorkspaceWidget';
import { ICheLoginPage } from '../../pageobjects/login/ICheLoginPage';
import * as fs from 'fs';
import { ContextMenu } from '../../pageobjects/ide/ContextMenu';

const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
const ide: Ide = e2eContainer.get(CLASSES.Ide);
const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree);
const topMenu: TopMenu = e2eContainer.get(CLASSES.TopMenu);
const quickOpenContainer: QuickOpenContainer = e2eContainer.get(CLASSES.QuickOpenContainer);
const editor: Editor = e2eContainer.get(CLASSES.Editor);
const contextMenu: ContextMenu = e2eContainer.get(CLASSES.ContextMenu);
const previewWidget: PreviewWidget = e2eContainer.get(CLASSES.PreviewWidget);
const rightToolbar: RightToolbar = e2eContainer.get(CLASSES.RightToolbar);
const terminal: Terminal = e2eContainer.get(CLASSES.Terminal);
Expand Down Expand Up @@ -116,11 +118,18 @@ suite('Language server validation', async () => {
await editor.waitSuggestion(javaFileName, 'run(Class<?> primarySource, String... args) : ConfigurableApplicationContext');
});

// it's skipped because of issue https://github.com/eclipse/che/issues/14520
test.skip('Codenavigation', async () => {

test('Codenavigation', async () => {
await editor.moveCursorToLineAndChar(javaFileName, 32, 17);
await editor.performKeyCombination(javaFileName, Key.chord(Key.CONTROL, Key.F12));
await editor.waitEditorAvailable(codeNavigationClassName);
// workaround for issue: https://github.com/eclipse/che/issues/14520
try {
await editor.performKeyCombination(javaFileName, Key.chord(Key.CONTROL, Key.F12));
await editor.waitEditorAvailable(codeNavigationClassName);
} catch (err) {
if (err instanceof error.TimeoutError) {
Copy link
Contributor

@dmytro-ndp dmytro-ndp Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be clearer to have comment with link to issue.

checkCodeNavigationWithContextMenu();
}
}
});

test.skip('Yaml LS initialization', async () => {
Expand Down Expand Up @@ -290,6 +299,12 @@ async function runTask(task: string) {
await quickOpenContainer.clickOnContainerItem('Continue without scanning the task output');
}

async function checkCodeNavigationWithContextMenu() {
musienko-maxim marked this conversation as resolved.
Show resolved Hide resolved
await contextMenu.invokeContextMenuOnActiveElementWithKeys();
await contextMenu.waitContextMenuAndClickOnItem('Go to Definition');
console.log('Known isuue https://github.com/eclipse/che/issues/14520.');
}

// sometimes under high loading the first click can be failed
async function isureClickOnDebugMenu() {
try { await topMenu.selectOption('Debug', 'Open Configurations'); } catch (e) {
Expand All @@ -312,10 +327,8 @@ async function checkJavaPathCompletion() {

await projectTree.expandPathAndOpenFile(projectName, classPathFilename);
await editor.waitEditorAvailable(classPathFilename);

await editor.type(classPathFilename, Key.chord(Key.CONTROL, 'a'), 1);
await editor.performKeyCombination(classPathFilename, Key.DELETE);

await editor.type(classPathFilename, classpathText, 1);
await editor.waitTabWithSavedStatus(classPathFilename);
}
Expand Down
3 changes: 2 additions & 1 deletion e2e/utils/DriverHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export class DriverHelper {
async waitOpenningSecondWindow(timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT) {
await this.driver.wait(async () => {
const handles: string[] = await this.driver.getAllWindowHandles();
if (handles.length > 1) {
if (handles.length > 1) {
return true;
}
}, timeout);
Expand All @@ -451,4 +451,5 @@ export class DriverHelper {
handles.splice(handles.indexOf(mainWindowHandle), 1);
await this.driver.switchTo().window(handles[0]);
}

}