code
stringlengths
73
34.1k
label
stringclasses
1 value
public void setDate(String date) { if (date == null || date.trim().isEmpty()) { throw new IllegalArgumentException("Date cannot be null or empty."); } try { Date dateToSet = new SimpleDateFormat("MM/dd/yyyy").parse(date); Calendar to = Calendar.getInstance(); ...
java
public void datePickerInit(String prevMonthLocator, String nextMonthLocator, String dateTextLocator) { this.prevMonthLocator = prevMonthLocator; this.nextMonthLocator = nextMonthLocator; this.dateTextLocator = dateTextLocator; }
java
public void reset() { this.getElement().clear(); Grid.driver().findElement(By.tagName("body")).click(); this.calendar = Calendar.getInstance(); this.getElement().click(); }
java
public int size() { int size = 0; try { if (getParent() != null) { size = getParent().locateChildElements(getLocator()).size(); } else { size = HtmlElementUtils.locateElements(getLocator()).size(); } } catch (NoSuchElementExcept...
java
public WebElement locateElement(int index, String childLocator) { if (index < 0) { throw new IllegalArgumentException("index cannot be a negative value"); } setIndex(index); WebElement locatedElement = null; if (getParent() != null) { locatedElement = getP...
java
public static Object instantiatePrimitiveArray(Class<?> type, String[] values) { logger.entering(new Object[] { type, values }); validateParams(type, values); checkArgument(isPrimitiveArray(type), type + " is NOT a primitive array type."); Class<?> componentType = type.getComponentType...
java
public static Object instantiatePrimitiveObject(Class<?> type, Object objectToInvokeUpon, String valueToAssign) { logger.entering(new Object[] { type, objectToInvokeUpon, valueToAssign }); validateParams(type, objectToInvokeUpon, valueToAssign); checkArgument(type.isPrimitive(), type + " is NOT...
java
public static Object instantiateWrapperObject(Class<?> type, Object objectToInvokeUpon, String valueToAssign) { logger.entering(new Object[] { type, objectToInvokeUpon, valueToAssign }); validateParams(type, objectToInvokeUpon, valueToAssign); checkArgument(ClassUtils.isPrimitiveWrapper(type), ...
java
void startProcess(boolean squelch) throws IOException { LOGGER.entering(squelch); if (!squelch) { LOGGER.fine("Executing command " + cmdLine.toString()); } watchdog.reset(); DefaultExecutor executor = new DefaultExecutor(); executor.setWatchdog(watchdog); ...
java
String[] getJavaClassPathArguments(String jarNamePrefix, String mainClass) { LOGGER.entering(); Set<String> uniqueClassPathEntries = new LinkedHashSet<>(); // find all jars in the SELION_HOME_DIR if (getLauncherOptions().isIncludeJarsInSeLionHomeDir()) { Collection<File> hom...
java
String[] getJavaSystemPropertiesArguments() throws IOException { LOGGER.entering(); List<String> args = new LinkedList<>(); // Next, FWD all JVM -D args to the child process args.addAll(Arrays.asList(getPresentJavaSystemPropertiesArguments())); // Setup logging for child proces...
java
@Override public Iterator<Object[]> getDataByFilter(DataProviderFilter dataFilter) { Preconditions.checkArgument(resource != null, "File resource cannot be null"); logger.entering(dataFilter); Class<?> arrayType; JsonReader reader = null; try { reader = new JsonRe...
java
@Override public Hashtable<String, Object> getDataAsHashtable() { Preconditions.checkArgument(resource != null, "File resource cannot be null"); logger.entering(); // Over-writing the resource because there is a possibility that a user // can give a type resource.setCls(Hasht...
java
protected void startHtml(PrintWriter out) { logger.entering(out); try { Template t = ve.getTemplate("/templates/header.part.html"); VelocityContext context = new VelocityContext(); StringBuilder output = new StringBuilder(); for (Entry<String, String> tem...
java
void printUsageInfo() { StringBuilder usage = new StringBuilder(); usage.append(" System Properties: \n"); usage.append(" -DselionHome=<folderPath>: \n"); usage.append(" Path of SeLion home directory. Defaults to <user.home>/.selion2/ \n"); usage.append(" -D[property...
java
public boolean isTextPresent(String pattern) { String text = getElement().getText(); return (text != null && (text.contains(pattern) || text.matches(pattern))); }
java
public static void log(String message, boolean takeScreenshot, boolean saveSrc) { SeLionReporter reporter = new SeLionReporter(); BaseLog currentLog = new BaseLog(); currentLog.setMsg(message); currentLog.setLocation(Gatherer.saveGetLocation(Grid.driver())); reporter.setCurrentLo...
java
public void shutdownProcesses() throws ProcessHandlerException { LOGGER.info("Shutting down all our node processes."); ProcessHandler handler = ProcessHandlerFactory.createInstance(); List<ProcessInfo> processes = handler.potentialProcessToBeKilled(); handler.killProcess(processes); ...
java
public void scrollLeft() { logger.entering(); WebElement webElement = this.findElement(By.className(SCROLLVIEW_CLASS)); swipeLeft(webElement); logger.exiting(); }
java
public void scrollRight() { logger.entering(); WebElement webElement = this.findElement(By.className(SCROLLVIEW_CLASS)); swipeRight(webElement); logger.exiting(); }
java
public void scrollUp() { logger.entering(); WebElement webElement = this.findElement(By.className(SCROLLVIEW_CLASS)); swipeUp(webElement); logger.exiting(); }
java
public void scrollDown() { logger.entering(); WebElement webElement = this.findElement(By.className(SCROLLVIEW_CLASS)); swipeDown(webElement); logger.exiting(); }
java
public void setMaxBrowserInstances(String browserName, int maxBrowserInstances) { logger.entering(new Object[] { browserName, maxBrowserInstances }); validateBrowserName(browserName); BrowserStatistics lStatistics = createStatisticsIfNotPresent(browserName); lStatistics.setMaxBrowserInst...
java
public void incrementWaitingRequests(String browserName) { logger.entering(browserName); validateBrowserName(browserName); BrowserStatistics lStatistics = createStatisticsIfNotPresent(browserName); lStatistics.incrementWaitingRequests(); logger.exiting(); }
java
public static synchronized void printConfiguration(String testName) { LocalConfig currentConfig = getConfig(testName); currentConfig.printConfigValues(testName); }
java
public RemoteWebElement getElement() { RemoteWebElement foundElement = null; try { if (parent == null) { foundElement = HtmlElementUtils.locateElement(getLocator()); } else { foundElement = parent.locateChildElement(locator); } ...
java
public List<WebElement> getElements() { List<WebElement> foundElements = null; try { if (parent == null) { foundElements = HtmlElementUtils.locateElements(getLocator()); } else { foundElements = parent.locateChildElements(getLocator()); ...
java
private void addInfoForNoSuchElementException(NoSuchElementException cause) { if (parent == null) { throw cause; } BasicPageImpl page = this.parent.getCurrentPage(); if (page == null) { throw cause; } String resolvedPageName = page.getClass().ge...
java
public Object clickAndExpect(ExpectedCondition<?> expectedCondition) { dispatcher.beforeClick(this, expectedCondition); getElement().click(); if (Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.ENABLE_GUI_LOGGING))) { logUIAction(UIActions.CLICKED); } if...
java
public void hover(final Object... expected) { dispatcher.beforeHover(this, expected); new Actions(Grid.driver()).moveToElement(getElement()).perform(); try { for (Object expect : expected) { if (expect instanceof AbstractElement) { AbstractElemen...
java
@Override public Object[][] getAllData() { logger.entering(); Object[][] objectArray; if ((null == resource.getCls()) && (null != resource.getXpathMap())) { Document doc = getDocument(); Object[][][] multipleObjectDataProviders = new Object[resource.getXpathMap().siz...
java
@Override public Object[][] getAllKeyValueData() { logger.entering(); Object[][] objectArray; try { JAXBContext context = JAXBContext.newInstance(resource.getCls()); Unmarshaller unmarshaller = context.createUnmarshaller(); StreamSource xmlStreamSource = ...
java
@Override public Object[][] getDataByKeys(String[] keys) { logger.entering(Arrays.toString(keys)); if (null == resource.getCls()) { resource.setCls(KeyValueMap.class); } Object[][] objectArray; try { JAXBContext context = JAXBContext.newInstance(resou...
java
private List<?> loadDataFromXmlFile() { logger.entering(); Preconditions.checkArgument(resource.getCls() != null, "Please provide a valid type."); List<?> returned; try { JAXBContext context = JAXBContext.newInstance(Wrapper.class, resource.getCls()); Unmarshalle...
java
private List<?> loadDataFromXml(String xml, Class<?> cls) { logger.entering(new Object[] { xml, cls }); Preconditions.checkArgument(cls != null, "Please provide a valid type."); List<?> returned; try { JAXBContext context = JAXBContext.newInstance(Wrapper.class, cls); ...
java
@SuppressWarnings("unchecked") private String getFilteredXml(Document document, String xpathExpression) { logger.entering(new Object[] { document, xpathExpression }); List<Node> nodes = (List<Node>) document.selectNodes(xpathExpression); StringBuilder newDocument = new StringBuilder(documen...
java
private JsonObject generateConfigSummary() throws JsonParseException { logger.entering(); if (jsonConfigSummary == null) { jsonConfigSummary = new JsonObject(); for (Entry<String, String> temp : ConfigSummaryData.getConfigSummary().entrySet()) { jsonConfigSummar...
java
public void generateLocalConfigSummary(String suiteName, String testName) { logger.entering(new Object[] { suiteName, testName }); try { Map<String, String> testLocalConfigValues = ConfigSummaryData.getLocalConfigSummary(testName); JsonObject json = new JsonObject(); ...
java
public synchronized void insertConfigMethod(String suite, String test, String packages, String classname, ITestResult result) { logger.entering(new Object[] { suite, test, packages, classname, result }); String type = null; if (result.getMethod().isBeforeSuiteConfiguration()) { ...
java
public synchronized void writeJSON(String outputDirectory, boolean bForceWrite) { logger.entering(new Object[] { outputDirectory, bForceWrite }); long currentTime = System.currentTimeMillis(); if (!bForceWrite && (currentTime - previousTime < ONE_MINUTE)) { return; } ...
java
private void generateReports(String outputDirectory) { logger.entering(outputDirectory); ClassLoader localClassLoader = this.getClass().getClassLoader(); try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputDirectory + File.separator + "index.html")); BufferedWr...
java
private void generateHTMLReport(BufferedWriter writer, BufferedReader templateReader, String jsonReport) throws IOException { logger.entering(new Object[] { writer, templateReader, jsonReport }); String readLine = null; while ((readLine = templateReader.readLine()) != null) { ...
java
private JsonObject buildJSONReport() { logger.entering(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonArray testObjects = loadJSONArray(jsonCompletedTest); for (TestMethodInfo temp : completedTest) { testObjects.add(gson.fromJson(temp.toJson(), JsonElem...
java
private JsonObject getReportSummaryCounts(JsonArray testObjects) { logger.entering(testObjects); int runningCount = 0; int skippedCount = 0; int passedCount = 0; int failedCount = 0; String result; for (JsonElement test : testObjects) { result = test...
java
private JsonArray loadJSONArray(File jsonFile) throws JsonParseException { logger.entering(jsonFile); String jsonTxt; try { jsonTxt = FileUtils.readFileToString(jsonFile, "UTF-8"); } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage(), e); ...
java
private String[] getNodeProgramArguments() throws IOException { LOGGER.entering(); LOGGER.fine("This instance is considered a SeLion Grid Node"); List<String> args = new LinkedList<>(); if (!commands.contains(NODE_CONFIG_ARG)) { args.add(NODE_CONFIG_ARG); args....
java
private String[] getHubProgramArguments() throws IOException { LOGGER.entering(); LOGGER.fine("This instance is considered a SeLion Grid Hub"); List<String> args = new LinkedList<>(); if (!commands.contains(HUB_CONFIG_ARG)) { String hubConfig = HUB_CONFIG_FILE; ...
java
String getHost() { LOGGER.entering(); String val = ""; InstanceType type = getType(); if (commands.contains(HOST_ARG)) { val = commands.get(commands.indexOf(HOST_ARG) + 1); LOGGER.exiting(val); return val; } try { if (type...
java
int getPort() { LOGGER.entering(); int val = -1; InstanceType type = getType(); if (commands.contains(PORT_ARG)) { val = Integer.parseInt(commands.get(commands.indexOf(PORT_ARG) + 1)); LOGGER.exiting(val); return val; } try { ...
java
private String getSeleniumConfigFilePath() { LOGGER.entering(); String result = null; InstanceType type = getType(); if (type.equals(InstanceType.SELENIUM_NODE)) { result = NODE_CONFIG_FILE; if (commands.contains(NODE_CONFIG_ARG)) { result = comm...
java
private boolean matchAgainstMobileNodeType(Map<String, Object> nodeCapability, String mobileNodeType) { String nodeValue = (String) nodeCapability.get(MOBILE_NODE_TYPE); return !StringUtils.isBlank(nodeValue) && nodeValue.equalsIgnoreCase(mobileNodeType); }
java
public static RemoteNodeInformation getRemoteNodeInfo(String hostName, int port, SessionId session) { logger.entering(new Object[] { hostName, port, session }); RemoteNodeInformation node = null; String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: "; //...
java
public static String getBuildValue(SeLionBuildProperty property) { return getInfo().getProperty(property.getPropertyValue(), property.getFallBackValue()); }
java
public static SeLionDataProvider getDataProvider(DataResource resource) throws IOException { logger.entering(resource); if(resource == null) { return null; } switch (resource.getType().toUpperCase()) { case "XML": return new XmlDataProviderIm...
java
private boolean isSupportedOnHub(Class<? extends HttpServlet> servlet) { LOGGER.entering(); final boolean response = getRegistry().getHub().getConfiguration().servlets.contains(servlet.getCanonicalName()); LOGGER.exiting(response); return response; }
java
private boolean isSupportedOnNode(Class<? extends HttpServlet> servlet) { LOGGER.entering(); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT) .setSocketTimeout(CONNECTION_TIMEOUT).build(); CloseableHttpClient client = HttpClientBuilder....
java
public int getMaxConcurrency() { LOGGER.entering(); if (maxTestCase == -1) { try { SauceLabsHttpResponse result = doSauceRequest("/limits"); JsonObject obj = result.getEntityAsJsonObject(); maxTestCase = obj.get("concurrency").getAsInt(); ...
java
public static void assertNotEquals(Object actual, Object expected, String msg) { hardAssert.assertNotEquals(actual, expected, msg); }
java
public static void verifyEquals(Object actual, Object expected, String msg) { getSoftAssertInContext().assertEquals(actual, expected, msg); }
java
public static void verifyNotEquals(Object actual, Object expected, String msg) { getSoftAssertInContext().assertNotEquals(actual, expected, msg); }
java
public static void assertEquals(Object actual, Object expected, String message) { hardAssert.assertEquals(actual, expected, message); }
java
public static boolean wildCardMatch(String text, String pattern) { logger.entering(new Object[] { text, pattern }); Preconditions.checkArgument(text != null, "The text on which the search is to be run cannot be null."); Preconditions.checkArgument(pattern != null, "The search pattern cannot be n...
java
public void setId(String id) { logger.entering(id); this.id = id; logger.exiting(); }
java
public byte[] getScreenImage() { logger.entering(); logger.exiting(this.screenImage); return Arrays.copyOf(screenImage, screenImage.length); }
java
public void setScreenImage(byte[] content) { logger.entering(content); this.screenImage = Arrays.copyOf(content, content.length); logger.exiting(); }
java
public static void addReporterMetadataItem(String key, String itemType, String value) { logger.entering(new Object[] { key, itemType, value }); if (StringUtils.isNotBlank(value) && supportedMetaDataProperties.contains(itemType)) { Map<String, String> subMap = reporterMetadata.get(key); ...
java
public static String toJsonAsString() { logger.entering(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonObject configItem = new JsonObject(); for (Entry<String, Map<String, String>> entry : ReporterConfigMetadata.getReporterMetaData().entrySet()) { Map<Stri...
java
public static String getPackage(String element) { Preconditions.checkNotNull(element,"argument 'element' can not be null"); return element.substring(0, element.lastIndexOf('.')); }
java
public static String getClass(String element) { Preconditions.checkNotNull(element,"argument 'element' can not be null"); return element.substring(element.lastIndexOf('.') + 1); }
java
@Override public boolean filter(Object data) { logger.entering(new Object[] { data }); invocationCount += 1; for (int index : this.indexes) { if (invocationCount == index) { logger.exiting(true); return true; } } ...
java
public synchronized static void initConfig(ISuite suite) { SeLionLogger.getLogger().entering(suite); Map<ConfigProperty, String> initialValues = new HashMap<>(); for (ConfigProperty prop : ConfigProperty.values()) { String paramValue = suite.getParameter(prop.getName()); ...
java
public synchronized static void initConfig(ITestContext context) { SeLionLogger.getLogger().entering(context); Map<ConfigProperty, String> initialValues = new HashMap<>(); Map<String, String> testParams = context.getCurrentXmlTest().getLocalParameters(); if (!testParams.isEmpty()) { ...
java
public synchronized static void initConfig() { SeLionLogger.getLogger().entering(); Map<ConfigProperty, String> initialValues = new HashMap<>(); initConfig(initialValues); SeLionLogger.getLogger().exiting(); }
java
public static void printSeLionConfigValues() { SeLionLogger.getLogger().entering(); StringBuilder builder = new StringBuilder("SeLion configuration: {"); boolean isFirst = true; for (ConfigProperty configProperty : ConfigProperty.values()) { if (!isFirst) { bu...
java
public static synchronized void setConfigProperty(ConfigProperty configProperty, Object configPropertyValue) { checkArgument(configProperty != null, "Config property cannot be null."); checkArgument(configPropertyValue != null, "Config property value cannot be null."); getConfig().setProperty(co...
java
private boolean generateJavaCode(File baseFile, File dataFile, File extendedFile) { return (baseFile.lastModified() < dataFile.lastModified() || (extendedFile.exists() && baseFile.lastModified() < extendedFile .lastModified())); }
java
public static synchronized void spawnLocalHub(AbstractTestSession testSession) { LOGGER.entering(testSession.getPlatform()); if (!isRunLocally()) { LOGGER.exiting(); return; } setupToBootList(); for (LocalServerComponent eachItem : toBoot) { t...
java
static synchronized void shutDownHub() { LOGGER.entering(); if (!isRunLocally()) { LOGGER.exiting(); return; } // shutdown in reverse order Collections.reverse(toBoot); for (LocalServerComponent eachItem : toBoot) { eachItem.shutdown()...
java
public static void initReportData(List<ISuite> suites) { logger.entering(suites); if (!isReportInitialized) { for (ISuite suite : suites) { Map<String, ISuiteResult> r = suite.getResults(); for (ISuiteResult r2 : r.values()) { ITestContext ...
java
public static String getStringFromISODateString(String dateISOString) { Date date; String formattedDate; DateFormat formatter = getFormatter(); try { date = formatter.parse(dateISOString); formattedDate = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateForma...
java
public static Entry<String, String> formatReportDataForBrowsableReports(Entry<String, String> entryItem) { String key = entryItem.getKey(); String value = entryItem.getValue(); String formattedKey = key; String formattedValue = value; switch (key) { case ReporterDateFor...
java
public synchronized String getConfigProperty(Config.ConfigProperty configProperty) { SeLionLogger.getLogger().entering(configProperty); checkArgument(configProperty != null, "Config property cannot be null"); // Search locally then query SeLionConfig if not found String propValue = null...
java
public synchronized void setConfigProperty(Config.ConfigProperty configProperty, Object configPropertyValue) { checkArgument(configProperty != null, "Config property cannot be null"); checkArgument(checkNotInGlobalScope(configProperty), String.format("The configuration property (%s) is n...
java
public synchronized boolean isLocalValuePresent(ConfigProperty configProperty) { checkArgument(configProperty != null, "Config property cannot be null"); String value = baseConfig.getString(configProperty.getName()); return value != null; }
java
private void initSeLionRemoteProxySpecificValues(RemoteProxy proxy) { if (SeLionRemoteProxy.class.getCanonicalName().equals( proxy.getOriginalRegistrationRequest().getConfiguration().proxy)) { SeLionRemoteProxy srp = (SeLionRemoteProxy) proxy; // figure out if the proxy ...
java
private String appendMoreLogsLink(final String fileName, String url) throws IOException { FileBackedStringBuffer buffer = new FileBackedStringBuffer(); int index = retrieveIndexValueFromFileName(fileName); index++; File logFileName = retrieveFileFromLogsFolder(Integer.toString(index)); ...
java
private File getLogsDirectory() { if (logsDirectory != null) { return logsDirectory; } logsDirectory = new File(SeLionGridConstants.LOGS_DIR); if (!logsDirectory.exists()) { logsDirectory.mkdirs(); } return logsDirectory; }
java
protected void process(HttpServletRequest request, HttpServletResponse response, String fileName) throws IOException { // TODO put this html code in a template response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); response.setStatus(200); FileB...
java
private String renderLogFileContents(String fileName) throws IOException { FileBackedStringBuffer buffer = new FileBackedStringBuffer(); int index = retrieveIndexValueFromFileName(fileName); int runningIndex = 0; File eachFile = null; while ((eachFile = retrieveFileFromLogsFolder...
java
private File retrieveFileFromLogsFolder(String index) { File[] logFiles = getLogsDirectory().listFiles(new LogFilesFilter()); File fileToReturn = null; for (File eachLogFile : logFiles) { String fileName = eachLogFile.getName().split("\\Q.\\E")[0]; if (fileName.endsWith(i...
java
public static GuiMapReader getInstance(String pageDomain, String pageClassName) throws IOException { logger.entering(new Object[]{pageDomain, pageClassName}); Preconditions.checkArgument(StringUtils.isNotBlank(pageClassName), "pageClassName can not be null, empty, or whitespace"); ...
java
private static String getFilePath(String file) { logger.entering(file); String filePath = null; URL fileURL = GuiMapReaderFactory.class.getClassLoader().getResource(file); if (fileURL != null) { filePath = fileURL.getPath(); } logger.exiting(filePath); ...
java
public int getNumberOfColumns() { List<WebElement> cells; String xPath = getXPathBase() + "tr"; List<WebElement> elements = HtmlElementUtils.locateElements(xPath); if (elements.size() > 0 && getDataStartIndex() - 1 < elements.size()) { cells = elements.get(getDataStartIndex...
java
public void clickLinkInCell(int row, int column) { String xPath = getXPathBase() + "tr[" + row + "]/td[" + column + "]/a"; new Link(xPath).click(); }
java
public String getRowText(int rowIndex) { String rowText = null; String xPath = getXPathBase() + "tr[" + rowIndex + "]"; rowText = HtmlElementUtils.locateElement(xPath).getText(); return rowText; }
java
public void checkCheckboxInCell(int row, int column) { String checkboxLocator = getXPathBase() + "tr[" + row + "]/td[" + column + "]/input"; CheckBox cb = new CheckBox(checkboxLocator); cb.check(); }
java
public void uncheckCheckboxInCell(int row, int column) { String checkboxLocator = getXPathBase() + "tr[" + row + "]/td[" + column + "]/input"; CheckBox cb = new CheckBox(checkboxLocator); cb.uncheck(); }
java
protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean doStatusQuery = request.getParameter(PING_NODES) != null; String acceptHeader = request.getHeader("Accept"); if (acceptHeader != null && acceptHeader.equalsIgnoreCase("application/json")...
java
@Override public Object[][] getDataByKeys(String[] keys) { logger.entering(Arrays.toString(keys)); Object[][] obj = new Object[keys.length][1]; for (int i = 0; i < keys.length; i++) { obj[i][0] = getSingleExcelRow(getObject(), keys[i], true); } logger.exiting((Ob...
java
@Override public Iterator<Object[]> getDataByFilter(DataProviderFilter dataFilter) { logger.entering(dataFilter); List<Object[]> objs = new ArrayList<>(); Field[] fields = resource.getCls().getDeclaredFields(); // Extracting number of rows of data to read // Notice that numR...
java