Best Testsigma code snippet using com.testsigma.service.JiraService.uploadScreenshots
Source:JiraService.java
...67 log.error(response.getResponseText());68 throw new TestsigmaException("Problem while creating jira issue with ::" + mapping.getFields());69 }70 uploadVideo(mapping);71 uploadScreenshots(mapping);72 mapping.setExternalId(new JSONObject(response.getResponseText()).optString("key", null));73 mapping.setMisc(response.getResponseText());74 return mapping;75 }76 public void unlink(TestCaseResultExternalMapping mapping) throws TestsigmaException {77 JsonNodeFactory jnf = JsonNodeFactory.instance;78 ObjectNode payload = jnf.objectNode();79 payload.putPOJO("body", "Unlinked from testsigma results [" + applicationConfig.getServerUrl() + "/ui/td/test_case_results/" + mapping.getTestCaseResultId() + "] :: " + mapping.getTestCaseResult().getTestCase().getName());80 HttpResponse<String> response = httpClient.post(integrations.getUrl() + "/rest/api/2/issue/" + mapping.getExternalId() + "/comment", getHeaders(), payload, new TypeReference<String>() {81 });82 if (response.getStatusCode() != HttpStatus.SC_CREATED) {83 log.error(response.getResponseText());84 throw new TestsigmaException("Problem while unlinking jira issue with ::" + mapping.getFields());85 }86 }87 public List<JiraProjectDTO> getIssueFields(String projectId, String issueType) throws TestsigmaException, EncoderException {88 String query = "?expand=projects.issuetypes.fields";89 if (projectId != null)90 query += "&projectKeys=" + new URLCodec().encode(projectId);91 if (issueType != null)92 query += "&issuetypeNames=" + new URLCodec().encode(issueType);93 HttpResponse<String> response = httpClient.get(integrations.getUrl() + "/rest/api/3/issue/createmeta" + query, getHeaders(), new TypeReference<String>() {94 });95 JSONObject createMeta = new JSONObject(response.getResponseText());96 JSONArray projects = new JSONArray();97 if (createMeta.has("projects")) {98 projects = createMeta.getJSONArray("projects");99 }100 List<JiraProjectDTO> jiraProjectDTOS = new ArrayList<>();101 try {102 jiraProjectDTOS = om.readValue(String.valueOf(projects), TypeFactory.defaultInstance().constructCollectionType(List.class,103 JiraProjectDTO.class));104 } catch (IOException e) {105 log.error(e.getMessage(), e);106 }107 return jiraProjectDTOS;108 }109 public JsonNode testIntegration(IntegrationsRequest testAuth) throws TestsigmaException {110 Header contentType = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json");111 String authHeader = HttpClient.getBasicAuthString(testAuth.getUsername() + ":" + testAuth.getPassword());112 Header authentication = new BasicHeader(HttpHeaders.AUTHORIZATION, "Basic " + authHeader);113 List<Header> headers = Lists.newArrayList(contentType, authentication);114 String query = "?expand=projects.issuetypes.fields";115 HttpResponse<JsonNode> response = httpClient.get(testAuth.getUrl() + "/rest/api/3/issue/createmeta" + query, headers, new TypeReference<JsonNode>() {116 });117 JsonNodeFactory jnf = JsonNodeFactory.instance;118 ObjectNode status = jnf.objectNode();119 status.put("status_code", response.getStatusCode());120 status.put("status_message", response.getStatusMessage());121 return status;122 }123 public Map<String, Object> fetchIssue(TestCaseResultExternalMapping mapping) throws TestsigmaException {124 HttpResponse<Map<String, Object>> response = httpClient.get(integrations.getUrl() + "/rest/api/2/issue/" + mapping.getExternalId() + "?expand=names,renderedFields", getHeaders(), new TypeReference<Map<String, Object>>() {125 });126 return response.getResponseEntity();127 }128 public TestCaseResultExternalMapping link(TestCaseResultExternalMapping mapping) throws TestsigmaException {129 JsonNodeFactory jnf = JsonNodeFactory.instance;130 ObjectNode payload = jnf.objectNode();131 payload.putPOJO("body", "Linked to testsigma results [" + applicationConfig.getServerUrl() + "/ui/td/test_case_results/" + mapping.getTestCaseResultId() + "] :: " + mapping.getTestCaseResult().getTestCase().getName());132 HttpResponse<String> response = httpClient.post(integrations.getUrl() + "/rest/api/2/issue/" + mapping.getExternalId() + "/comment", getHeaders(), payload, new TypeReference<String>() {133 });134 if (response.getStatusCode() != HttpStatus.SC_CREATED) {135 log.error(response.getResponseText());136 throw new TestsigmaException("Problem while Linking jira issue with ::" + mapping.getFields());137 }138 return mapping;139 }140 public JsonNode getIssuesList(String projectId, String issueType, String summary) throws TestsigmaException {141 JsonNodeFactory jnf = JsonNodeFactory.instance;142 ObjectNode payload = jnf.objectNode();143 {144 String jqlString = "project = " + projectId;145 if (issueType != null) {146 jqlString += " AND issuetype = " + issueType;147 }148 if (summary != null) {149 jqlString += " AND summary ~ '" + summary + "*'";150 }151 payload.put("jql", jqlString);152 ArrayNode fields = payload.putArray("fields");153 {154 fields.add("id");155 fields.add("key");156 fields.add("summary");157 fields.add("description");158 fields.add("status");159 }160 }161 HttpResponse<JsonNode> response = httpClient.post(integrations.getUrl() + "/rest/api/2/search", getHeaders(), payload, new TypeReference<JsonNode>() {162 });163 return response.getResponseEntity();164 }165 private List<Header> getHeaders() {166 Header contentType = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json");167 String authHeader = HttpClient.getBasicAuthString(this.integrations.getUsername() + ":" + this.integrations.getPassword());168 Header authentication = new BasicHeader(HttpHeaders.AUTHORIZATION, "Basic " + authHeader);169 return Lists.newArrayList(contentType, authentication);170 }171 private List<Header> getUploadHeaders() {172 Header contentType = new BasicHeader("X-Atlassian-Token", "nocheck");173 String authHeader = HttpClient.getBasicAuthString(this.integrations.getUsername() + ":" + this.integrations.getPassword());174 Header authentication = new BasicHeader(HttpHeaders.AUTHORIZATION, "Basic " + authHeader);175 return Lists.newArrayList(contentType, authentication);176 }177 private void uploadVideo(TestCaseResultExternalMapping mapping) {178 (new Thread(new Runnable() {179 public void run() {180 try {181 String videoFullPath = "/executions/videos/" + mapping.getTestCaseResult().getEnvironmentResultId() + "/video.mp4";182 Calendar cal = Calendar.getInstance();183 cal.add(Calendar.MINUTE, 30);184 Optional<URL> url = storageServiceFactory.getStorageService().generatePreSignedURLIfExists(videoFullPath, StorageAccessLevel.READ);185 if (url != null && url.isPresent()) {186 httpClient.post(integrations.getUrl() + "/rest/api/2/issue/" + mapping.getExternalId() + "/attachments", getUploadHeaders(), "video.mp4", url.get().openStream(), new TypeReference<Map<String, Object>>() {187 }, null);188 }189 } catch (Exception e) {190 log.error(e.getMessage(), e);191 log.error("Problem while uploading video as attachment to jira issue::" + mapping.getExternalId());192 }193 }194 })).start();195 }196 private void uploadScreenshots(TestCaseResultExternalMapping mapping) {197 List<TestStepResult> stepResults = testStepResultService.findAllByTestCaseResultIdAndScreenshotNameIsNotNull(mapping.getTestCaseResultId());198 (new Thread(new Runnable() {199 public void run() {200 try {201 for (TestStepResult stepResult : stepResults) {202 String fileFullPath =203 "/executions/" + mapping.getTestCaseResultId() + "/" + stepResult.getScreenshotName();204 Calendar cal = Calendar.getInstance();205 cal.add(Calendar.MINUTE, 30);206 Optional<URL> url = storageServiceFactory.getStorageService().generatePreSignedURLIfExists(fileFullPath, StorageAccessLevel.READ);207 if (url != null && url.isPresent()) {208 httpClient.post(integrations.getUrl() + "/rest/api/2/issue/" + mapping.getExternalId() + "/attachments", getUploadHeaders(), stepResult.getScreenshotName(), url.get().openStream(), new TypeReference<Map<String, Object>>() {209 }, null);210 }...
uploadScreenshots
Using AI Code Generation
1import com.testsigma.service.JiraService;2import com.testsigma.service.JiraService;3import java.util.ArrayList;4import java.util.List;5List<String> screenshots = new ArrayList<String>();6screenshots.add("C:\\Users\\testsigma\\Desktop\\Jira\\1.png");7screenshots.add("C:\\Users\\testsigma\\Desktop\\Jira\\2.png");8screenshots.add("C:\\Users\\testsigma\\Desktop\\Jira\\3.png");9List<String> attachmentNames = new ArrayList<String>();10attachmentNames.add("1.png");11attachmentNames.add("2.png");12attachmentNames.add("3.png");13JiraService jiraService = new JiraService();
uploadScreenshots
Using AI Code Generation
1import com.testsigma.service.JiraService;2import com.testsigma.service.JiraServiceFactory;3import java.io.File;4import java.io.IOException;5import java.util.logging.Level;6import java.util.logging.Logger;7public class JiraServiceTest {8 public static void main(String[] args) {9 JiraService jiraService = JiraServiceFactory.getJiraService();10 try {11 jiraService.uploadScreenshots("JIRA", "JIRA-1", new File("C:\\Users\\TestSigma\\Desktop\\TestSigma\\jira.jpg"), "Jira screenshot");12 } catch (IOException ex) {13 Logger.getLogger(JiraServiceTest.class.getName()).log(Level.SEVERE, null, ex);14 }15 }16}17import com.testsigma.service.JiraService;18import com.testsigma.service.JiraServiceFactory;19public class JiraServiceTest {20 public static void main(String[] args) {21 }22}23import com.testsigma.service.JiraService;24import com.testsigma.service.JiraServiceFactory;25public class JiraServiceTest {26 public static void main(String[] args) {27 JiraService jiraService = JiraServiceFactory.getJiraService();28 jiraService.addComment("JIRA", "JIRA-1", "Comment added");29 }30}
uploadScreenshots
Using AI Code Generation
1import com.testsigma.service.JiraService;2JiraService jiraService = new JiraService();3jiraService.uploadScreenshots("TC-1", "C:\\Users\\user\\Desktop\\screenshot1.png", "C:\\Users\\user\\Desktop\\screenshot2.png");4JiraService jiraService = new JiraService();5jiraService.uploadScreenshots("TC-1", "C:\\Users\\user\\Desktop\\screenshot1.png", "C:\\Users\\user\\Desktop\\screenshot2.png");6import com.testsigma.service.JiraService;7JiraService jiraService = new JiraService();8jiraService.uploadScreenshots("TC-1", "C:\\Users\\user\\Desktop\\screenshot1.png", "C:\\Users\\user\\Desktop\\screenshot2.png");9JiraService jiraService = new JiraService();10jiraService.uploadScreenshots("TC-1", "C:\\Users\\user\\Desktop\\screenshot1.png", "C:\\Users\\user\\Desktop\\screenshot2.png");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!