Robot Class In Selenium WebDriver

During automation activity Selenium often find difficulty to find an object and perform actions which is related to mouse or keyboard type of activity. It is not easy to perform keyboard or mouse events using selenium commands. There are many specific scenarios where any selenium command is launched but actual event did not fired. This result that execution of test is stopped and it reports some error.

Read More »

JSON.simple example – Write JSON

1. JSON.simple Dependency

JSON.simple is available at Maven central repository, just declares following dependency in your pom.xml file.

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>

2. Write JSON to file

In below example, it write JSON data via JSONObject and JSONArray, and save it into a file named “test.json“.

import java.io.FileWriter;
import java.io.IOException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class JsonSimpleExample {
public static void main(String[] args) {

JSONObject obj = new JSONObject();
obj.put(“name”, “mkyong.com”);
obj.put(“age”, new Integer(100));

JSONArray list = new JSONArray();
list.add(“msg 1”);
list.add(“msg 2”);
list.add(“msg 3”);

obj.put(“messages”, list);

try {

FileWriter file = new FileWriter(“c:\\test.json”);
file.write(obj.toJSONString());
file.flush();
file.close();

} catch (IOException e) {
e.printStackTrace();
}
System.out.print(obj);
}
}

Output – See content of file named “test.json“.

{
“age”:100,
“name”:”seleniumsuite.com”,
“messages”:[“msg 1″,”msg 2″,”msg 3”]
}