List of usage examples for java.awt Robot Robot
public Robot() throws AWTException
From source file:com.seleniumtests.driver.CustomEventFiringWebDriver.java
/** * send keys to desktop//from ww w . j a v a 2 s .c o m * This is useful for typing special keys like ENTER * @param keys */ public static void sendKeysToDesktop(List<Integer> keyCodes, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Robot robot = new Robot(); WaitHelper.waitForSeconds(1); for (Integer key : keyCodes) { robot.keyPress(key); robot.keyRelease(key); } } catch (AWTException e) { throw new ScenarioException("could not initialize robot to type keys: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.sendKeysWithKeyboard(keyCodes); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }
From source file:com.ucuenca.pentaho.plugin.step.FusekiLoaderDialog.java
/** * This method is called by Spoon when the user opens the settings dialog of * the step. It should open the dialog and return only once the dialog has * been closed by the user.// ww w . j av a2 s . c o m * * If the user confirms the dialog, the meta object (passed in the * constructor) must be updated to reflect the new step settings. The * changed flag of the meta object must reflect whether the step * configuration was changed by the dialog. * * If the user cancels the dialog, the meta object must not be updated, and * its changed flag must remain unaltered. * * The open() method must return the name of the step after the user has * confirmed the dialog, or null if the user cancelled the dialog. */ public String open() { // store some convenient SWT variables Shell parent = getParent(); Display display = parent.getDisplay(); // SWT code for preparing the dialog shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); props.setLook(shell); setShellImage(shell, meta); // Save the value of the changed flag on the meta object. If the user // cancels // the dialog, it will be restored to this saved value. // The "changed" variable is inherited from BaseStepDialog changed = meta.hasChanged(); // The ModifyListener used on all controls. It will update the meta // object to // indicate that changes are being made. ModifyListener lsMod = new ModifyListener() { public void modifyText(ModifyEvent e) { meta.setChanged(); } }; // ------------------------------------------------------- // // SWT code for building the actual settings dialog // // ------------------------------------------------------- // FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout(formLayout); shell.setText(BaseMessages.getString(PKG, "FusekiLoader.Shell.Title")); int middle = props.getMiddlePct(); int margin = Const.MARGIN; // Stepname line wlStepname = new Label(shell, SWT.RIGHT); wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName")); props.setLook(wlStepname); fdlStepname = new FormData(); fdlStepname.left = new FormAttachment(0, 0); fdlStepname.right = new FormAttachment(middle, -margin); fdlStepname.top = new FormAttachment(0, margin); wlStepname.setLayoutData(fdlStepname); wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); wStepname.setText(stepname); props.setLook(wStepname); wStepname.addModifyListener(lsMod); fdStepname = new FormData(); fdStepname.left = new FormAttachment(middle, 0); fdStepname.top = new FormAttachment(0, margin); fdStepname.right = new FormAttachment(100, 0); wStepname.setLayoutData(fdStepname); // output field value Label wlValName = new Label(shell, SWT.RIGHT); wlValName.setText(BaseMessages.getString(PKG, "FusekiLoader.FieldName.Label")); props.setLook(wlValName); FormData fdlValName = new FormData(); fdlValName.left = new FormAttachment(0, 0); fdlValName.right = new FormAttachment(middle, -margin); fdlValName.top = new FormAttachment(wStepname, margin); // fdlValName.top = new FormAttachment(10, margin); wlValName.setLayoutData(fdlValName); wHelloFieldName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wHelloFieldName); wHelloFieldName.addModifyListener(lsMod); FormData fdValName = new FormData(); fdValName.left = new FormAttachment(middle, 0); // fdValName.right = new FormAttachment(100, 0); fdValName.top = new FormAttachment(wlStepname, margin + 10); wHelloFieldName.setLayoutData(fdValName); wHelloFieldName.setEditable(false); // ------------ wLoadFile = new Button(shell, SWT.PUSH); wLoadFile.setText(BaseMessages.getString(PKG, "FusekiLoader.FieldName.LoadFile")); wLoadFile.setToolTipText(BaseMessages.getString(PKG, "System.Tooltip.ChooseFile")); FormData fdChooseFile = new FormData(); fdChooseFile = new FormData(); fdChooseFile.right = new FormAttachment(100, 0); fdChooseFile.top = new FormAttachment(wStepname, margin); wLoadFile.setLayoutData(fdChooseFile); fdValName.right = new FormAttachment(wLoadFile, 0); // precatch data wPreCatch = new Button(shell, SWT.PUSH); wPreCatch.setText(BaseMessages.getString(PKG, "System.Tooltip.Precatch")); wPreCatch.setToolTipText(BaseMessages.getString(PKG, "System.Tooltip.Precatch")); FormData fdwPreCatch = new FormData(); fdwPreCatch = new FormData(); fdwPreCatch.right = new FormAttachment(100, 0); fdwPreCatch.top = new FormAttachment(wLoadFile, margin); wPreCatch.setLayoutData(fdwPreCatch); // OK and cancel buttons wOK = new Button(shell, SWT.PUSH); wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); // label to say fuseki parameters Label wlabelFuseki = new Label(shell, SWT.RIGHT); wlabelFuseki.setText(BaseMessages.getString(PKG, "FusekiLoader.label.FusekiParameters")); props.setLook(wlabelFuseki); FormData fdlValName1 = new FormData(); fdlValName1.left = new FormAttachment(0, 0); fdlValName1.right = new FormAttachment(middle, -margin); fdlValName1.top = new FormAttachment(wHelloFieldName, margin + 10); wlabelFuseki.setLayoutData(fdlValName1); // label to serviceName Label wlabelServiceName = new Label(shell, SWT.RIGHT); wlabelServiceName.setText(BaseMessages.getString(PKG, "FusekiLoader.label.FusekiservName")); props.setLook(wlabelServiceName); FormData fdlValservName = new FormData(); fdlValservName.left = new FormAttachment(0, 0); fdlValservName.right = new FormAttachment(middle, -margin); fdlValservName.top = new FormAttachment(wlabelFuseki, margin + 5); wlabelServiceName.setLayoutData(fdlValservName); // text para service name wTextServName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wTextServName); wTextServName.setText("myservice"); // wStepname.addModifyListener(lsMod); FormData fdtextservName = new FormData(); fdtextservName.left = new FormAttachment(middle, 0); fdtextservName.top = new FormAttachment(wlabelFuseki, margin + 5); fdtextservName.right = new FormAttachment(100, 0); wTextServName.setLayoutData(fdtextservName); wTextServName.addVerifyListener(new VerifyListener() { public void verifyText(VerifyEvent event) { event.text = event.text.replaceAll("[^A-Za-z0-9]", ""); } }); // label to service Port Label wlabelServicePort = new Label(shell, SWT.RIGHT); wlabelServicePort.setText(BaseMessages.getString(PKG, "FusekiLoader.label.FusekiservPort")); props.setLook(wlabelServicePort); FormData fdlValservPort = new FormData(); fdlValservPort.left = new FormAttachment(0, 0); fdlValservPort.right = new FormAttachment(middle, -margin); fdlValservPort.top = new FormAttachment(wlabelServiceName, margin + 5); wlabelServicePort.setLayoutData(fdlValservPort); // text para service Port wTextServPort = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wTextServPort); wTextServPort.setText("3030"); // wStepname.addModifyListener(lsMod); FormData fdtextservPort = new FormData(); fdtextservPort.left = new FormAttachment(middle, 0); fdtextservPort.top = new FormAttachment(wlabelServiceName, margin + 5); // fdtextservPort.right = new FormAttachment(100, 0); wTextServPort.setLayoutData(fdtextservPort); //agregando Base URI // label to service Port Label wlabelBaseUri = new Label(shell, SWT.RIGHT); wlabelBaseUri.setText(BaseMessages.getString(PKG, "FusekiLoader.label.BaseUri")); props.setLook(wlabelBaseUri); FormData fdlBaseUri = new FormData(); fdlBaseUri.left = new FormAttachment(0, 0); fdlBaseUri.right = new FormAttachment(middle, -margin); fdlBaseUri.top = new FormAttachment(wlabelServicePort, margin + 5); wlabelBaseUri.setLayoutData(fdlBaseUri); // text para service Port wTextBaseUri = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wTextBaseUri); wTextBaseUri.setText(""); // wStepname.addModifyListener(lsMod); FormData fdtextBaseUri = new FormData(); fdtextBaseUri.left = new FormAttachment(middle, 0); fdtextBaseUri.top = new FormAttachment(wlabelServicePort, margin + 5); fdtextBaseUri.right = new FormAttachment(100, 0); wTextBaseUri.setLayoutData(fdtextBaseUri); // confgiracion table empieza aqui table = new Table(shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); table.setLinesVisible(true); table.setHeaderVisible(true); String[] titles = { BaseMessages.getString(PKG, "Fuseki.table.col1"), BaseMessages.getString(PKG, "Fuseki.table.col2"), }; for (int i = 0; i < titles.length; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(titles[i]); column.setWidth(160); } //verifico si hayconfiguracion en el meta ArrayList<String> myListPropiedades = new ArrayList<String>(); ArrayList<String> myListValores = new ArrayList<String>(); if (meta.getListaPropiedades() != null) { myListPropiedades = cleanspaces(meta.getListaPropiedades()); myListValores = cleanspaces(meta.getListaValores()); if (!myListPropiedades.get(0).trim().isEmpty()) { // valido que este // cargado con // algun valor // para // agregarlo a // la tabla TableItem[] items = table.getItems(); for (int i = 0; i < myListPropiedades.size(); i++) { new TableItem(table, SWT.NONE); } } } else {//vacio for (int i = 0; i < 3; i++) { //4 new TableItem(table, SWT.NONE); } } //--------------- final TableItem[] items = table.getItems(); final TableEditor editor2 = new TableEditor(table); for (int i = 0; i < items.length; i++) { TableEditor editor = new TableEditor(table); CCombo combo = new CCombo(table, SWT.NONE); combo.setText("Propiedades"); combo.add("fuseki:dataset"); combo.add("fuseki:serviceReadGraphStore"); combo.add("fuseki:serviceQuery"); combo.add("fuseki:serviceUpload"); combo.add("fuseki:serviceUpdate"); combo.add("fuseki:serviceReadWriteGraphStore"); //JO adding fulltext support combo.add("lucene:fulltext"); //JO* combo.setEditable(false); //selecciono la parte del combo combo.select(i); if (meta.getListaPropiedades() != null) { //si existe se carga la configuracion anterior String propiedad = myListPropiedades.get(i).trim(); if (propiedad.compareTo("fuseki:dataset") == 0) { combo.select(0); } else if (propiedad.compareTo("fuseki:serviceReadGraphStore") == 0) { combo.select(1); } else if (propiedad.compareTo("fuseki:serviceQuery") == 0) { combo.select(2); } else if (propiedad.compareTo("fuseki:serviceUpload") == 0) { combo.select(3); } else if (propiedad.compareTo("fuseki:serviceUpdate") == 0) { combo.select(4); } else if (propiedad.compareTo("fuseki:serviceReadWriteGraphStore") == 0) { combo.select(5); } //JO adding fulltext support else if (propiedad.compareTo("lucene:fulltext") == 0) { combo.select(6); } //JO* } editor.grabHorizontal = true; items[i].setData(editor); editor.setEditor(combo, items[i], 0); combos.add(combo); editors.add(editor); } table.setSize(table.computeSize(SWT.DEFAULT, 200)); //aqui hago que sea editable la segunda columna final TableEditor editor = new TableEditor(table); //The editor must have the same size as the cell and must //not be any smaller than 50 pixels. final int EDITABLECOLUMN = 1; table.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // Clean up any previous editor control Control oldEditor = editor.getEditor(); if (oldEditor != null) oldEditor.dispose(); // Identify the selected row TableItem item = (TableItem) e.item; if (item == null) return; // The control that will be the editor must be a child of the Table Text newEditor = new Text(table, SWT.NONE); newEditor.setText(item.getText(EDITABLECOLUMN)); newEditor.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { Text text = (Text) editor.getEditor(); editor.getItem().setText(EDITABLECOLUMN, text.getText()); } }); newEditor.selectAll(); newEditor.setFocus(); editor.setEditor(newEditor, item, EDITABLECOLUMN); } }); //aquie se precargar valores de las tres primeras filas if (meta.getListaPropiedades() != null) { for (int i = 0; i < myListValores.size(); i++) { table.getItem(i).setText(1, myListValores.get(i).trim()); } } else { for (int i = 0; i < 3; i++) { table.getItem(i).setText(1, valoresPrecargados[i]); } } //aqui se borra supuestamente Menu menu = new Menu(shell, SWT.POP_UP); table.setMenu(menu); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText("Delete Selection"); item.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { TableItem[] items = table.getItems(); for (TableItem item : items) { if (table.indexOf(item) == table.getSelectionIndex()) { if (item.getData() != null) { TableEditor ed = (TableEditor) item.getData(); int i = editors.indexOf(ed); CCombo cmb = (CCombo) combos.get(i); cmb.dispose(); ed.dispose(); editors.remove(ed); combos.remove(cmb); } int index = table.indexOf(item); table.remove(index); if (index > 0) { // table.setSelection(table.getItem(0)); } //item.dispose(); } } wHelloFieldName.setFocus(); try { Robot r = new Robot(); //PointerInfo a = MouseInfo.getPointerInfo(); //Point b = a.getLocation(); r.mousePress(InputEvent.BUTTON1_DOWN_MASK); } catch (AWTException e) { // TODO Auto-generated catch block e.printStackTrace(); } //TableEditor editor = new TableEditor(table); //item.dispose() //editor.getEditor().redraw() ; // int fil = table.getSelectionIndex(); // table.remove(table.getSelectionIndices()); // } }); // --------------------------------------------------------- // table.setItemCount(3);// para ver las filas por defecto // parametrizando aqui le ubico en el formulario fdmitabla = new FormData(); fdmitabla.left = new FormAttachment(1, 0); fdmitabla.right = new FormAttachment(100, 1); fdmitabla.top = new FormAttachment(wTextBaseUri, margin); // boton ok y cancel al ultimo fdmitabla.height = 280; table.setLayoutData(fdmitabla); //agregar fila automaticamente table.setEnabled(true); table.addListener(SWT.MouseDown, new Listener() { public void handleEvent(Event event) { if ((table.getItemCount() - 1) == table.getSelectionIndex()) { Rectangle clientArea = table.getClientArea(); Point pt = new Point(event.x, event.y); agregarfila(); } } }); table.addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event arg0) { // TODO Auto-generated method stub if (arg0.keyCode == SWT.DEL) { //System.out.println("aplasto Borrar"); } } }); // --------------------crear fila nueva // ---------------------------------------- // label to choose output Label wlValNameO = new Label(shell, SWT.RIGHT); wlValNameO.setText(BaseMessages.getString(PKG, "FusekiLoader.FieldName.LabelOutput")); props.setLook(wlValNameO); FormData fdlValNameO = new FormData(); fdlValNameO.left = new FormAttachment(middle, 0); fdlValNameO.right = new FormAttachment(middle, -margin); fdlValNameO.top = new FormAttachment(table, margin + 5); // fdlValName.top = new FormAttachment(10, margin); wlValNameO.setLayoutData(fdlValNameO); // text to output wChooseOutput = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wChooseOutput); // wChooseOutput.addModifyListener(lsMod); FormData fdValNameO = new FormData(); fdValNameO.left = new FormAttachment(middle, 0); // fdValNameO.right = new FormAttachment(100, 0); fdValNameO.top = new FormAttachment(table, margin + 5); wChooseOutput.setLayoutData(fdValNameO); wChooseOutput.setEditable(false); // booton to choose directory wChooseDirectory = new Button(shell, SWT.PUSH | SWT.SINGLE | SWT.MEDIUM | SWT.BORDER); props.setLook(wChooseDirectory); wChooseDirectory.setText(BaseMessages.getString(PKG, "FusekiLoader.Output.ChooseDirectory")); wChooseDirectory.setToolTipText(BaseMessages.getString(PKG, "System.Tooltip.ChooseDirectory")); FormData fdChooseDirectory = new FormData(); fdChooseDirectory = new FormData(); fdChooseDirectory.right = new FormAttachment(100, 0); fdChooseDirectory.top = new FormAttachment(table, margin + 5); wChooseDirectory.setLayoutData(fdChooseDirectory); fdValNameO.right = new FormAttachment(wChooseDirectory, -margin); wChooseOutput.setLayoutData(fdValNameO); // checkbox star service wCheckService = new Button(shell, SWT.PUSH); props.setLook(wCheckService); wCheckService.setText(BaseMessages.getString(PKG, "FusekiLoader.Check.label")); wCheckService.setToolTipText(BaseMessages.getString(PKG, "FukekiLoader.Check.tooltip")); FormData fdBotonCheck = new FormData(); fdBotonCheck = new FormData(); fdBotonCheck.right = new FormAttachment(middle, -margin); fdBotonCheck.top = new FormAttachment(wlValNameO, margin + 5); // fdBotonCheck.right = new FormAttachment(wOpenBrowser, margin); wCheckService.setLayoutData(fdBotonCheck); wStopService = new Button(shell, SWT.PUSH); props.setLook(wStopService); wStopService.setText(BaseMessages.getString(PKG, "FusekiLoader.Stopservice")); FormData fdBotonstop = new FormData(); fdBotonstop = new FormData(); fdBotonstop.left = new FormAttachment(wCheckService, margin); fdBotonstop.top = new FormAttachment(wlValNameO, margin + 5); wStopService.setEnabled(false); wStopService.setLayoutData(fdBotonstop); wOpenBrowser = new Button(shell, SWT.PUSH); props.setLook(wOpenBrowser); wOpenBrowser.setText(BaseMessages.getString(PKG, "FusekiLoader.BotonBrowser")); wOpenBrowser.setToolTipText(BaseMessages.getString(PKG, "FukekiLoader.BotonBrowser.tooltip")); FormData fdBotonBrowser = new FormData(); fdBotonBrowser = new FormData(); fdBotonBrowser.left = new FormAttachment(wStopService, margin); fdBotonBrowser.top = new FormAttachment(wlValNameO, margin + 5); wOpenBrowser.setLayoutData(fdBotonBrowser); wOpenBrowser.setEnabled(false); // ------------------------------------ how start service // label how to startService Label wLabelHowService = new Label(shell, SWT.RIGHT); wLabelHowService.setText(BaseMessages.getString(PKG, "FusekiLoader.label.HowService")); props.setLook(wLabelHowService); FormData fdlHowService = new FormData(); fdlHowService.left = new FormAttachment(0, 0); fdlHowService.right = new FormAttachment(middle, -margin); fdlHowService.top = new FormAttachment(wCheckService, margin + 5); wLabelHowService.setLayoutData(fdlHowService); // text para service Port wTextHowService = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); wTextHowService.setData(new GridData(GridData.FILL_BOTH)); wTextHowService.setText( "To start the service, go to the terminal and type ${outputDir}/fuseki-server --port=${servicePort} --config=config.ttl To access the service go to: http://localhost:${servicePort}/control-panel.tpl To perform some queries make a request to http://localhost:3030/${serviceName}/query?query=${your-query}"); props.setLook(wTextHowService); // wStepname.addModifyListener(lsMod); FormData fdtextservHow = new FormData(); fdtextservHow.left = new FormAttachment(middle, 0); fdtextservHow.top = new FormAttachment(wCheckService, margin + 10); fdtextservHow.right = new FormAttachment(100, 0); wTextHowService.setLayoutData(fdtextservHow); wTextHowService.setEditable(false); // ---------------------------- BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, wTextHowService); // Add listeners for cancel and OK lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; lsLoadFile = new Listener() { public void handleEvent(Event e) { LoadFile(); } }; lsChooseDirectory = new Listener() { public void handleEvent(Event e) { ChooseDirectory(); } }; lsCheckService = new Listener() { public void handleEvent(Event e) { StartService(); } }; lsStopService = new Listener() { public void handleEvent(Event e) { stop(); } }; lsUpdateInstrucctions = new ModifyListener() { public void handleEvent(Event e) { UpdateInstrucctions(); } public void modifyText(ModifyEvent arg0) { UpdateInstrucctions(); } }; lsOpenBrowser = new Listener() { public void handleEvent(Event e) { OpenBrowser(); } }; lsPrecatch = new Listener() { public void handleEvent(Event e) { PreCargar(); } }; /* * lsAddRow = new Listener() { public void handleEvent(Event e) { * agregarfila(); } }; */ wCancel.addListener(SWT.Selection, lsCancel); wOK.addListener(SWT.Selection, lsOK); wLoadFile.addListener(SWT.Selection, lsLoadFile); wOpenBrowser.addListener(SWT.Selection, lsOpenBrowser); wCheckService.addListener(SWT.Selection, lsCheckService); this.wChooseDirectory.addListener(SWT.Selection, lsChooseDirectory); this.wPreCatch.addListener(SWT.Selection, lsPrecatch); this.wStopService.addListener(SWT.Selection, lsStopService); wTextServPort.addListener(SWT.Verify, new Listener() { public void handleEvent(Event e) { String string = e.text; char[] chars = new char[string.length()]; string.getChars(0, chars.length, chars, 0); for (int i = 0; i < chars.length; i++) { if (!('0' <= chars[i] && chars[i] <= '9')) { e.doit = false; return; } } } }); wTextServName.addModifyListener(lsUpdateInstrucctions); wTextServPort.addModifyListener(lsUpdateInstrucctions); wChooseOutput.addModifyListener(lsUpdateInstrucctions); // default listener (for hitting "enter") lsDef = new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; wStepname.addSelectionListener(lsDef); wHelloFieldName.addSelectionListener(lsDef); // Detect X or ALT-F4 or something that kills this window and cancel the // dialog properly shell.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } }); // Set/Restore the dialog size based on last position on screen // The setSize() method is inherited from BaseStepDialog setSize(); // populate the dialog with the values from the meta object populateDialog(); // restore the changed flag to original value, as the modify listeners // fire during dialog population meta.setChanged(changed); // open dialog and enter event loop shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } // at this point the dialog has closed, so either ok() or cancel() have // been executed // The "stepname" variable is inherited from BaseStepDialog return stepname; }
From source file:com.jaspersoft.studio.property.color.chooser.AdvancedColorWidget.java
/** * Read the color under the mouse position and set it as the current color. This * is done only if JSS or one of its components are focused. It is necessary to control * this dialog and its content because it modal, so every other component of JSS can not be focused *//*from w ww. ja va2 s. co m*/ private void checkColorPicker() { if (!isDisposed() && (getShell().isFocusControl() || checkControlFocused(getShell().getChildren()))) { Robot robot; try { robot = new Robot(); Point pos = Display.getCurrent().getCursorLocation(); java.awt.Color color = robot.getPixelColor(pos.x, pos.y); RGB rgbColor = new RGB(color.getRed(), color.getGreen(), color.getBlue()); colorsSelector.setSelectedColor(rgbColor, false); updateText(rgbColor, rgbColor.getHSB(), null); } catch (AWTException e) { e.printStackTrace(); } } }
From source file:SwiftSeleniumWeb.WebHelper.java
/** * This class performs the reuired action on an element * //from w w w . ja v a2 s. c om * @param imageType * @param controlType * @param controlId * @param controlName * @param ctrlValue * @param logicalName * @param action * @param webElement * @param Results * @param strucSheet * @param valSheet * @param rowIndex * @param rowcount * @param rowNo * @param colNo * @return * @throws Exception */ @SuppressWarnings("incomplete-switch") public static String doAction(String imageType, String controlType, String controlId, String controlName, String ctrlValue, String logicalName, String action, WebElement webElement, Boolean Results, HSSFSheet strucSheet, HSSFSheet valSheet, int rowIndex, int rowcount, String rowNo, String colNo) throws Exception { List<WebElement> WebElementList = null; String currentValue = null; String uniqueNumber = ""; ControlTypeEnum controlTypeEnum = ControlTypeEnum.valueOf(controlType); ControlTypeEnum actionName = ControlTypeEnum.valueOf(action.toString()); if (controlType.contains("Robot") && !isIntialized) { robot = new Robot(); isIntialized = true; } if (action.toString().equalsIgnoreCase("I") && !ctrlValue.equalsIgnoreCase("") || action.toString().equalsIgnoreCase("Read") || action.toString().equalsIgnoreCase("Write") || action.toString().equalsIgnoreCase("V") && !ctrlValue.equalsIgnoreCase("") || action.toString().equalsIgnoreCase("NC") || action.toString().equalsIgnoreCase("T") && !ctrlValue.equalsIgnoreCase("")) { try { switch (controlTypeEnum) { case WebEdit: switch (actionName) { case Read: uniqueNumber = ReadFromExcel(ctrlValue); webElement.clear(); webElement.sendKeys(uniqueNumber); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case I: if (!ctrlValue.equalsIgnoreCase("null")) { webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.clear(); webElement.sendKeys(ctrlValue); } else { webElement.clear(); } break; case V: currentValue = webElement.getText(); break; } break; case WebButton: switch (actionName) { case I: if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) { webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.click(); } break; case NC: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.click(); break; case V: if (webElement.isDisplayed()) { if (webElement.isEnabled() == true) currentValue = "True"; else currentValue = "False"; } } break; case WebElement: switch (actionName) { case I: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.click(); break; case Read: uniqueNumber = ReadFromExcel(ctrlValue); webElement.clear(); webElement.sendKeys(uniqueNumber); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case V: boolean textPresent = false; textPresent = webElement.getText().contains(ctrlValue); if (textPresent == false) currentValue = webElement.getText(); else currentValue = ctrlValue; break; } break; case JSScript: ((JavascriptExecutor) Automation.driver).executeScript(controlName, ctrlValue); break; case Wait: Thread.sleep(Integer.parseInt(controlName) * 1000); break; case CheckBox: switch (actionName) { case I: if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) { webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.click(); } break; case NC: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.click(); break; } break; case Radio: switch (actionName) { case I: if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) { webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); if (!webElement.isSelected()) { webElement.click(); } } break; case NC: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); if (!webElement.isSelected()) { webElement.click(); } break; case V: if (webElement.isSelected()) { currentValue = webElement.getAttribute(controlName.toString()); } break; } break; case WebLink: case CloseWindow://added this Case to bypass page loading after clicking the event switch (actionName) { case Read: uniqueNumber = ReadFromExcel(ctrlValue); WebElementList = getElementsByType(controlId, controlName, controlType, imageType, uniqueNumber); webElement = GetControlByIndex("", WebElementList, controlId, controlName, controlType, uniqueNumber); webElement.click(); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case I: if (controlId.equalsIgnoreCase("LinkValue")) { webElement.click(); } else { if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) { webElement.click(); } } break; case NC: webElement.click(); break; } break; case WaitForJS: waitForCondition(); break; case ListBox: case WebList: switch (actionName) { case Read: uniqueNumber = ReadFromExcel(ctrlValue); new Select(webElement).selectByVisibleText(uniqueNumber); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case I: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); ExpectedCondition<Boolean> isTextPresent = CommonExpectedConditions .textToBePresentInElement(webElement, ctrlValue); if (isTextPresent != null) { if (webElement != null) { new Select(webElement).selectByVisibleText(ctrlValue); } } break; case V: currentValue = new Select(webElement).getFirstSelectedOption().getText(); if (currentValue.isEmpty()) { currentValue = new Select(webElement).getFirstSelectedOption().getAttribute("value"); } break; } break; case IFrame: Automation.driver = Automation.driver.switchTo().frame(controlName); break; case Browser: //Thread.sleep(3000); //DS:Check if required Set<String> handlers = Automation.driver.getWindowHandles(); handlers = Automation.driver.getWindowHandles(); for (String handler : handlers) { Automation.driver = Automation.driver.switchTo().window(handler); if (Automation.driver.getTitle().equalsIgnoreCase(controlName)) { System.out.println("Focus on window with title: " + Automation.driver.getTitle()); break; } } break; case URL: switch (actionName) { case I: Automation.driver.navigate().to(ctrlValue); break; case NC: break; } break; case Menu: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.click(); break; case Alert: switch (actionName) { case V: Alert alert = Automation.driver.switchTo().alert(); if (alert != null) { currentValue = alert.getText(); System.out.println(currentValue); alert.accept(); } break; } break; case WebImage: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.click(); Thread.sleep(5000); for (int Seconds = 0; Seconds <= Integer .parseInt(Automation.configHashMap.get("TIMEOUT").toString()); Seconds++) { if (!((Automation.driver.getWindowHandles().size()) > 1)) { webElement.click(); Thread.sleep(5000); } else { break; } } break; case ActionClick: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); Actions builderClick = new Actions(Automation.driver); Action clickAction = builderClick.moveToElement(webElement).clickAndHold().release().build(); clickAction.perform(); break; case ActionDoubleClick: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); Actions builderdoubleClick = new Actions(Automation.driver); Action doubleClickAction = builderdoubleClick.moveToElement(webElement).click().build(); doubleClickAction.perform(); doubleClickAction.perform(); break; case ActionClickandEsc: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); Actions clickandEsc = new Actions(Automation.driver); Action clickEscAction = clickandEsc.moveToElement(webElement).click() .sendKeys(Keys.ENTER, Keys.ESCAPE).build(); clickEscAction.perform(); break; case ActionMouseOver: Actions builderMouserOver = new Actions(Automation.driver); Action mouseOverAction = builderMouserOver.moveToElement(webElement).build(); mouseOverAction.perform(); break; case CalendarNew: Boolean isCalendarDisplayed = Automation.driver.switchTo().activeElement().isDisplayed(); System.out.println(isCalendarDisplayed); if (isCalendarDisplayed == true) { String[] dtMthYr = ctrlValue.split("/"); Thread.sleep(2000); //String[] CurrentDate = dtFormat.format(frmDate).split("/"); WebElement Monthyear = Automation.driver.findElement(By.xpath("//table/thead/tr/td[2]")); String Monthyear1 = Monthyear.getText(); String[] Monthyear2 = Monthyear1.split(","); Monthyear2[1] = Monthyear2[1].trim(); month = CalendarSnippet.getMonthForString(Monthyear2[0]); while (!Monthyear2[1].equalsIgnoreCase(dtMthYr[2])) { if (Integer.parseInt(Monthyear2[1]) > Integer.parseInt(dtMthYr[2])) { WebElement yearButton = Automation.driver .findElement(By.cssSelector("td:contains('')")); yearButton.click(); Monthyear2[1] = Integer.toString(Integer.parseInt(Monthyear2[1]) - 1); } else if (Integer.parseInt(Monthyear2[1]) < Integer.parseInt(dtMthYr[2])) { WebElement yearButton = Automation.driver .findElement(By.cssSelector("td:contains('')")); yearButton.click(); Monthyear2[1] = Integer.toString(Integer.parseInt(Monthyear2[1]) + 1); } } while (!month.equalsIgnoreCase(dtMthYr[1])) { if (Integer.parseInt(month) > Integer.parseInt(dtMthYr[1])) { WebElement monthButton = Automation.driver .findElement(By.cssSelector("td:contains('')")); monthButton.click(); if (Integer.parseInt(month) < 11) { month = "0" + Integer.toString(Integer.parseInt(month) - 1); } else { month = Integer.toString(Integer.parseInt(month) - 1); } } else if (Integer.parseInt(month) < Integer.parseInt(dtMthYr[1])) { WebElement monthButton = Automation.driver .findElement(By.cssSelector("td:contains('')")); monthButton.click(); if (Integer.parseInt(month) < 9) { month = "0" + Integer.toString(Integer.parseInt(month) + 1); } else { month = Integer.toString(Integer.parseInt(month) + 1); } } } WebElement dateButton = Automation.driver .findElement(By.cssSelector("td.day:contains('" + dtMthYr[0] + "')")); System.out.println(dateButton); dateButton.click(); } else { System.out.println("Calendar not Diplayed"); } break; case CalendarIPF: String[] dtMthYr = ctrlValue.split("/"); Thread.sleep(2000); String year = dtMthYr[2]; String monthNum = dtMthYr[1]; String day = dtMthYr[0]; //Xpath for Year, mMnth & Days String xpathYear = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-years']"; String xpathMonth = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-months']"; String xpathDay = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-days']"; //Selecting year in 3 steps Automation.driver.findElement(By.xpath(xpathDay + "/table/thead/tr[1]/th[2]")).click(); Automation.driver.findElement(By.xpath(xpathMonth + "/table/thead/tr/th[2]")).click(); Automation.driver .findElement(By.xpath(xpathYear + "/table/tbody/tr/td/span[@class='year'][contains(text()," + year + ")]")) .click(); //Selecting month in 1 step Automation.driver .findElement(By.xpath(xpathMonth + "/table/tbody/tr/td/span[" + monthNum + "]")) .click(); //Selecting day in 1 step Automation.driver .findElement(By.xpath( xpathDay + "/table/tbody/tr/td[@class='day'][contains(text()," + day + ")]")) .click(); case CalendarEBP: String[] dtMthYrEBP = ctrlValue.split("/"); Thread.sleep(2000); String yearEBP = dtMthYrEBP[2]; String monthNumEBP = CalendarSnippet.getMonthForInt(Integer.parseInt(dtMthYrEBP[1])) .substring(0, 3); String dayEBP = dtMthYrEBP[0]; //common path used for most of the elements String pathToVisibleCalendar = "//div[@class='ajax__calendar'][contains(@style, 'visibility: visible;')]/div"; //following is to click the title once to reach the year page wait.until(ExpectedConditions.elementToBeClickable( By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_header']/div[3]/div"))) .click(); //check if 'Dec' is visibly clickable after refreshing wait.until(ExpectedConditions.elementToBeClickable(By.xpath( pathToVisibleCalendar + "/div/div/table/tbody/tr/td/div[contains(text(), 'Dec')]"))); //following is to click the title once again to reach the year page Automation.driver .findElement(By.xpath( pathToVisibleCalendar + "/div[@class='ajax__calendar_header']/div[3]/div")) .click(); //common path used for most of the elements while selection of year, month and date pathToVisibleCalendar = "//div[@class='ajax__calendar'][contains(@style, 'visibility: visible;')]/div/div/div/table/tbody/tr/td"; //each of the following line selects the year, month and date wait.until(ExpectedConditions.elementToBeClickable( By.xpath(pathToVisibleCalendar + "/div[contains(text()," + yearEBP + ")]"))).click(); wait.until(ExpectedConditions.elementToBeClickable(By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_month'][contains(text(),'" + monthNumEBP + "')]"))) .click(); wait.until(ExpectedConditions.elementToBeClickable(By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_day'][contains(text()," + dayEBP + ")]"))).click(); break; /**Code for window popups**/ case Window: switch (actionName) { case O: String parentHandle = Automation.driver.getWindowHandle(); for (String winHandle : Automation.driver.getWindowHandles()) { Automation.driver.switchTo().window(winHandle); if (Automation.driver.getTitle().equalsIgnoreCase(controlName)) { Automation.driver.close(); } } Automation.driver.switchTo().window(parentHandle); break; } break; case WebTable: switch (actionName) { case Read: ReadFromExcel(ctrlValue); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case NC: WebElement table = webElement; List<WebElement> tableRows = table.findElements(By.tagName("tr")); int tableRowIndex = 0; //int tableColumnIndex = 0; boolean matchFound = false; for (WebElement tableRow : tableRows) { tableRowIndex += 1; List<WebElement> tableColumns = tableRow.findElements(By.tagName("td")); if (tableColumns.size() > 0) { for (WebElement tableColumn : tableColumns) if (tableColumn.getText().equals(ctrlValue)) { matchFound = true; System.out.println(tableRowIndex); List<Object> elementProperties = getPropertiesOfWebElement( tableColumns.get(Integer.parseInt(colNo)), imageType); controlName = elementProperties.get(0).toString(); if (controlName.equals("")) { controlName = elementProperties.get(1).toString(); } controlType = elementProperties.get(2).toString(); webElement = (WebElement) elementProperties.get(3); doAction(imageType, controlType, controlId, controlName, ctrlValue, logicalName, action, webElement, Results, strucSheet, valSheet, tableRowIndex, rowcount, rowNo, colNo); break; } if (matchFound) { break; } } } break; case V: WriteToDetailResults(ctrlValue, "", logicalName); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } break; } break; case Robot: if (controlName.equalsIgnoreCase("SetFilePath")) { StringSelection stringSelection = new StringSelection(ctrlValue); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null); robot.delay(1000); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); } else if (controlName.equalsIgnoreCase("TAB")) { robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); } else if (controlName.equalsIgnoreCase("SPACE")) { robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); } else if (controlName.equalsIgnoreCase("ENTER")) { robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); } break; case WaitForEC: wait.until(CommonExpectedConditions.elementToBeClickable(webElement)); break; case SikuliType: sikuliScreen.type(controlName, ctrlValue); break; case SikuliButton: sikuliScreen.click(controlName); System.out.println("Done"); break; case Date: Calendar cal = new GregorianCalendar(); int i = cal.get(Calendar.DAY_OF_MONTH); if (i >= 31) { i = i - 10; } break; case FileUpload: webElement.sendKeys(ctrlValue); break; case ScrollTo: Locatable element = (Locatable) webElement; Point p = element.getCoordinates().onScreen(); JavascriptExecutor js = (JavascriptExecutor) Automation.driver; js.executeScript("window.scrollTo(" + p.getX() + "," + (p.getY() + 150) + ");"); break; default: System.out.println("U r in Default"); break; } } catch (WebDriverException we) { throw new Exception("Error Occurred from Do Action " + controlName + we.getMessage()); } catch (Exception e) { throw new Exception(e.getMessage()); } } if (action.toString().equalsIgnoreCase("V") && !ctrlValue.equalsIgnoreCase("")) { if (Results == true) { SwiftSeleniumWeb.WebDriver.report = WriteToDetailResults(ctrlValue, currentValue, logicalName); } } return currentValue; }
From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java
private void projectTreeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_projectTreeKeyReleased if (evt.getKeyCode() == 525) { // treePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); try {// w w w.j a v a2 s.c om Robot robot = new Robot(); robot.mousePress(InputEvent.BUTTON3_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); } catch (AWTException ex) { Exceptions.printStackTrace(ex); } } }
From source file:com.photon.phresco.framework.rest.api.UtilService.java
@POST @Path("/sendErrorReport") @Produces(MediaType.APPLICATION_JSON)//from ww w .j a va 2 s . com public Response sendErrorReport(String errorReport, @QueryParam("emailId") String emailId, @QueryParam("username") String username) throws PhrescoException { ResponseInfo<String> responseData = new ResponseInfo<String>(); File screenShot = new File(Utility.getPhrescoTemp(), FrameworkConstants.TEMP_ERRORIMG_FILE); File logFile = new File(Utility.getPhrescoTemp(), FrameworkConstants.TEMP_ERROR_FILE); FileWriter fileWriter = null; UpgradeManagerImpl build = new UpgradeManagerImpl(); String buildNumber = build.getCurrentVersion(); try { fileWriter = new FileWriter(logFile); fileWriter.write(errorReport); fileWriter.close(); // For screen shot Robot robot = new Robot(); BufferedImage bi = robot.createScreenCapture(new Rectangle(1000, 700)); ImageIO.write(bi, "jpg", new File(Utility.getPhrescoTemp(), FrameworkConstants.TEMP_ERRORIMG_FILE)); InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("framework.config"); Properties prop = new Properties(); prop.load(resourceAsStream); String group = prop.getProperty("phresco.support.mailIds"); String[] groupp = group.split(","); Utility.sendTemplateEmail(groupp, emailId, username, MAIL_SUBJECT, logFile.getPath(), MAIL_ID, MAIL_PASSWORD, null, screenShot.getPath(), buildNumber); ResponseInfo<String> finalOutput = responseDataEvaluation(responseData, null, null, RESPONSE_STATUS_SUCCESS, PHR14C00001); return Response.status(Status.OK).entity(finalOutput).header("Access-Control-Allow-Origin", "*") .build(); } catch (IOException ex) { throw new PhrescoException(ex); } catch (Exception e) { ResponseInfo<String> finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHR14C10001); return Response.status(Status.OK).entity(finalOutput).header("Access-Control-Allow-Origin", "*") .build(); } finally { Utility.closeStream(fileWriter); if (logFile.exists()) { FileUtil.delete(logFile); } if (screenShot.exists()) { FileUtil.delete(screenShot); } } }
From source file:com.jsystem.j2autoit.AutoItAgent.java
@Override public void run() { try {//from w w w .j av a 2 s.com Robot robot = new Robot(); BufferedImage bufferedImage = robot.createScreenCapture(screenRect); ImageIO.write(bufferedImage, "png", theImageFile); Log.infoLog("Created image file : " + theImageFile.getAbsolutePath() + "\n"); robot = null; } catch (Exception exception) { Log.throwable(exception.getMessage(), exception); } }
From source file:org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils.java
public static void uploadFileWithJavaRobot(String FilePath, String FileName) throws Exception { StringSelection sel = new StringSelection(FilePath + FileName); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null); Thread.sleep(1000);/*from ww w . ja v a 2 s . c o m*/ Robot robot = new Robot(); robot.delay(1000); // Release Enter robot.keyRelease(KeyEvent.VK_ENTER); // Press CTRL+V robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); // Release CTRL+V robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyRelease(KeyEvent.VK_V); Thread.sleep(1000); // Press Enter robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); Thread.sleep(3000); }
From source file:swift.selenium.WebHelper.java
@SuppressWarnings("incomplete-switch") public static String doAction(String imageType, String controlType, String controlId, String controlName, String ctrlValue, String logicalName, String action, WebElement webElement, Boolean Results, HSSFSheet strucSheet, HSSFSheet valSheet, int rowIndex, int rowcount, String rowNo, String colNo) throws Exception { List<WebElement> WebElementList = null; String currentValue = null;// w w w . j a v a2 s.c o m //HSSFSheet uniqueNumberSheet =null; String uniqueNumber = ""; WebVerification.isFromVerification = false; //HashMap<String ,Object> uniqueValuesHashMap = null; //HSSFRow uniqueRow = null; ControlTypeEnum controlTypeEnum = ControlTypeEnum.valueOf(controlType); ControlTypeEnum actionName = ControlTypeEnum.valueOf(action.toString()); if (controlType.contains("Robot") && !isIntialized) { robot = new Robot(); isIntialized = true; } if (action.toString().equalsIgnoreCase("I") && !ctrlValue.equalsIgnoreCase("") || action.toString().equalsIgnoreCase("Read") || action.toString().equalsIgnoreCase("Write") || action.toString().equalsIgnoreCase("V") && !ctrlValue.equalsIgnoreCase("") || action.toString().equalsIgnoreCase("NC") || action.toString().equalsIgnoreCase("T") && !ctrlValue.equalsIgnoreCase("") || action.toString().equalsIgnoreCase("F") && !ctrlValue.equalsIgnoreCase("") || action.toString().equalsIgnoreCase("VA") && !ctrlValue.equalsIgnoreCase("") || action.toString().equalsIgnoreCase("O") || action.toString().equalsIgnoreCase("CP") || action.toString().equalsIgnoreCase("GV") || action.toString().equalsIgnoreCase("LV") || action.toString().equalsIgnoreCase("GB") || action.toString().equalsIgnoreCase("Get") || action.toString().equalsIgnoreCase("Post")) { try { switch (controlTypeEnum) { case WebEdit: switch (actionName) { case Read: uniqueNumber = ReadFromExcel(ctrlValue); webElement.clear(); webElement.sendKeys(uniqueNumber); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case I: if (!ctrlValue.equalsIgnoreCase("null")) { webElement.clear(); webElement.sendKeys(ctrlValue); } else { webElement.clear(); } break; case T: if (!ctrlValue.equalsIgnoreCase("null")) { webElement.clear(); webElement.sendKeys(ctrlValue); ((DeviceActionShortcuts) Automation.driver).hideKeyboard(); } else { webElement.clear(); } break; case V: currentValue = webElement.getText(); break; } break; case WebButton: switch (actionName) { case I: if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) { webElement.click(); } break; case NC: webElement.click(); break; case V: if (webElement.isDisplayed()) { if (webElement.isEnabled() == true) currentValue = "True"; else currentValue = "False"; } } break; case WebElement: switch (actionName) { case I: webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement)); webElement.click(); break; case Read: uniqueNumber = ReadFromExcel(ctrlValue); webElement.clear(); webElement.sendKeys(uniqueNumber); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case V: if (WebVerification.isFromVerification == true) { currentValue = webElement.getText(); break; } boolean textPresent = false; String ObservedText = webElement.getText(); if (StringUtils.isBlank(ObservedText)) { ObservedText = webElement.getAttribute("value"); } textPresent = ObservedText.contains(ctrlValue); if (textPresent == false) currentValue = Boolean.toString(textPresent); else currentValue = ctrlValue; break; case T: Point p = ((Locatable) webElement).getCoordinates().onPage(); ((MobileDriver) Automation.driver).tap(1, p.getX(), p.getY(), 1); break; } break; case JSScript: ((JavascriptExecutor) Automation.driver).executeScript(controlName, ctrlValue); break; case Wait: Thread.sleep(Integer.parseInt(controlName) * 1000); break; case CheckBox: switch (actionName) { case I: if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) { webElement.click(); } break; case NC: webElement.click(); break; } break; case Radio: switch (actionName) { case I: if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) { if (!webElement.isSelected()) { webElement.click(); } } break; case NC: if (!webElement.isSelected()) { webElement.click(); } break; case V: if (webElement.isSelected()) { currentValue = webElement.getAttribute(controlName.toString()); } break; case F: if (webElement != null) { currentValue = "Y"; } break; } break; case WebLink: //case CloseWindow://added this Case to bypass page loading after clicking the event switch (actionName) { case Read: uniqueNumber = ReadFromExcel(ctrlValue); WebElementList = getElementsByType(controlId, controlName, controlType, imageType, uniqueNumber); webElement = GetControlByIndex("", WebElementList, controlId, controlName, controlType, uniqueNumber); webElement.click(); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case I: if (controlId.equalsIgnoreCase("LinkValue")) { webElement.click(); } else { if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) { webElement.click(); } } break; case NC: webElement.click(); break; } break; case CloseWindow: //TM-09/09/2015: This case is written to help in closing any specific windows switch (actionName) { case I: //This case helps in closing a specific window on the basis on the given title Set<String> handlers = null; handlers = Automation.driver.getWindowHandles(); for (String handler : handlers) { Automation.driver = Automation.driver.switchTo().window(handler); //TM-19/01/2015: Changed following comparison from equalsIgnoreCase to contains if (Automation.driver.getTitle().contains(ctrlValue)) { System.out.println("Closing required window :-" + Automation.driver.getTitle()); Automation.driver.close(); break; } } break; case NC://This case helps in closing the window with current focus Automation.driver.close(); break; } break; case WaitForJS: waitForCondition(); break; case ListBox: case WebList: switch (actionName) { case Read: uniqueNumber = ReadFromExcel(ctrlValue); new Select(webElement).selectByVisibleText(uniqueNumber); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case I: ExpectedCondition<Boolean> isTextPresent = CommonExpectedConditions .textToBePresentInElement(webElement, ctrlValue); if (isTextPresent != null) { if (webElement != null) { new Select(webElement).selectByVisibleText(ctrlValue); } } break; case V: if (!ctrlValue.contains(",")) { currentValue = new Select(webElement).getFirstSelectedOption().getText(); if (currentValue.isEmpty()) { currentValue = new Select(webElement).getFirstSelectedOption() .getAttribute("value"); } break; } else { currentValue = new String(); List<WebElement> currentValues = new ArrayList<WebElement>(); currentValues = new Select(webElement).getOptions(); for (int j = 0; j < currentValues.size(); j++) { if (j + 1 == currentValues.size()) currentValue = currentValue.concat(currentValues.get(j).getText()); else { currentValue = currentValue.concat(currentValues.get(j).getText() + ","); } } break; } } break; //New code for AJAX Dropdown with dojo case AjaxWebList: switch (actionName) { case I: webElement.click(); break; case VA: Thread.sleep(20000); currentValue = new String(); List<WebElement> currentValues = new ArrayList<WebElement>(); currentValues = Automation.driver.findElements(By.xpath(controlName)); for (int j = 0; j < currentValues.size(); j++) { if (j + 1 == currentValues.size()) currentValue = currentValue.concat(currentValues.get(j).getText()); else { currentValue = currentValue.concat(currentValues.get(j).getText() + ","); } } break; } break; case IFrame: Automation.driver = Automation.driver.switchTo().frame(controlName); break; case Browser: Set<String> handlers = null; handlers = Automation.driver.getWindowHandles(); for (String handler : handlers) { Automation.driver = Automation.driver.switchTo().window(handler); if (Automation.driver.getTitle().contains(controlName)) { System.out.println("Focus on window with title: " + Automation.driver.getTitle()); break; } } break; case BrowserControl: Set<String> winHandles = Automation.driver.getWindowHandles(); boolean controlfound = false; winHandles = Automation.driver.getWindowHandles(); for (String handler : winHandles) { Automation.driver = Automation.driver.switchTo().window(handler); try { Automation.driver.findElement(By.xpath(controlName)); System.out.println("Focus on window with Control: " + controlName); controlfound = true; break; } catch (Exception e) { // TODO: handle exception } } if (!controlfound) System.out.println("Unable to find control with : " + controlName); break; case BrowserType: switch (actionName) { case I: if (StringUtils.isNotBlank(ctrlValue)) { Automation.browser = Automation.configHashMap.get("BROWSERTYPE").toString(); if (StringUtils.equalsIgnoreCase("none", Automation.browser)) { Automation.browser = ctrlValue.toString(); Automation.browserType = Automation.browserTypeEnum.valueOf(Automation.browser); Automation.setUp(); wait = new WebDriverWait(Automation.driver, Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString())); //Thread.sleep(5000); } } break; case NC: if (StringUtils.isNotBlank(controlName)) { Automation.browser = Automation.configHashMap.get("BROWSERTYPE").toString(); if (StringUtils.equalsIgnoreCase("none", Automation.browser)) { Automation.browser = controlName.toString(); Automation.browserType = Automation.browserTypeEnum.valueOf(Automation.browser); Automation.setUp(); wait = new WebDriverWait(Automation.driver, Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString())); //Thread.sleep(5000); } } break; } break; case BrowserAuth: final String details[] = ctrlValue.split(","); Runnable thread2 = new Runnable() { public void run() { try { smartRobot = new SmartRobot(); Thread.sleep(5000); smartRobot.type(details[0].toString());// Enter username Thread.sleep(2000); smartRobot.pressTab();// Click Keyboard Tab smartRobot.type(details[1].toString());// Enter password Thread.sleep(2000); smartRobot.pressEnter();// Click Enter button Thread.sleep(5000); } catch (Exception e) { e.printStackTrace(); } } }; Thread thr2 = new Thread(thread2); thr2.start(); break; case URL: final String url = ctrlValue; if (!StringUtils.isBlank(ctrlValue)) { if (Automation.browser.equals("InternetExplorer")) { Automation.driver.navigate().to(url); Thread.sleep(5000); } else { Runnable thread1 = new Runnable() { public void run() { try { Automation.driver.navigate().to(url); Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } }; Thread thr1 = new Thread(thread1); thr1.start(); } } break; case Menu: webElement.click(); break; case Alert: switch (actionName) { case V: Alert alert = wait.until(ExpectedConditions.alertIsPresent()); if (alert != null) { Automation.driver.switchTo().alert(); currentValue = alert.getText(); System.out.println(currentValue); alert.accept(); } break; } break; case WebImage: webElement.sendKeys(Keys.TAB); webElement.click(); Thread.sleep(5000); for (int Seconds = 0; Seconds <= Integer .parseInt(Automation.configHashMap.get("TIMEOUT").toString()); Seconds++) { if (!((Automation.driver.getWindowHandles().size()) > 1)) { webElement.click(); Thread.sleep(5000); } else { break; } } break; case ActionClick: Actions builderClick = new Actions(Automation.driver); Action clickAction = builderClick.moveToElement(webElement).clickAndHold().release().build(); clickAction.perform(); break; case ActionDoubleClick: Actions builderdoubleClick = new Actions(Automation.driver); builderdoubleClick.doubleClick(webElement).perform();//TM-27/01/2015 :- commented following code and used this code for simultaneous clicks //Action doubleClickAction = builderdoubleClick.moveToElement(webElement).click().build(); //doubleClickAction.perform(); //doubleClickAction.perform(); break; case ActionClickandEsc: Actions clickandEsc = new Actions(Automation.driver); Action clickEscAction = clickandEsc.moveToElement(webElement).click() .sendKeys(Keys.ENTER, Keys.ESCAPE).build(); clickEscAction.perform(); break; case ActionMouseOver: Actions builderMouserOver = new Actions(Automation.driver); Action mouseOverAction = builderMouserOver.moveToElement(webElement).build(); mouseOverAction.perform(); break; case Calendar: // Thread.sleep(5000); Boolean isCalendarDisplayed = Automation.driver.switchTo().activeElement().isDisplayed(); System.out.println(isCalendarDisplayed); if (isCalendarDisplayed == true) { String[] dtMthYr = ctrlValue.split("/"); WebElement Year = WaitTool.waitForElement(Automation.driver, By.name("year"), Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.name("year")); while (!Year.getAttribute("value").equalsIgnoreCase(dtMthYr[2])) { if (Integer.parseInt(Year.getAttribute("value")) > Integer.parseInt(dtMthYr[2])) { WebElement yearButton = WaitTool.waitForElement(Automation.driver, By.id("button1"), Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.id("button1")); yearButton.click(); } else if (Integer.parseInt(Year.getAttribute("value")) < Integer .parseInt(dtMthYr[2])) { WebElement yearButton = WaitTool.waitForElement(Automation.driver, By.id("Button5"), Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.id("Button5")); yearButton.click(); } } Select date = new Select(WaitTool.waitForElement(Automation.driver, By.name("month"), Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()))); month = CalendarSnippet.getMonthForInt(Integer.parseInt(dtMthYr[1])); date.selectByVisibleText(month); WebElement Day = WaitTool.waitForElement(Automation.driver, By.id("Button6"), Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.id("Button6")); int day = 6; while (Day.getAttribute("value") != null) { Day = WaitTool.waitForElement(Automation.driver, By.id("Button" + day), Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.id("Button"+day)); if (Day.getAttribute("value").toString().equalsIgnoreCase(dtMthYr[0])) { Day.click(); break; } day++; } } else { System.out.println("Calendar not Diplayed"); } //Automation.selenium.click(controlName); break; case CalendarNew: isCalendarDisplayed = Automation.driver.switchTo().activeElement().isDisplayed(); System.out.println(isCalendarDisplayed); if (isCalendarDisplayed == true) { String[] dtMthYr = ctrlValue.split("/"); Thread.sleep(2000); //String[] CurrentDate = dtFormat.format(frmDate).split("/"); WebElement Monthyear = Automation.driver.findElement(By.xpath("//table/thead/tr/td[2]")); String Monthyear1 = Monthyear.getText(); String[] Monthyear2 = Monthyear1.split(","); Monthyear2[1] = Monthyear2[1].trim(); month = CalendarSnippet.getMonthForString(Monthyear2[0]); while (!Monthyear2[1].equalsIgnoreCase(dtMthYr[2])) { if (Integer.parseInt(Monthyear2[1]) > Integer.parseInt(dtMthYr[2])) { WebElement yearButton = Automation.driver .findElement(By.cssSelector("td:contains('')")); yearButton.click(); Monthyear2[1] = Integer.toString(Integer.parseInt(Monthyear2[1]) - 1); } else if (Integer.parseInt(Monthyear2[1]) < Integer.parseInt(dtMthYr[2])) { WebElement yearButton = Automation.driver .findElement(By.cssSelector("td:contains('')")); yearButton.click(); Monthyear2[1] = Integer.toString(Integer.parseInt(Monthyear2[1]) + 1); } } while (!month.equalsIgnoreCase(dtMthYr[1])) { if (Integer.parseInt(month) > Integer.parseInt(dtMthYr[1])) { WebElement monthButton = Automation.driver .findElement(By.cssSelector("td:contains('')")); monthButton.click(); if (Integer.parseInt(month) < 11) { month = "0" + Integer.toString(Integer.parseInt(month) - 1); } else { month = Integer.toString(Integer.parseInt(month) - 1); } } else if (Integer.parseInt(month) < Integer.parseInt(dtMthYr[1])) { WebElement monthButton = Automation.driver .findElement(By.cssSelector("td:contains('')")); monthButton.click(); if (Integer.parseInt(month) < 9) { month = "0" + Integer.toString(Integer.parseInt(month) + 1); } else { month = Integer.toString(Integer.parseInt(month) + 1); } } } WebElement dateButton = Automation.driver .findElement(By.cssSelector("td.day:contains('" + dtMthYr[0] + "')")); System.out.println(dateButton); dateButton.click(); } else { System.out.println("Calendar not Diplayed"); } break; case CalendarIPF: String[] dtMthYr = ctrlValue.split("/"); Thread.sleep(2000); String year = dtMthYr[2]; String monthNum = dtMthYr[1]; String day = dtMthYr[0]; //Xpath for Year, mMnth & Days String xpathYear = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-years']"; String xpathMonth = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-months']"; String xpathDay = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-days']"; //Selecting year in 3 steps Automation.driver.findElement(By.xpath(xpathDay + "/table/thead/tr[1]/th[2]")).click(); Automation.driver.findElement(By.xpath(xpathMonth + "/table/thead/tr/th[2]")).click(); Automation.driver .findElement(By.xpath(xpathYear + "/table/tbody/tr/td/span[@class='year'][contains(text()," + year + ")]")) .click(); //Selecting month in 1 step Automation.driver .findElement(By.xpath(xpathMonth + "/table/tbody/tr/td/span[" + monthNum + "]")) .click(); //Selecting day in 1 step Automation.driver .findElement(By.xpath( xpathDay + "/table/tbody/tr/td[@class='day'][contains(text()," + day + ")]")) .click(); case CalendarEBP: String[] dtMthYrEBP = ctrlValue.split("/"); Thread.sleep(500); String yearEBP = dtMthYrEBP[2]; String monthNumEBP = CalendarSnippet.getMonthForInt(Integer.parseInt(dtMthYrEBP[1])) .substring(0, 3); String dayEBP = dtMthYrEBP[0]; //common path used for most of the elements String pathToVisibleCalendar = "//div[@class='ajax__calendar'][contains(@style, 'visibility: visible;')]/div"; //following is to click the title once to reach the year page wait.until(ExpectedConditions.elementToBeClickable( By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_header']/div[3]/div"))) .click(); //check if 'Dec' is visibly clickable after refreshing wait.until(ExpectedConditions.elementToBeClickable(By.xpath( pathToVisibleCalendar + "/div/div/table/tbody/tr/td/div[contains(text(), 'Dec')]"))); Thread.sleep(5000); //following is to click the title once again to reach the year page wait.until(ExpectedConditions.elementToBeClickable( (By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_header']/div[3]/div")))) .click(); //common path used for most of the elements while selection of year, month and date pathToVisibleCalendar = "//div[@class='ajax__calendar'][contains(@style, 'visibility: visible;')]/div/div/div/table/tbody/tr/td"; Thread.sleep(2000); //each of the following line selects the year, month and date wait.until(ExpectedConditions.elementToBeClickable( By.xpath(pathToVisibleCalendar + "/div[contains(text()," + yearEBP + ")]"))).click(); Thread.sleep(2000); wait.until(ExpectedConditions.elementToBeClickable(By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_month'][contains(text(),'" + monthNumEBP + "')]"))) .click(); Thread.sleep(2000); wait.until(ExpectedConditions.elementToBeClickable(By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_day'][contains(text()," + dayEBP + ")]"))).click(); break; /**Code for window popups**/ case Window: switch (actionName) { case O: String parentHandle = Automation.driver.getWindowHandle(); for (String winHandle : Automation.driver.getWindowHandles()) { Automation.driver.switchTo().window(winHandle); if (Automation.driver.getTitle().contains(controlName)) { ((JavascriptExecutor) Automation.driver) .executeScript("window.onbeforeunload = function(e){};");//By Tripti: 16/02/2015 Automation.driver.close(); } else { parentHandle = winHandle; } } Automation.driver.switchTo().window(parentHandle); break; } break; case WebTable: switch (actionName) { case Read: ReadFromExcel(ctrlValue); break; case Write: writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; case NC: WebElement table = webElement; List<WebElement> tableRows = table.findElements(By.tagName("tr")); int tableRowIndex = 0; //int tableColumnIndex = 0; boolean matchFound = false; for (WebElement tableRow : tableRows) { tableRowIndex += 1; List<WebElement> tableColumns = tableRow.findElements(By.tagName("td")); if (tableColumns.size() > 0) { for (WebElement tableColumn : tableColumns) if (tableColumn.getText().equals(ctrlValue)) { matchFound = true; System.out.println(tableRowIndex); List<Object> elementProperties = getPropertiesOfWebElement( tableColumns.get(Integer.parseInt(colNo)), imageType); controlName = elementProperties.get(0).toString(); if (controlName.equals("")) { controlName = elementProperties.get(1).toString(); } controlType = elementProperties.get(2).toString(); webElement = (WebElement) elementProperties.get(3); doAction(imageType, controlType, controlId, controlName, ctrlValue, logicalName, action, webElement, Results, strucSheet, valSheet, tableRowIndex, rowcount, rowNo, colNo); break; } if (matchFound) { break; } } } break; case V: WriteToDetailResults(ctrlValue, "", logicalName); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } break; case GB: WebVerification.GroupBy = ctrlValue; break; } break; case Robot: if (controlName.equalsIgnoreCase("SetFilePath")) { StringSelection stringSelection = new StringSelection(ctrlValue); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null); robot.delay(5000); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); } else if (controlName.equalsIgnoreCase("Type")) { robot.keyPress(KeyEvent.VK_M); robot.keyRelease(KeyEvent.VK_TAB); } else if (controlName.equalsIgnoreCase("TAB")) { robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); } else if (controlName.equalsIgnoreCase("SPACE")) { robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); } else if (controlName.equalsIgnoreCase("ENTER")) { robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); } break; case DB: switch (actionName) { case Write: ResultSet rs = JDBCConnection.establishDBConn("", ctrlValue); rs.next(); ctrlValue = String.valueOf(rs.getLong("COL_1")); rs.close(); writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo); break; } break; //Kinjal 9/6/2015 Added for DB Approach case DBV: switch (actionName) { case CP: currentValue = webElement.getText(); if (StringUtils.isBlank(currentValue)) { currentValue = webElement.getAttribute("value"); } ctrlValue = JDBCConnection.getFirstColumnName(ctrlValue); System.out.println("Database value fetched from DB is " + ctrlValue); break; case V: List<WebElement> rowElements = WebHelper.getElementsByType(controlId, controlName, "", "", ""); if (rowElements != null) { currentValue = Integer.toString(rowElements.size()); } else { currentValue = "0"; } ctrlValue = JDBCConnection.getFirstColumnName(ctrlValue); break; } break; case WaitForEC: wait.until(CommonExpectedConditions.elementToBeClickable(webElement)); break; case SikuliType: sikuliScreen.type(controlName, ctrlValue); break; case SikuliButton: sikuliScreen.click(controlName); System.out.println("Done"); break; case Date: Calendar cal = new GregorianCalendar(); int i = cal.get(Calendar.DAY_OF_MONTH); if (i >= 31) { i = i - 10; } break; case FileUpload: webElement.sendKeys(ctrlValue); break; case ScrollTo: //Locatable element = (Locatable) webElement; //TM:04/03/2015-commented as incorrect //Point p= element.getCoordinates().onScreen();//TM:04/03/2015-commented as incorrect Point p = webElement.getLocation();//TM:04/03/2015-New correct code System.out.println("X,Y co-ordinates of textbox is:- " + p);//TM:04/03/2015-New correct code JavascriptExecutor js = (JavascriptExecutor) Automation.driver; //TM:04/03/2015-New correct code js.executeScript("window.scrollTo(" + p.getX() + "," + (p.getY() + 150) + ");"); break; case SwitchContext: Thread.sleep(3000); Set<String> contexts = ((AppiumDriver) Automation.driver).getContextHandles(); for (String s : contexts) { System.out.println("Count of contexts : " + contexts.size()); System.out.println("Context Name : " + s); if (s.contains(ctrlValue)) { System.out.println("Mobile Web View found"); ((AppiumDriver) Automation.driver).context(s); break; } } Thread.sleep(2000); break; case SwipeDown: //((AppiumDriver)(Automation.driver)).swipe(0, 0, 0, 1500, 2000); ((AppiumDriver) (Automation.driver)).scrollTo(ctrlValue); break; case CaptureScreen: Date toDate = new Date(); TransactionMapping.report.setFromDate(Automation.dtFormat.format(frmDate)); TransactionMapping.report .setStrIteration(Automation.configHashMap.get("CYCLENUMBER").toString()); TransactionMapping.report.setStrTestcaseId(MainController.controllerTestCaseID.toString()); TransactionMapping.report.setStrGroupName(MainController.controllerGroupName.toString()); TransactionMapping.report .setStrTrasactionType(MainController.controllerTransactionType.toString()); TransactionMapping.report.setStrTestDescription(MainController.testDesciption); TransactionMapping.report.setStrMessage( "Screenshot of Test Case Id:" + MainController.controllerTestCaseID.toString() + " & Transaction Type:" + MainController.controllerTransactionType.toString()); TransactionMapping.report.setToDate(Automation.dtFormat.format(toDate)); saveScreenShot(TransactionMapping.report, logicalName); break; case WebService: switch (actionName) { case I: if (logicalName.equalsIgnoreCase("WSDL_URL")) wsdl_url = ctrlValue; else if (logicalName.equalsIgnoreCase("REQUEST_URL")) request_url = ctrlValue; else if (logicalName.equalsIgnoreCase("REQUEST_XML")) request_xml = ctrlValue; break; case T: WebService.callWebService(); break; case V: currentValue = WebService.getXMLTagValue(controlName); break; } break; case WebService_REST: switch (actionName) { case I: if (logicalName.equalsIgnoreCase("REQUEST_URL")) request_url = ctrlValue; else if (logicalName.equalsIgnoreCase("REQUEST_XML")) { request_xml = ctrlValue; } break; case Get: WebService.callRESTWebService("Get", controlId); break; case Post: WebService.callRESTWebService("Post", controlId); break; case V: if (controlId.equalsIgnoreCase("JSON")) { currentValue = WebService.getJSONTagValue(controlName); } else { currentValue = WebService.getXMLTagValue(controlName); } break; } break; case JSONResp: switch (actionName) { case I: if (logicalName.equalsIgnoreCase("JSON_URL")) { response_url = controlName; response_fileName = ctrlValue; WebService.downloadAndStoreJson(response_url, response_fileName); } break; } break; case DonutChart: switch (actionName) { case GV: DonutChart donut = new DonutChart(Automation.driver, webElement); WebVerification.verifyTabularData(testcaseID.toString(), MainController.controllerTransactionType.toString(), donut.getDonutColumnNames(), donut.getDonutChartData()); break; case LV: DonutChart donutLegend = new DonutChart(Automation.driver, webElement); WebVerification.verifyTabularData(testcaseID.toString(), MainController.controllerTransactionType.toString(), donutLegend.getDonutLegendColumnNames(), donutLegend.getDonutLegendData()); break; } break; case BarChart: switch (actionName) { case GV: String[] series = ctrlValue.split("!"); List<String> seriesList = Arrays.asList(series); BarChart barChart = new BarChart(Automation.driver, webElement); WebVerification.verifyTabularData(testcaseID.toString(), MainController.controllerTransactionType.toString(), barChart.getColumnNames(), barChart.getChartData(seriesList)); break; case LV: BarChart barchartLegend = new BarChart(Automation.driver, webElement); WebVerification.verifyTabularData(testcaseID.toString(), MainController.controllerTransactionType.toString(), barchartLegend.getLegendColumnNames(), barchartLegend.getLegendData()); break; } break; case BasicLineChart: switch (actionName) { case GV: BasicLineChart lineChart = new BasicLineChart(Automation.driver, webElement); WebVerification.verifyTabularData(testcaseID.toString(), MainController.controllerTransactionType.toString(), lineChart.getColumnNames(), lineChart.getChartData()); break; case LV: BasicLineChart linechartLegend = new BasicLineChart(Automation.driver, webElement); WebVerification.verifyTabularData(testcaseID.toString(), MainController.controllerTransactionType.toString(), linechartLegend.getLegendColumnNames(), linechartLegend.getLegendData()); break; } break; default: System.out.println("U r in Default"); break; } } catch (WebDriverException we) { throw new Exception("Error Occurred from Do Action " + controlName + we.getMessage()); } catch (Exception e) { throw new Exception(e.getMessage()); } } //TM-02/02/2015: Radio button found ("F") & AJAX control ("VA") if ((action.toString().equalsIgnoreCase("V") || action.toString().equalsIgnoreCase("CP") || action.toString().equalsIgnoreCase("F") || action.toString().equalsIgnoreCase("VA")) && !ctrlValue.equalsIgnoreCase("")) { if (Results == true) { TransactionMapping.report = WriteToDetailResults(ctrlValue, currentValue, logicalName); } } return currentValue; }
From source file:com.netease.dagger.BrowserEmulator.java
/** * javascript executer which must contains one object to be affected * /*www. j a v a 2 s .co m*/ * @param js * @param by * */ public void uploadFile(String filepath) { try { //put file path in a clipboard StringSelection strSel = new StringSelection(filepath); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(strSel, null); //imitate mouse event ENTER/COPY/PASTE Robot robot = new Robot(); pause(500); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); logger.info("Success to upload file: " + filepath); } catch (Exception e) { e.printStackTrace(); } }