diff --git a/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/pom.xml b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/pom.xml new file mode 100644 index 0000000..856269f --- /dev/null +++ b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + automation.com + qa + 0.0.1-SNAPSHOT + + + + org.testng + testng + 6.8.13 + + + org.seleniumhq.selenium + selenium-java + 2.42.1 + + + org.seleniumhq.selenium + selenium-firefox-driver + 2.43.1 + + + postgresql + postgresql + 9.1-901.jdbc4 + + + javax.xml.soap + javax.xml.soap-api + 1.3.5 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + + src/test/resources/testng.xml + + 1.7 + 1.7 + + + + + + + \ No newline at end of file diff --git a/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/FeatureTests.java b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/FeatureTests.java new file mode 100644 index 0000000..f95608c --- /dev/null +++ b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/FeatureTests.java @@ -0,0 +1,62 @@ +package core.tests.com; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class FeatureTests { + + // We take url from testng file + @Test + @Parameters({ "url" }) + public void simpleTestLogInToGmail(String url) throws InterruptedException { + // Run fire fox + WebDriver driver = new FirefoxDriver(); + driver.get(url); + driver.manage().window().maximize(); // maximize window + Thread.sleep(5000); + + // Log in to gmail + + // Find object + WebElement loginField = getElementById(driver, "Email"); + WebElement passwordField = getElementById(driver, "Passwd"); + WebElement signInButton = getElementById(driver, "signIn"); + + // Fill in form and log in + loginField.sendKeys("gmail@gmail.com"); + passwordField.sendKeys("XXXXXXXX"); + signInButton.click(); + Thread.sleep(5000); + + // delete all emails from inbox + WebElement checkBoxAllEmails = getElementByXpath( + driver, + "//html/body/div[7]/div[3]/div/div[2]/div/div[2]/div/div/div/div/div/div/div/div/div/div/div/div/span/div"); + WebElement deleteButton = getElementByXpath( + driver, + "//html/body/div[7]/div[3]/div/div[2]/div/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div[3]/div/div"); + + checkBoxAllEmails.click(); + Thread.sleep(5000); + deleteButton.click(); + + Thread.sleep(5000); + driver.quit(); + + } + + private WebElement getElementById(WebDriver driver, String id) { + + return driver.findElement(By.id(id)); + } + + private WebElement getElementByXpath(WebDriver driver, String xpath) { + + return driver.findElement(By.xpath(xpath)); + } +} diff --git a/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/JsonControler.java b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/JsonControler.java new file mode 100644 index 0000000..811e641 --- /dev/null +++ b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/JsonControler.java @@ -0,0 +1,64 @@ +package core.tests.com; + +import java.io.IOException; +import java.net.SocketException; + +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicHeader; +import org.apache.http.protocol.HTTP; +import org.json.JSONException; +import org.testng.Assert; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class JsonControler { + + @Test + @Parameters({ "url" }) + public void simpleTestLogInToGmail(String url) throws InterruptedException, + ClientProtocolException, IOException, JSONException { + + // Create json + String json = "{\"user1\": {\"name\": \"Jamse\",\"email\": \"main_window@mail.com\",\"age\": 50,}" + + ",\"user2\": {\"name\": \"Bond\",\"email\":\"aston@mail.com\",\"age\": 49,}," + + " \"user3\": {\"name\": \"Weider\"\"email\": \"starwars@mail.com\",\"age\": 500,}}"; + + // Send json to api + HttpResponse response = sendJSon(url, json); + + + //Compare result + Assert.assertTrue(response.toString().contains("200")); + System.out.println("DEBUG1:" + response); + + + } + + public static HttpResponse sendJSon(String url, String json) + throws ClientProtocolException, IOException, JSONException { + HttpPost request = new HttpPost( + "https://api.rest-test-app.com/users/add"); // meyhod post + StringEntity entity = new StringEntity(json); + entity.setContentType("application/json;charset=UTF-8"); + entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, + "application/json;charset=UTF-8")); + request.addHeader("Authorization", "Basic "); // if we need + // authorization + request.setEntity(entity); + HttpResponse response = null; + HttpClient httpclient = HttpClientBuilder.create().build(); + try { + response = httpclient.execute(request); + System.out.println(response); + return response; + } catch (SocketException se) { + throw se; + } + } + +} diff --git a/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/WebServiceTest.java b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/WebServiceTest.java new file mode 100644 index 0000000..1c425c0 --- /dev/null +++ b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/core/tests/com/WebServiceTest.java @@ -0,0 +1,88 @@ +package core.tests.com; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.Charset; + +import javax.xml.soap.MessageFactory; +import javax.xml.soap.MimeHeaders; +import javax.xml.soap.SOAPConnection; +import javax.xml.soap.SOAPConnectionFactory; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPMessage; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class WebServiceTest { + + @Test + public void testForWS()throws Exception { + + SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory + .newInstance(); + SOAPConnection soapConnection = soapConnectionFactory + .createConnection(); + + // Send SOAP Message to SOAP Server + String url = "http://helpqaspb.com:8080/ws/"; + + String xml = " " + + "" + + "" + + "Spain" + + "" + + "" + ""; + SOAPMessage soapResponse = soapConnection.call( + getSoapMessageFromString(xml), url); + + // Process the SOAP Response + String responce = printSOAPResponse(soapResponse); + //Check responce + Assert.assertTrue(responce.contains("EUR")); + Assert.assertTrue(responce.contains("46704314")); + + + } + + public static SOAPMessage getSoapMessageFromString(String xml) + throws SOAPException, IOException { + MessageFactory factory = MessageFactory.newInstance(); + SOAPMessage message = factory + .createMessage( + new MimeHeaders(), + new ByteArrayInputStream(xml.getBytes(Charset + .forName("UTF-8")))); + return message; + } + + /** + * Method used to print the SOAP Response + */ + private static String printSOAPResponse(SOAPMessage soapResponse) + throws Exception { + TransformerFactory transformerFactory = TransformerFactory + .newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + Source sourceContent = soapResponse.getSOAPPart().getContent(); + System.out.print("\nResponse SOAP Message = "); + StreamResult result = new StreamResult(System.out); + transformer.transform(sourceContent, result); + + StringWriter writer = new StringWriter(); + StreamResult result1 = new StreamResult(writer); + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer transformer1 = tFactory.newTransformer(); + transformer1.transform(sourceContent,result1); + return writer.toString(); + } + +} + + \ No newline at end of file diff --git a/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/testng.xml b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/testng.xml new file mode 100644 index 0000000..2a8e892 --- /dev/null +++ b/functional test automation/webdriver/AutomationTest_RestApi_Soap_WebApp/qa/src/main/java/testng.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +