2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.US;
24 import java.io.IOException;
25 import java.net.InetSocketAddress;
26 import java.net.Proxy;
27 import java.net.ProxySelector;
28 import java.net.SocketAddress;
30 import java.util.List;
32 import org.openqa.selenium.By;
33 import org.openqa.selenium.WebDriver;
34 import org.openqa.selenium.WebElement;
35 import org.openqa.selenium.firefox.FirefoxDriver;
36 import org.openqa.selenium.remote.CapabilityType;
37 import org.openqa.selenium.remote.DesiredCapabilities;
38 import org.testng.AssertJUnit;
39 import org.testng.annotations.AfterClass;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.Test;
43 import com.github.markusbernhardt.proxy.ProxySearch;
44 import com.github.markusbernhardt.proxy.ProxySearch.Strategy;
46 import net.lightbody.bmp.BrowserMobProxyServer;
47 import net.lightbody.bmp.client.ClientUtil;
48 import net.lightbody.bmp.core.har.Har;
49 import net.lightbody.bmp.proxy.CaptureType;
51 public class MobProxy {
52 public static WebDriver driver;
53 public static BrowserMobProxyServer server;
56 public void setup() throws Exception {
58 ProxySearch proxySearch = new ProxySearch();
59 proxySearch.addStrategy(Strategy.OS_DEFAULT);
60 proxySearch.addStrategy(Strategy.JAVA);
61 proxySearch.addStrategy(Strategy.BROWSER);
62 ProxySelector proxySelector = proxySearch.getProxySelector();
64 ProxySelector.setDefault(proxySelector);
65 URI home = URI.create("http://www.google.com");
66 System.out.println("ProxySelector: " + proxySelector);
67 System.out.println("URI: " + home);
68 List<Proxy> proxyList = proxySelector.select(home);
71 if (proxyList != null && !proxyList.isEmpty()) {
72 for (Proxy proxy : proxyList) {
73 System.out.println(proxy);
74 SocketAddress address = proxy.address();
75 if (address instanceof InetSocketAddress) {
76 host = ((InetSocketAddress) address).getHostName();
77 port = Integer.toString(((InetSocketAddress) address).getPort());
78 System.setProperty("http.proxyHost", host);
79 System.setProperty("http.proxyPort", port);
84 server = new BrowserMobProxyServer();
85 InetSocketAddress address = new InetSocketAddress(host, Integer.parseInt(port));
86 server.setChainedProxy(address);
88 int port1 = server.getPort();
89 DesiredCapabilities seleniumCapabilities = new DesiredCapabilities();
90 seleniumCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
91 seleniumCapabilities.setCapability(CapabilityType.PROXY, ClientUtil.createSeleniumProxy(server));
92 driver = new FirefoxDriver(seleniumCapabilities);
93 server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
94 System.out.println("Port started:" + port1);
98 public void first_test1() throws InterruptedException {
100 server.newHar("asdc.har");
102 driver.get("https://www.e-access.att.com/QA-SCRUM1/sdc1/portal#/dashboard");
103 driver.manage().window().maximize();
105 WebElement userNameTextbox = driver.findElement(By.name("userid"));
106 userNameTextbox.sendKeys("m99121");
107 WebElement passwordTextbox = driver.findElement(By.name("password"));
108 passwordTextbox.sendKeys("66-Percent");
110 WebElement submitButton = driver.findElement(By.name("btnSubmit"));
111 submitButton.click();
113 WebElement buttonOK = driver.findElement(By.name("successOK"));
114 AssertJUnit.assertTrue(buttonOK.isDisplayed());
117 driver.findElement(By.xpath(getXpath("main-menu-button-catalog"))).click();
119 driver.findElement(By.xpath(getXpath("checkbox-service"))).click();
123 public static String getXpath(String dataTestId){
124 return String.format("//*[@data-tests-id='%s']", dataTestId);
128 public void shutdown() {
132 Har har = server.getHar();
133 File harFile = new File("C:\\temp\\asdc.har");
134 har.writeTo(harFile);
136 } catch (IOException ioe) {
137 ioe.printStackTrace();