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.ProxySelector;
27 import java.net.SocketAddress;
29 import java.util.List;
31 import java.net.Proxy;
33 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
34 import org.openqa.selenium.By;
35 import org.openqa.selenium.WebDriver;
36 import org.openqa.selenium.WebElement;
37 import org.openqa.selenium.firefox.FirefoxDriver;
38 import org.openqa.selenium.remote.CapabilityType;
39 import org.openqa.selenium.remote.DesiredCapabilities;
40 import org.testng.AssertJUnit;
41 import org.testng.annotations.AfterClass;
42 import org.testng.annotations.BeforeClass;
43 import org.testng.annotations.Test;
45 import com.github.markusbernhardt.proxy.ProxySearch;
46 import com.github.markusbernhardt.proxy.ProxySearch.Strategy;
48 import net.lightbody.bmp.BrowserMobProxyServer;
49 import net.lightbody.bmp.client.ClientUtil;
50 import net.lightbody.bmp.core.har.Har;
51 import net.lightbody.bmp.proxy.CaptureType;
53 public class MobProxy {
54 public static WebDriver driver;
55 public static BrowserMobProxyServer server;
58 public void setup() throws Exception {
60 ProxySearch proxySearch = new ProxySearch();
61 proxySearch.addStrategy(Strategy.OS_DEFAULT);
62 proxySearch.addStrategy(Strategy.JAVA);
63 proxySearch.addStrategy(Strategy.BROWSER);
64 ProxySelector proxySelector = proxySearch.getProxySelector();
66 ProxySelector.setDefault(proxySelector);
67 URI home = URI.create("http://www.google.com");
68 System.out.println("ProxySelector: " + proxySelector);
69 System.out.println("URI: " + home);
70 List<Proxy> proxyList = proxySelector.select(home);
73 if (proxyList != null && !proxyList.isEmpty()) {
74 for (Proxy proxy : proxyList) {
75 System.out.println(proxy);
76 SocketAddress address = proxy.address();
77 if (address instanceof InetSocketAddress) {
78 host = ((InetSocketAddress) address).getHostName();
79 port = Integer.toString(((InetSocketAddress) address).getPort());
80 System.setProperty("http.proxyHost", host);
81 System.setProperty("http.proxyPort", port);
86 server = new BrowserMobProxyServer();
87 InetSocketAddress address = new InetSocketAddress(host, Integer.parseInt(port));
88 server.setChainedProxy(address);
90 int port1 = server.getPort();
91 DesiredCapabilities seleniumCapabilities = new DesiredCapabilities();
92 seleniumCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
93 seleniumCapabilities.setCapability(CapabilityType.PROXY, ClientUtil.createSeleniumProxy(server));
94 driver = new FirefoxDriver(seleniumCapabilities);
95 server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
96 System.out.println("Port started:" + port1);
100 public void first_test1() throws InterruptedException {
102 server.newHar("asdc.har");
104 driver.get("https://www.e-access.att.com/QA-SCRUM1/sdc1/portal#/dashboard");
105 driver.manage().window().maximize();
107 WebElement userNameTextbox = driver.findElement(By.name("userid"));
108 userNameTextbox.sendKeys("m99121");
109 WebElement passwordTextbox = driver.findElement(By.name("password"));
110 passwordTextbox.sendKeys("66-Percent");
112 WebElement submitButton = driver.findElement(By.name("btnSubmit"));
113 submitButton.click();
115 WebElement buttonOK = driver.findElement(By.name("successOK"));
116 AssertJUnit.assertTrue(buttonOK.isDisplayed());
119 driver.findElement(By.xpath(getXpath("main-menu-button-catalog"))).click();
121 driver.findElement(By.xpath(getXpath("checkbox-service"))).click();
125 public static String getXpath(String dataTestId){
126 return String.format("//*[@data-tests-id='%s']", dataTestId);
130 public void shutdown() {
134 Har har = server.getHar();
135 File harFile = new File("C:\\temp\\asdc.har");
136 har.writeTo(harFile);
138 } catch (IOException ioe) {
139 ioe.printStackTrace();