After having test execution from automation script, is it a manual task to post bugs? No. We can do with the help of XML-RPC support by bugzilla.
Pre-requisite:
Code:
HttpClient httpClient = new HttpClient();
XmlRpcClient rpcClient = new XmlRpcClient();
XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(rpcClient);
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
factory.setHttpClient(httpClient);
rpcClient.setTransportFactory(factory);
config.setServerURL(new URL("http://bugzillaofyours/xmlrpc.cgi"));
rpcClient.setConfig(config);
HashMap<String, String> loginMap = new HashMap<String, String>();
loginMap.put("login", "email id");
loginMap.put("password", "password");
loginMap.put("rememberlogin", "Bugzilla_remember");
// login to bugzilla
Object loginResult = rpcClient.execute("User.login", new Object[] { loginMap });
System.err.println("loginResult=" + loginResult);
System.out.println(loginResult);
// map of the bug data
HashMap<String, String> bugMap = new HashMap<String, String>();
bugMap.put("product", "Test-Auto");
bugMap.put("component", "test");
bugMap.put("summary", "Bug created from groovy script");
bugMap.put("description", "This is text including stacktrace");
bugMap.put("version", "1");
bugMap.put("op_sys", "Linux");
bugMap.put("platform", "PC");
bugMap.put("priority", "Normal");
bugMap.put("severity", "Normal");
bugMap.put("status", "CONFIRMED");
// Having one custom field on adding bug screen.
bugMap.put("cf_functionality", "Test");
// create a bug
Object createResult = rpcClient.execute("Bug.create", new Object[] { bugMap });
System.err.println("createResult = " + createResult);
System.out.println(createResult.toString().replace("{id=", "").replace("}", ""));
String strBugID = createResult.toString().replace("{id=", "").replace("}", "");
if (strBugID.length() > 0) {
String str = encoder("full path/fail.png");
HashMap<String, Object> bugAttachmentMap = new HashMap<String, Object>();
bugAttachmentMap.put("ids", strBugID);
bugAttachmentMap.put("data", str);
bugAttachmentMap.put("file_name", "bug");
bugAttachmentMap.put("summary", "Summary");
bugAttachmentMap.put("content_type", "image/png");
// create attachment
Object bugAttachment = rpcClient.execute("Bug.add_attachment", new Object[] { bugAttachmentMap });
System.err.println("createResult = " + bugAttachment);
System.out.println(bugAttachment);
Pre-requisite:
- <!-- https://mvnrepository.com/artifact/org.apache.xmlrpc/xmlrpc-client -->
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>
<version>3.1.3</version>
</dependency> - Make sure to use java 1.8+ as have used Base64
Objective: If test becomes failure then need to report a bug.
Code:
HttpClient httpClient = new HttpClient();
XmlRpcClient rpcClient = new XmlRpcClient();
XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(rpcClient);
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
factory.setHttpClient(httpClient);
rpcClient.setTransportFactory(factory);
config.setServerURL(new URL("http://bugzillaofyours/xmlrpc.cgi"));
rpcClient.setConfig(config);
HashMap<String, String> loginMap = new HashMap<String, String>();
loginMap.put("login", "email id");
loginMap.put("password", "password");
loginMap.put("rememberlogin", "Bugzilla_remember");
// login to bugzilla
Object loginResult = rpcClient.execute("User.login", new Object[] { loginMap });
System.err.println("loginResult=" + loginResult);
System.out.println(loginResult);
// map of the bug data
HashMap<String, String> bugMap = new HashMap<String, String>();
bugMap.put("product", "Test-Auto");
bugMap.put("component", "test");
bugMap.put("summary", "Bug created from groovy script");
bugMap.put("description", "This is text including stacktrace");
bugMap.put("version", "1");
bugMap.put("op_sys", "Linux");
bugMap.put("platform", "PC");
bugMap.put("priority", "Normal");
bugMap.put("severity", "Normal");
bugMap.put("status", "CONFIRMED");
// Having one custom field on adding bug screen.
bugMap.put("cf_functionality", "Test");
// create a bug
Object createResult = rpcClient.execute("Bug.create", new Object[] { bugMap });
System.err.println("createResult = " + createResult);
System.out.println(createResult.toString().replace("{id=", "").replace("}", ""));
String strBugID = createResult.toString().replace("{id=", "").replace("}", "");
if (strBugID.length() > 0) {
String str = encoder("full path/fail.png");
HashMap<String, Object> bugAttachmentMap = new HashMap<String, Object>();
bugAttachmentMap.put("ids", strBugID);
bugAttachmentMap.put("data", str);
bugAttachmentMap.put("file_name", "bug");
bugAttachmentMap.put("summary", "Summary");
bugAttachmentMap.put("content_type", "image/png");
// create attachment
Object bugAttachment = rpcClient.execute("Bug.add_attachment", new Object[] { bugAttachmentMap });
System.err.println("createResult = " + bugAttachment);
System.out.println(bugAttachment);
No comments:
Post a Comment