Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 195e824

Browse files
committed
Improving KillIE task, clear all history and cookies, cache etc, and also run the command after each IE build
1 parent f2f60a5 commit 195e824

File tree

3 files changed

+153
-54
lines changed

3 files changed

+153
-54
lines changed

SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/grid/proxies/SetupTeardownProxy.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
package com.groupon.seleniumgridextras.grid.proxies;
4040

4141
import com.google.common.base.Throwables;
42+
import com.groupon.seleniumgridextras.config.capabilities.BrowserType;
4243
import com.groupon.seleniumgridextras.grid.proxies.sessions.threads.NodeRestartCallable;
4344
import com.groupon.seleniumgridextras.tasks.config.TaskDescriptions;
45+
import com.groupon.seleniumgridextras.utilities.JsonWireCommandTranslator;
4446
import com.groupon.seleniumgridextras.utilities.json.JsonCodec;
47+
import com.groupon.seleniumgridextras.utilities.threads.CommonThreadPool;
4548
import com.groupon.seleniumgridextras.utilities.threads.RemoteGridExtrasAsyncCallable;
4649
import com.groupon.seleniumgridextras.utilities.threads.SessionHistoryCallable;
47-
import com.groupon.seleniumgridextras.utilities.JsonWireCommandTranslator;
48-
49-
import com.groupon.seleniumgridextras.utilities.threads.CommonThreadPool;
5050
import com.groupon.seleniumgridextras.utilities.threads.video.RemoteVideoRecordingControlCallable;
5151
import com.groupon.seleniumgridextras.utilities.threads.video.VideoDownloaderCallable;
5252
import org.apache.log4j.Logger;
@@ -56,17 +56,17 @@
5656
import org.openqa.grid.internal.TestSession;
5757
import org.openqa.grid.internal.listeners.TestSessionListener;
5858
import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;
59+
import org.openqa.selenium.remote.CapabilityType;
5960

61+
import javax.servlet.http.HttpServletRequest;
62+
import javax.servlet.http.HttpServletResponse;
6063
import java.util.HashMap;
6164
import java.util.LinkedList;
6265
import java.util.List;
6366
import java.util.Map;
6467
import java.util.concurrent.ExecutionException;
6568
import java.util.concurrent.Future;
6669

67-
import javax.servlet.http.HttpServletRequest;
68-
import javax.servlet.http.HttpServletResponse;
69-
7070

