private HtmlRadioButtonInput getRadioOption(String radioGroup, String radioOption) { for (HtmlForm form : getForms()) { List<HtmlRadioButtonInput> buttons = form.getRadioButtonsByName(radioGroup); for (HtmlRadioButtonInput button : buttons) { if (button.getValueAttribute().equals(radioOption)) { return button; } } } return null; }
@Override public String getSelectedRadio(String radioGroup) { List<HtmlRadioButtonInput> radios = getForm().getRadioButtonsByName(radioGroup); for (HtmlRadioButtonInput radio : radios) { if (radio.isChecked()) { return radio.getValueAttribute(); } } throw new RuntimeException("Unexpected state: no radio button was selected in radio group [" + radioGroup + "]. Is it possible in a real browser?"); }
/** * Makes sure that there's no JavaScript error in the new view page. */ @Test public void newViewPage() throws Exception { Folder f = createFolder(); HtmlPage p = r.createWebClient().getPage(f, "newView"); HtmlForm fm = p.getFormByName("createItem"); fm.getInputByName("name").setValueAttribute("abcView"); for (HtmlRadioButtonInput r : fm.getRadioButtonsByName("mode")) { if (r.getValueAttribute().equals(ListView.class.getName())) r.click(); } r.submit(fm); assertSame(ListView.class, f.getView("abcView").getClass()); }
/** * Add a GerritServer with default configs from the UI. * * @param serverName the name * @throws Exception if error getting URL or getting page from URL. */ private void addNewServerWithDefaultConfigs(String serverName) throws Exception { URL url = new URL(j.getURL(), newServerURL); HtmlPage page = j.createWebClient().getPage(url); HtmlForm form = page.getFormByName(newServerFormName); form.getInputByName(inputFormName).setValueAttribute(serverName); List<HtmlRadioButtonInput> radioButtons = form.getRadioButtonsByName(radioButtonName); HtmlRadioButtonInput radioButtonDefaultConfig = null; for (HtmlRadioButtonInput button : radioButtons) { if (radioButtonDefaultConfigValue.equals(button.getValueAttribute())) { radioButtonDefaultConfig = button; radioButtonDefaultConfig.setChecked(true); } } assertTrue("Failed to choose 'GerritServer with Default Configurations'", radioButtonDefaultConfig.isChecked()); j.submit(form); }
/** * Add a GerritServer by copying existing configs from the UI. * * @param newServerName the name of the new server * @param fromServerName the name of the server from which the config is copied. * @throws Exception if error getting URL or getting page from URL. */ private void addNewServerByCopyingConfig(String newServerName, String fromServerName) throws Exception { URL url = new URL(j.getURL(), newServerURL); HtmlPage page = j.createWebClient().getPage(url); HtmlForm form = page.getFormByName(newServerFormName); form.getInputByName(inputFormName).setValueAttribute(newServerName); List<HtmlRadioButtonInput> radioButtons = form.getRadioButtonsByName(radioButtonName); HtmlRadioButtonInput radioButtonCopy = null; for (HtmlRadioButtonInput button : radioButtons) { if (radioButtonCopyValue.equals(button.getValueAttribute())) { radioButtonCopy = button; radioButtonCopy.setChecked(true); } } assertTrue("Failed to choose 'Copy from Existing Server Configurations'", radioButtonCopy.isChecked()); form.getInputByName(fromInputFormName).setValueAttribute(fromServerName); j.submit(form); }