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;
23 import com.github.markusbernhardt.proxy.ProxySearch;
24 import com.github.markusbernhardt.proxy.ProxySearch.Strategy;
25 import net.lightbody.bmp.BrowserMobProxyServer;
26 import net.lightbody.bmp.client.ClientUtil;
27 import net.lightbody.bmp.core.har.Har;
28 import net.lightbody.bmp.proxy.CaptureType;
29 import org.openqa.selenium.By;
30 import org.openqa.selenium.WebDriver;
31 import org.openqa.selenium.WebElement;
32 import org.openqa.selenium.firefox.FirefoxDriver;
33 import org.openqa.selenium.remote.CapabilityType;
34 import org.openqa.selenium.remote.DesiredCapabilities;
35 import org.testng.AssertJUnit;
36 import org.testng.annotations.AfterClass;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.Test;
41 import java.io.IOException;
43 import java.util.List;
45 public class MobProxy {
46 public static WebDriver driver;
47 public static BrowserMobProxyServer server;
50 public void setup() throws Exception {
52 ProxySearch proxySearch = new ProxySearch();
53 proxySearch.addStrategy(Strategy.OS_DEFAULT);
54 proxySearch.addStrategy(Strategy.JAVA);
55 proxySearch.addStrategy(Strategy.BROWSER);
56 ProxySelector proxySelector = proxySearch.getProxySelector();
58 ProxySelector.setDefault(proxySelector);
59 URI home = URI.create("http://www.google.com");
60 System.out.println("ProxySelector: " + proxySelector);
61 System.out.println("URI: " + home);
62 List<Proxy> proxyList = proxySelector.select(home);
65 if (proxyList != null && !proxyList.isEmpty()) {
66 for (Proxy proxy : proxyList) {
67 System.out.println(proxy);
68 SocketAddress address = proxy.address();
69 if (address instanceof InetSocketAddress) {
70 host = ((InetSocketAddress) address).getHostName();
71 port = Integer.toString(((InetSocketAddress) address).getPort());
72 System.setProperty("http.proxyHost", host);
73 System.setProperty("http.proxyPort", port);
78 server = new BrowserMobProxyServer();
79 InetSocketAddress address = new InetSocketAddress(host, Integer.parseInt(port));
80 server.setChainedProxy(address);
82 int port1 = server.getPort();
83 DesiredCapabilities seleniumCapabilities = new DesiredCapabilities();
84 seleniumCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
85 seleniumCapabilities.setCapability(CapabilityType.PROXY, ClientUtil.createSeleniumProxy(server));
86 driver = new FirefoxDriver(seleniumCapabilities);
87 server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
88 System.out.println("Port started:" + port1);
92 public void first_test1() throws InterruptedException {
94 server.newHar("asdc.har");
96 driver.get("https://www.e-access.att.com/QA-SCRUM1/sdc1/portal#/dashboard");
97 driver.manage().window().maximize();
99 WebElement userNameTextbox = driver.findElement(By.name("userid"));
100 userNameTextbox.sendKeys("m99121");
101 WebElement passwordTextbox = driver.findElement(By.name("password"));
102 passwordTextbox.sendKeys("66-Percent");
104 WebElement submitButton = driver.findElement(By.name("btnSubmit"));
105 submitButton.click();
107 WebElement buttonOK = driver.findElement(By.name("successOK"));
108 AssertJUnit.assertTrue(buttonOK.isDisplayed());
111 driver.findElement(By.xpath(getXpath("main-menu-button-catalog"))).click();
113 driver.findElement(By.xpath(getXpath("checkbox-service"))).click();
117 public static String getXpath(String dataTestId){
118 return String.format("//*[@data-tests-id='%s']", dataTestId);
122 public void shutdown() {
126 Har har = server.getHar();
127 File harFile = new File("C:\\temp\\asdc.har");
128 har.writeTo(harFile);
130 } catch (IOException ioe) {
131 ioe.printStackTrace();