7171
public class SetupTeardownProxy extends DefaultRemoteProxy implements TestSessionListener {
7272

@@ -138,6 +138,22 @@ public void beforeCommand(TestSession session, HttpServletRequest request,
138138
public void afterSession(TestSession session) {
139139
super.afterSession(session);
140140

141+
Map<String, Object> cap = session.getRequestedCapabilities();
142+
String browser = (String) cap.get(CapabilityType.BROWSER_NAME);
143+
144+
if (browser.equals(BrowserType.IE) ||
145+
browser.equals(BrowserType.IEXPLORE) ||
146+
browser.equals(BrowserType.IE_HTA) ||
147+
browser.equals(BrowserType.IEXPLORE_PROXY)) {
148+
CommonThreadPool.startCallable(
149+
new RemoteGridExtrasAsyncCallable(
150+
this.getRemoteHost().getHost(),
151+
3000,
152+
TaskDescriptions.Endpoints.KILL_IE,
153+
new HashMap<String, String>()));
154+
}
155+
156+
141157
// Stop and download video only if the external session has been established
142158
if (session.getExternalKey() != null) {
143159
stopVideoRecording(session);
@@ -160,7 +176,6 @@ public void afterSession(TestSession session) {
160176
new NodeRestartCallable(
161177
this,
162178
session));
163-
164179
}
165180

166181
private boolean alreadyRecordingCurrentSession(TestSession session) {

SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/KillAllIE.java

Lines changed: 99 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,108 @@
3838
package com.groupon.seleniumgridextras.tasks;
3939

4040

41+
import com.google.common.base.Throwables;
4142
import com.google.gson.JsonObject;
42-
43+
import com.groupon.seleniumgridextras.ExecuteCommand;
44+
import com.groupon.seleniumgridextras.config.RuntimeConfig;
4345
import com.groupon.seleniumgridextras.tasks.config.TaskDescriptions;
46+
import com.groupon.seleniumgridextras.utilities.json.JsonCodec;
47+
import com.groupon.seleniumgridextras.utilities.json.JsonParserWrapper;
48+
import org.apache.log4j.Logger;
49+
50+
import java.util.HashMap;
51+
import java.util.Map;
4452

4553
public class KillAllIE extends KillAllByName {
4654

47-
public KillAllIE() {
48-
setEndpoint(TaskDescriptions.Endpoints.KILL_IE);
49-
setDescription(TaskDescriptions.Description.KILL_IE);
50-
JsonObject params = new JsonObject();
51-
setAcceptedParams(params);
52-
setRequestType("GET");
53-
setResponseType("json");
54-
setClassname(this.getClass().getCanonicalName().toString());
55-
setCssClass(TaskDescriptions.UI.BTN_DANGER);
56-
setButtonText(TaskDescriptions.UI.ButtonText.KILL_IE);
57-
setEnabledInGui(true);
58-
}
59-
60-
61-
@Override
62-
public String getWindowsCommand() {
63-
return super.getWindowsCommand("iexplore.exe");
64-
}
65-
66-
@Override
67-
public String getLinuxCommand() {
68-
return super.getLinuxCommand("iexplore.exe");
69-
}
70-
71-
@Override
72-
public String getMacCommand() {
73-
return super.getMacCommand("iexplore.exe");
74-
}
55+
public static final String CLEAR_HISTORY_RESPONSE = "clear_history_response";
56+
public static final String KILL_IE_RESPONSE = "kill_ie_response";
57+
public static final String KILL_DRIVER_RESPONSE = "kill_driver_response";
58+
59+
private static Logger logger = Logger.getLogger(KillAllIE.class);
60+
61+
public KillAllIE() {
62+
setEndpoint(TaskDescriptions.Endpoints.KILL_IE);
63+
setDescription(TaskDescriptions.Description.KILL_IE);
64+
JsonObject params = new JsonObject();
65+
setAcceptedParams(params);
66+
setRequestType("GET");
67+
setResponseType("json");
68+
setClassname(this.getClass().getCanonicalName().toString());
69+
setCssClass(TaskDescriptions.UI.BTN_DANGER);
70+
setButtonText(TaskDescriptions.UI.ButtonText.KILL_IE);
71+
setEnabledInGui(true);
72+
}
73+
74+
75+
@Override
76+
public JsonObject execute(String parameter) {
77+
return execute();
78+
}
79+
80+
@Override
81+
public JsonObject execute(Map<String, String> parameter) {
82+
return execute();
83+
}
84+
85+
public JsonObject execute() {
86+
87+
if (!RuntimeConfig.getOS().isWindows()) {
88+
getJsonResponse().addKeyValues(JsonCodec.ERROR, "This command can only be executed on Windows");
89+
return getJsonResponse().getJson();
90+
}
91+
92+
93+
Map<String, String> responsesList = new HashMap<String, String>();
94+
try {
95+
logger.info(String.format("Killing all IE Driver instances with command %s", getKillDriverCommand()));
96+
JsonObject killDriverResponse = ExecuteCommand.execRuntime(getKillDriverCommand(), true);
97+
logger.debug(killDriverResponse);
98+
responsesList.put(KILL_DRIVER_RESPONSE, JsonParserWrapper.prettyPrintString(killDriverResponse));
99+
100+
logger.info(String.format("Killing all IE instances with command %s", getKillIECommand()));
101+
JsonObject killIEResponse = ExecuteCommand.execRuntime(getKillIECommand(), true);
102+
logger.debug(killIEResponse);
103+
responsesList.put(KILL_IE_RESPONSE, JsonParserWrapper.prettyPrintString(killIEResponse));
104+
105+
logger.info(String.format("Clearing all browser data with command %s", getClearHistoryCommand()));
106+
JsonObject clearHistoryResponse = ExecuteCommand.execRuntime(getClearHistoryCommand(), true);
107+
logger.debug(clearHistoryResponse);
108+
responsesList.put(CLEAR_HISTORY_RESPONSE, JsonParserWrapper.prettyPrintString(clearHistoryResponse));
109+
} catch (Exception e) {
110+
getJsonResponse().addKeyValues(JsonCodec.ERROR, Throwables.getStackTraceAsString(e));
111+
}
112+
113+
getJsonResponse().addKeyValues(JsonCodec.OUT, responsesList);
114+
return getJsonResponse().getJson();
115+
}
116+
117+
public String getKillDriverCommand() {
118+
return "taskkill -F -T -IM iedriver*";
119+
}
120+
121+
public String getKillIECommand() {
122+
return "taskkill -F -T -IM iexplore*";
123+
}
124+
125+
public String getClearHistoryCommand() {
126+
return "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351";
127+
}
128+
129+
@Override
130+
public boolean initialize() {
131+
try {
132+
if (RuntimeConfig.getOS().isWindows()) {
133+
execute();
134+
}
135+
} catch (Exception error) {
136+
printInitilizedFailure();
137+
logger.error(error);
138+
return false;
139+
}
140+
141+
printInitilizedSuccessAndRegisterWithAPI();
142+
return true;
143+
144+
}
75145
}

SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/KillAllIETest.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,49 @@
3838
package com.groupon.seleniumgridextras;
3939

4040

41-
import com.groupon.seleniumgridextras.tasks.ExecuteOSTask;
4241
import com.groupon.seleniumgridextras.tasks.KillAllIE;
43-
4442
import org.junit.Before;
4543
import org.junit.Test;
4644

4745
import static org.junit.Assert.assertEquals;
4846

4947
public class KillAllIETest {
5048

51-
private ExecuteOSTask task;
52-
private String windowsCommand;
49+
private KillAllIE task;
50+
private String expectedIEDriverCommand = "taskkill -F -T -IM iedriver*";
51+
private String expectedIECommand = "taskkill -F -T -IM iexplore*";
52+
private String expectedHistoryCommand = "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351";
53+
54+
@Before
55+
public void setUp() throws Exception {
56+
task = new KillAllIE();
57+
}
58+
59+
@Test
60+
public void testGetDescription() throws Exception {
61+
62+
assertEquals("Executes os level kill command on all instance of Internet Explorer",
63+
task.getDescription());
64+
}
5365

54-
@Before
55-
public void setUp() throws Exception {
56-
task = new KillAllIE();
57-
windowsCommand = "taskkill -F -IM iexplore.exe";
58-
}
66+
@Test
67+
public void testGetEndpoint() throws Exception {
68+
assertEquals("/kill_ie", task.getEndpoint());
69+
}
5970

60-
@Test
61-
public void testGetDescription() throws Exception {
71+
@Test
72+
public void testGetKillDriverCommand() throws Exception {
73+
assertEquals(expectedIEDriverCommand, task.getKillDriverCommand());
74+
}
6275

63-
assertEquals("Executes os level kill command on all instance of Internet Explorer",
64-
task.getDescription());
65-
}
76+
@Test
77+
public void testGetKillIECommand() throws Exception{
78+
assertEquals(expectedIECommand, task.getKillIECommand());
79+
}
6680

67-
@Test
68-
public void testGetEndpoint() throws Exception {
69-
assertEquals("/kill_ie", task.getEndpoint());
70-
}
81+
@Test
82+
public void testGetClearHistoryCommand() throws Exception{
83+
assertEquals(expectedHistoryCommand, task.getClearHistoryCommand());
84+
}
7185

7286
}

0 commit comments

Comments
 (0)