To Post a tweet on Twitter timeline follow below steps:
Step 1: Create a twitter account. Add your mobile number if not already added.
Step 2: Create your app on Twitter and generate keys and tokens. Follow steps here.
Step 3: Add following code
public class TwitterAPITest
{
String consumerKey = "s1lAvT5uU3fPLhzgI5m4cFBz8";
String consumerSecret = "0QU8aC58Ypy0hJQIeqs4Y1PJwjWV2OffdthjJ55JZJvZaGccns";
String accessToken = "1441253365-gAUOzD1QjLZg7CCKpKJ84j8HRuONiTSGi9r9mZn";
String tokenSecret = "tM1y94Nx4rD9iQirOIL9xxuUlGOForSLK7xGzlpl4Oy2y";
@BeforeClass
public void setup()
{
RestAssured.baseURI = "https://api.twitter.com";
RestAssured.basePath = "/1.1/statuses";
}
/*Post request example*/
@Test(enabled=false)
public void postExample()
{
given()
.auth()
.oauth(consumerKey, consumerSecret, accessToken, tokenSecret)
.queryParam("status", "REST Assured Automation Tweet.")
.header("Content-Type","application/json")
.when()
.post("/update.json")
.then()
.statusCode(200);
}
}