public AvatarUploaderDialog uploadImage(File imageFile) { if (!imageFile.exists()) { throw new IllegalArgumentException("The image was not found in the path."); } // Can't use OS file picker with webdriver but we can type file path to the input // Hack: can't type to hidden inputs so we must show it first uploadFileField.javascript().execute("AJS.$(arguments[0]).show()"); uploadFileField.type(imageFile.getAbsolutePath()); return this; }
public <T> T execute(@Nonnull Class<T> expectedReturnType, @Nonnull String moduleId, @Nonnull String functionName, @Nonnull String... args) { checkNotNull(expectedReturnType, "expectedReturnType"); String script = format("return require('%s').%s(%s)", moduleId, functionName, Joiner.on(',').join(args)); return elementFinder.find(By.tagName(Elements.TAG_BODY)).javascript().execute(expectedReturnType, script); } }
public SpaceDetailsDialog uploadImage(File imageFile) { if (!imageFile.exists()) { throw new IllegalArgumentException("The image was not found in the path."); } // Can't use OS file picker with webdriver but we can type file path to the input // Hack: can't type to hidden inputs so we must show it first uploadFileField.javascript().execute("AJS.$(arguments[0]).show()"); uploadFileField.type(imageFile.getAbsolutePath()); return this; }
private List<String> getContracts(String method) { String contractsString = (String) testPage.getTestResult().javascript() .execute("return AJS.TestContractManager && AJS.TestContractManager." + method + "().join();"); String[] contracts = contractsString == null ? new String[]{} : contractsString.split(","); return Lists.newArrayList(contracts); }
/** * Focus on multi select, input some value and blur * * @param query input for multi select * @return this multi select instance */ public MultiSelect freeInput(CharSequence query) { textArea.type(query); textArea.javascript().execute("arguments[0].blur()"); return this; }
public void deactivateDropDownIfPresent() { if (dropDownLinkId.isPresent()) { List<PageElement> elementList = elementFinder.findAll(By.id(dropDownLinkId.get())); if (elementList.size() > 0) { waitUntilTrue(elementList.get(0).timed().isVisible()); if (elementList.get(0).hasClass("aui-dropdown2-active")) { elementList.get(0).javascript().mouse().click(); } } } }
public void deactivateDropDownIfPresent() { if (dropDownLinkId.isPresent()) { List<PageElement> elementList = elementFinder.findAll(By.id(dropDownLinkId.get())); if (elementList.size() > 0) { waitUntilTrue(elementList.get(0).timed().isVisible()); if (elementList.get(0).hasClass("aui-dropdown2-active")) { elementList.get(0).javascript().mouse().click(); } } } }
private void whyIntegrationTestingSux() { // START HACK because WebDriver in its infinite wisdom thinks that the whole confirm dialog is not visible // (not that we are making it easy for WebDriver to figure out things, by opening a dialog inside // an iframe and what not) // it will not allow to click that freakin' button - obviously - because user couldn't click it. So // considerate of you WebDriver, thanks. We have to deal with this in a well-established way // of using Javascript to do the job (back to Selenium1, yaaay) confirmDeleteDialog.find(By.className("confirm")).javascript().execute("jQuery(arguments[0]).click();"); // END HACK <crying> }
public BasicAccessAuthenticationSection modifyAtlToken() { elementFinder.find(By.tagName(PageElements.BODY)).javascript() .execute("AJS.$('.auth-config input[name=\"atl_token\"]').val('hacker!')"); return this; }
/** * Executes JavaScript against the page, updating the 'atl_token' value for the form. This simulates a malicious * user attempting to hack the page. * * @return this */ public TrustedApplicationAuthenticationSection modifyAtlToken() { elementFinder.find(By.tagName(BODY)).javascript() .execute("AJS.$('.auth-config .edit input[name=\"atl_token\"]').val('hacker!')"); return this; }
public DeleteCommentConfirmationDialog openDeleteDialog() { //Need to use JS because element is only visible on :hover item.find(By.className("delete-comment")).javascript().execute("AJS.$(arguments[0]).click();"); return binder.bind(DeleteCommentConfirmationDialog.class, issueKey); } }
public WatchersComponent removeWatcher(String watcher) { Tracer tracer = traceContext.checkpoint(); // need to execute javascript because it is only visible on :hover watchersDialog.find(By.cssSelector("li[data-username=" + watcher + "] .item-delete")).javascript().execute("jQuery(arguments[0]).click()"); traceContext.waitFor(tracer, "jira.issue.watcher.deleted"); return this; }
private WebElement getDragHandle(String tab) { final PageElement tabEl = elementFinder.find(By.cssSelector(".menu-item[data-name='" + tab + "']")); tabEl.javascript().execute("jQuery(arguments[0]).addClass('wd-activate-hover')"); // hacking css :hover return driver.findElement(By.cssSelector(".menu-item[data-name='" + tab + "'] .tab-draghandle")); }
public <T> T selectBlueprint(BlueprintDialog createDialog, Class<T> pageClass, String createDialogWebItemKey) { // blueprint may not be visible, we should first scroll it into view PageElement blueprint = finder.find(By.cssSelector("li[data-item-module-complete-key='" + createDialogWebItemKey + "']")); blueprint.javascript().execute("arguments[0].scrollIntoView(true);"); createDialog.selectContentType(createDialogWebItemKey); return createDialog.waitForSubmitEnabledAndSubmit(pageClass); }
private void preventTheEvil() { // get out of any IFrame webDriver.switchTo().defaultContent(); // just make it WOOOORK finder.find(body()).javascript().execute("window.onbeforeunload=null;"); }
private PageElement openIssueActionsMenu() { PageElement issueActionsTrigger = issue.find(By.className("issue-actions-trigger")); // HACK: Button appears on mouseover, which fails in webdriver, so use javascript to make element appear and be clickable issueActionsTrigger.javascript().execute("AJS.$(arguments[0]).addClass('active');"); Poller.waitUntilTrue("Issue actions trigger is not visible.", issueActionsTrigger.timed().isVisible()); issueActionsTrigger.click(); return finder.find(By.id("actions_" + id + "_drop")); } }
public ViewIssuePage confirm() { PageElement deleteButton = locator.find(By.id("comment-delete-submit")); deleteButton.javascript().execute("AJS.$('#" + DIALOG_ELEMENT_ID + "').addClass('" + DIRTY_FLAG_CLASS + "');"); Tracer tracer = traceContext.checkpoint(); deleteButton.click(); Poller.waitUntilFalse(dialog.timed().hasClass(DIRTY_FLAG_CLASS)); ViewIssuePage viewIssuePage = pageBinder.bind(ViewIssuePage.class, issueKey); return viewIssuePage.waitForAjaxRefresh(tracer); }
public EditScreenTab removeField(String field) { final PageElement row = findRow(field); row.javascript().execute("jQuery(arguments[0]).addClass('active')"); // hacking css :hover row.find(By.className("aui-restfultable-delete")).click(); Poller.waitUntilFalse(hasField(field)); return this; }
public void sync() { rootElement.javascript().mouse().mouseover(); final PageElement syncIcon = getSyncIcon(); waitUntilTrue(syncIcon.timed().isPresent()); TimedQuery<Long> lastSync = Queries.forSupplier(timeouts, () -> NumberUtils.toLong(syncIcon.getAttribute("data-last-sync")), TimeoutType.SLOW_PAGE_LOAD); final long lastSyncBefore = lastSync.now(); syncIcon.javascript().mouse().click(); waitUntil(lastSync, greaterThan(lastSyncBefore)); waitUntilFalse(syncIcon.withTimeout(TimeoutType.SLOW_PAGE_LOAD).timed().hasClass("running")); }
@WaitUntil public void isAt() { // TODO wrong place to initialize stuff table = elementFinder.find(By.id("tab-" + tabId)); Poller.waitUntilTrue(table.timed().isPresent()); Poller.waitUntilFalse(table.timed().hasClass("loading")); fieldPicker = pageBinder.bind(SingleSelect.class, elementFinder.find(By.className("available-fields"))); tab = elementFinder.find(By.cssSelector(".menu-item[data-tab='" + tabId + "']")); tab.javascript().execute("jQuery(arguments[0]).addClass('wd-activate-hover')"); deleteTab = tab.find(By.className("delete-tab")); }