Skip to content

Commit

Permalink
Bringing MarionetteConnection in line with the current marionette sta…
Browse files Browse the repository at this point in the history
…te (FF33)
  • Loading branch information
barancev committed Oct 19, 2014
1 parent d0c863a commit a009c52
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.openqa.selenium.firefox.ExtensionConnection;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.NotConnectedException;
import org.openqa.selenium.internal.Lock;
import org.openqa.selenium.logging.LocalLogs;
import org.openqa.selenium.logging.NeedsLocalLogs;
Expand All @@ -47,8 +46,6 @@
import java.io.Reader;
import java.net.ConnectException;
import java.net.Socket;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand All @@ -64,7 +61,7 @@ public class MarionetteConnection implements ExtensionConnection, NeedsLocalLogs
private File profileDir;

private static Map<String, String> seleniumToMarionetteCommandMap = ImmutableMap.<String, String>builder()
.put(DriverCommand.GET, "goUrl")
.put(DriverCommand.GET, "get")
.put(DriverCommand.GET_CURRENT_WINDOW_HANDLE, "getWindow")
.put(DriverCommand.GET_WINDOW_HANDLES, "getWindows")
.put(DriverCommand.CLOSE, "closeWindow")
Expand Down Expand Up @@ -162,6 +159,7 @@ public void start() throws IOException {
// This initializes the "actor" for future communication with this instance.
sendCommand(serializeCommand(new Command(null, "getMarionetteID")));
String getMarionetteIdRawResponse = receiveResponse();
System.out.println(getMarionetteIdRawResponse);
Map<String, Object> map = new JsonToBeanConverter().convert(Map.class,
getMarionetteIdRawResponse);
marionetteId = map.get("id").toString();
Expand Down Expand Up @@ -191,14 +189,8 @@ public Response execute(Command command) throws IOException {
Map<String, Object> map = new JsonToBeanConverter().convert(Map.class, rawResponse);
Response response;
if (DriverCommand.NEW_SESSION.equals(command.getName())) {
// If we're starting a new session, we need to return the response
// with that session.
// ***************************************************************
// Marionette Compliance Issue: The response should return the
// newly created session ID in the "sessionId" member of the
// returned JSON object.
// ***************************************************************
response = new Response(new SessionId(map.get("value").toString()));
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1073732
response = new Response(new SessionId(new BeanToJsonConverter().convert(map.get("value"))));
response.setValue(Maps.newHashMap());

} else {
Expand All @@ -217,17 +209,27 @@ public Response execute(Command command) throws IOException {
// }
// ***************************************************************
response = new Response();
Map<String, Object> errorMap = (Map<String, Object>) map.get("error");
if (errorMap != null) {
response.setStatus(Integer.parseInt(errorMap.get("status").toString()));
errorMap.remove("status");
response.setValue(errorMap);
Object value = map.get("error");
if (value != null) {
if (value instanceof Map) {
Map<String, Object> errorMap = (Map<String, Object>) value;
if (errorMap != null) {
response.setStatus(Integer.parseInt(errorMap.get("status").toString()));
errorMap.remove("status");
response.setValue(errorMap);
}
} else {
response.setStatus(ErrorCodes.UNHANDLED_ERROR);
response.setValue(value + ": " + map.get("message"));
}
}

} else {
response = new JsonToBeanConverter().convert(Response.class, rawResponse);

// ***************************************************************
// Marionette Compliance Issue: Responses from findElement and
// findElements are returned with raw element IDs as the value.
// Marionette Compliance Issue: Responses from findElements
// are returned with raw element IDs as the value.
// This should be a JSON object with the following structure:
//
// { "ELEMENT": "<element ID goes here>" }
Expand All @@ -236,11 +238,7 @@ public Response execute(Command command) throws IOException {
// a raw string and an element reference returned from the
// executeScript command.
// ***************************************************************
response = new JsonToBeanConverter().convert(Response.class, rawResponse);

if (DriverCommand.FIND_ELEMENT.equals(command.getName())
|| DriverCommand.FIND_CHILD_ELEMENT.equals(command.getName())
|| DriverCommand.GET_ACTIVE_ELEMENT.equals(command.getName()))
if (DriverCommand.GET_ACTIVE_ELEMENT.equals(command.getName()))
{
if (response.getStatus() == ErrorCodes.SUCCESS) {
Map<String, Object> wrappedElement = Maps.newHashMap();
Expand Down Expand Up @@ -278,51 +276,17 @@ private String serializeCommand(Command command) {
if (DriverCommand.NEW_SESSION.equals(commandName)) {
params.remove("desiredCapabilities");

} else if (DriverCommand.GET.equals(commandName)) {
renameParameter(params, "url", "value");

} else if (DriverCommand.SET_TIMEOUT.equals(commandName)) {
String timeoutType = (String) params.get("type");
// System.out.println("timeout type = " + timeoutType);
if ("implicit".equals(timeoutType)) {
commandName = "setSearchTimeout";
} else if ("script".equals(timeoutType)) {
commandName = "setScriptTimeout";
}
params.remove("type");
renameParameter(params, "ms", "value");

} else if (DriverCommand.EXECUTE_SCRIPT.equals(commandName)
|| DriverCommand.EXECUTE_ASYNC_SCRIPT.equals(commandName)) {
renameParameter(params, "script", "value");

} else if (DriverCommand.SWITCH_TO_WINDOW.equals(commandName)) {
renameParameter(params, "name", "value");

} else if (DriverCommand.SWITCH_TO_FRAME.equals(commandName)) {
Object target = params.get("id");
if (target instanceof Map) {
String elementId = (String) ((Map<String,Object>) target).get("ELEMENT");
params.put("element", elementId);
params.remove("id");

} else {
renameParameter(params, "id", "value");
}

} else if (DriverCommand.FIND_CHILD_ELEMENT.equals(commandName)
|| DriverCommand.FIND_CHILD_ELEMENTS.equals(commandName)
|| DriverCommand.CLICK_ELEMENT.equals(commandName)
|| DriverCommand.CLEAR_ELEMENT.equals(commandName)
|| DriverCommand.GET_ELEMENT_ATTRIBUTE.equals(commandName)
|| DriverCommand.GET_ELEMENT_TEXT.equals(commandName)
|| DriverCommand.SEND_KEYS_TO_ELEMENT.equals(commandName)
|| DriverCommand.IS_ELEMENT_SELECTED.equals(commandName)
|| DriverCommand.IS_ELEMENT_ENABLED.equals(commandName)
|| DriverCommand.IS_ELEMENT_DISPLAYED.equals(commandName)
|| DriverCommand.GET_ELEMENT_SIZE.equals(commandName)
|| DriverCommand.GET_ELEMENT_LOCATION.equals(commandName)
|| DriverCommand.GET_ELEMENT_TAG_NAME.equals(commandName)) {
|| DriverCommand.FIND_CHILD_ELEMENTS.equals(commandName)) {
renameParameter(params, "id", "element");

} else if (DriverCommand.CLICK.equals(commandName)
Expand All @@ -349,11 +313,12 @@ private String serializeCommand(Command command) {

Map<String, Object> map = Maps.newHashMap();
map.put("to", marionetteId != null ? marionetteId : "root");
map.put("type", commandName);
map.put("name", commandName);
if (command.getSessionId() != null) {
map.put("session", command.getSessionId().toString());
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1073732
map.put("sessionId", new JsonToBeanConverter().convert(Map.class, command.getSessionId().toString()));
}
map.putAll(params);
map.put("parameters", params);

return new BeanToJsonConverter().convert(map);
}
Expand All @@ -365,8 +330,8 @@ private void renameParameter(Map<String, Object> params, String origParName, Str
}

private void sendCommand(String commandAsString) {
String line = "" + commandAsString.length() + ":" + commandAsString + " ";
// System.out.println(line);
String line = "" + commandAsString.length() + ":" + commandAsString;
System.out.println(line);
writer.write(line);
writer.flush();
}
Expand All @@ -383,7 +348,7 @@ private String receiveResponse() throws IOException {
response.append(buf, 0, len);
}

// System.out.println("<- |" + response.toString() + "|");
System.out.println("<- |" + response.toString() + "|");

String[] parts = response.toString().split(":", 2);
int length = Integer.parseInt(parts[0]);
Expand Down
3 changes: 3 additions & 0 deletions java/client/test/org/openqa/selenium/AtomsInjectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
package org.openqa.selenium;

import org.junit.Test;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.JavascriptEnabled;

import static org.junit.Assert.assertEquals;
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;

public class AtomsInjectionTest extends JUnit4TestBase {

/** http://code.google.com/p/selenium/issues/detail?id=1333 */
@JavascriptEnabled
@Test
@Ignore({MARIONETTE})
public void testInjectingAtomShouldNotTrampleOnUnderscoreGlobal() {
driver.get(pages.underscorePage);
driver.findElement(By.tagName("body"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testShouldBeAbleToClickOnAnElementHiddenByDoubleOverflow() {
}

@JavascriptEnabled
@Ignore(value = {IPHONE, SAFARI, MARIONETTE}, reason = "Safari: failed, iPhone: untested")
@Ignore(value = {IPHONE, SAFARI}, reason = "Safari: failed, iPhone: untested")
@Test
public void testShouldBeAbleToClickOnAnElementHiddenByYOverflow() {
driver.get(appServer.whereIs("scrolling_tests/page_with_y_overflow_auto.html"));
Expand Down
7 changes: 3 additions & 4 deletions java/client/test/org/openqa/selenium/ClickTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public void testCanClickOnALinkThatContainsTextWrappedInASpan() {
}

@Test
@Ignore(MARIONETTE)
public void testCanClickOnALinkThatContainsEmbeddedBlockElements() {
driver.findElement(By.id("embeddedBlock")).click();
wait.until(titleIs("XHTML Test Page"));
Expand Down Expand Up @@ -330,8 +331,7 @@ public void testShouldBeAbleToClickOnRTLLanguageLink() {
}

@Test
@Ignore(value = {OPERA, OPERA_MOBILE, ANDROID, IPHONE, MARIONETTE}, reason
= "not tested")
@Ignore(value = {OPERA, OPERA_MOBILE, ANDROID, IPHONE}, reason = "not tested")
public void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooter() {
String url = appServer.whereIs("fixedFooterNoScroll.html");
driver.get(url);
Expand All @@ -343,8 +343,7 @@ public void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooter() {
}

@Test
@Ignore(value = {OPERA, OPERA_MOBILE, ANDROID, IPHONE, MARIONETTE}, reason
= "not tested")
@Ignore(value = {OPERA, OPERA_MOBILE, ANDROID, IPHONE}, reason = "not tested")
public void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooterInQuirksMode() {
String url = appServer.whereIs("fixedFooterNoScrollQuirksMode.html");
driver.get(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public void testShouldFireMouseMoveEventWhenClicking() {

@JavascriptEnabled
@Test
@Ignore(MARIONETTE)
public void testShouldNotThrowIfEventHandlerThrows() {
driver.get(pages.javascriptPage);

Expand Down Expand Up @@ -290,7 +289,7 @@ public void testClearingAnElementShouldCauseTheOnChangeHandlerToFire() {
}

@JavascriptEnabled
@Ignore(value = {IPHONE, ANDROID, MARIONETTE}, reason = "iPhone: sendKeys implementation is incorrect")
@Ignore(value = {IPHONE, ANDROID}, reason = "iPhone: sendKeys implementation is incorrect")
@Test
public void testSendingKeysToAnotherElementShouldCauseTheBlurEventToFire() {
assumeFalse(browserNeedsFocusOnThisOs(driver));
Expand All @@ -304,7 +303,7 @@ public void testSendingKeysToAnotherElementShouldCauseTheBlurEventToFire() {
}

@JavascriptEnabled
@Ignore(value = {IPHONE, ANDROID, MARIONETTE}, reason = "iPhone: sendKeys implementation is incorrect")
@Ignore(value = {IPHONE, ANDROID}, reason = "iPhone: sendKeys implementation is incorrect")
@Test
public void testSendingKeysToAnElementShouldCauseTheFocusEventToFire() {
assumeFalse(browserNeedsFocusOnThisOs(driver));
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/CssValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testGetCssValueShouldReturnStandardizedColour() {
}

@JavascriptEnabled
@Ignore({ANDROID, IPHONE, OPERA, HTMLUNIT, MARIONETTE})
@Ignore({ANDROID, IPHONE, OPERA, HTMLUNIT})
@Test
public void testShouldAllowInheritedStylesToBeUsed() {
driver.get(pages.javascriptPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void testSameElementLookedUpDifferentWaysShouldBeEqual() {
}

@Test
@Ignore(value = MARIONETTE, reason = "Marionette does not recognize the packet type elementEquals")
public void testDifferentElementsShouldNotBeEqual() {
driver.get(pages.simpleTestPage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ public void testShouldBeAbleToGrabTheBodyOfFrameOnceSwitchedTo() {
@SuppressWarnings("unchecked")
@JavascriptEnabled
@Test
@Ignore(MARIONETTE)
public void testShouldBeAbleToReturnAnArrayOfWebElements() {
driver.get(pages.formPage);

Expand Down Expand Up @@ -484,7 +483,6 @@ public void testShouldBeAbleToExecuteABigChunkOfJavascriptCode() throws IOExcept
@SuppressWarnings("unchecked")
@JavascriptEnabled
@Test
@Ignore(MARIONETTE)
public void testShouldBeAbleToExecuteScriptAndReturnElementsList() {
driver.get(pages.formPage);
String scriptToExec = "return document.getElementsByName('snack');";
Expand Down Expand Up @@ -539,7 +537,7 @@ public void testCanHandleAnArrayOfElementsAsAnObjectArray() {
}

@JavascriptEnabled
@Ignore(value = {ANDROID, OPERA, OPERA_MOBILE, MARIONETTE},
@Ignore(value = {ANDROID, OPERA, OPERA_MOBILE},
reason = "Opera obeys the method contract. Android not tested")
@Test
public void testCanPassAMapAsAParameter() {
Expand Down
7 changes: 2 additions & 5 deletions java/client/test/org/openqa/selenium/FormHandlingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,28 @@ public void testShouldBeAbleToClickImageButtons() {
}

@Test
@Ignore(MARIONETTE)
public void testShouldBeAbleToSubmitForms() {
driver.get(pages.formPage);
driver.findElement(By.name("login")).submit();
wait.until(titleIs("We Arrive Here"));
}

@Test
@Ignore(MARIONETTE)
public void testShouldSubmitAFormWhenAnyInputElementWithinThatFormIsSubmitted() {
driver.get(pages.formPage);
driver.findElement(By.id("checky")).submit();
wait.until(titleIs("We Arrive Here"));
}

@Test
@Ignore(MARIONETTE)
public void testShouldSubmitAFormWhenAnyElementWithinThatFormIsSubmitted() {
driver.get(pages.formPage);
driver.findElement(By.xpath("//form/p")).submit();
wait.until(titleIs("We Arrive Here"));
}

@Test(expected = NoSuchElementException.class)
@Ignore(value = {ANDROID, IPHONE, OPERA, PHANTOMJS, SAFARI, OPERA_MOBILE, MARIONETTE})
@Ignore(value = {ANDROID, IPHONE, OPERA, PHANTOMJS, SAFARI, OPERA_MOBILE})
public void testShouldNotBeAbleToSubmitAFormThatDoesNotExist() {
driver.get(pages.formPage);
driver.findElement(By.name("SearchableText")).submit();
Expand Down Expand Up @@ -206,7 +203,7 @@ public void testShouldBeAbleToSendKeysToAFileUploadInputElementInAnXhtmlDocument
assertTrue(uploadPath.endsWith(file.getName()));
}

@Ignore(value = {IPHONE, ANDROID, OPERA, SAFARI, MARIONETTE},
@Ignore(value = {IPHONE, ANDROID, OPERA, SAFARI},
reason = "Does not yet support file uploads", issues = {4220})
@Test
public void testShouldBeAbleToUploadTheSameFileTwice() throws IOException {
Expand Down
2 changes: 0 additions & 2 deletions java/client/test/org/openqa/selenium/FrameSwitchingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void tearDown() throws Exception {
//
// ----------------------------------------------------------------------------------------------
@Test
@Ignore(MARIONETTE)
public void testShouldAlwaysFocusOnTheTopMostFrameAfterANavigationEvent() {
driver.get(pages.framesetPage);
driver.findElement(By.tagName("frameset")); // Test passes if this does not throw.
Expand Down Expand Up @@ -101,7 +100,6 @@ public void testShouldOpenPageWithBrokenFrameset() {
//
// ----------------------------------------------------------------------------------------------
@Test
@Ignore(MARIONETTE)
public void testShouldBeAbleToSwitchToAFrameByItsIndex() {
driver.get(pages.framesetPage);
driver.switchTo().frame(1);
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/MiscTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testShouldReturnTheSourceOfAPage() {
}

@JavascriptEnabled
@Ignore(value = {ANDROID, CHROME, IE, SAFARI, OPERA, OPERA_MOBILE, MARIONETTE},
@Ignore(value = {ANDROID, CHROME, IE, SAFARI, OPERA, OPERA_MOBILE},
reason = "Chrome, Safari: returns XML content formatted for display as HTML document"
+ "Opera: includes XML doctype"
+ "Others: untested")
Expand Down
4 changes: 2 additions & 2 deletions java/client/test/org/openqa/selenium/PageLoadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void testShouldDoNothingIfThereIsNothingToGoBackTo() {
assertThat(driver.getTitle(), equalTo(originalTitle));
}

@Ignore(value = {ANDROID, SAFARI, MARIONETTE}, issues = {3771})
@Ignore(value = {ANDROID, SAFARI}, issues = {3771})
@Test
public void testShouldBeAbleToNavigateBackInTheBrowserHistory() {
driver.get(pages.formPage);
Expand All @@ -298,7 +298,7 @@ public void testShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes
wait.until(titleIs("XHTML Test Page"));
}

@Ignore(value = {ANDROID, SAFARI, MARIONETTE}, issues = {3771})
@Ignore(value = {ANDROID, SAFARI}, issues = {3771})
@Test
public void testShouldBeAbleToNavigateForwardsInTheBrowserHistory() {
driver.get(pages.formPage);
Expand Down
Loading

0 comments on commit a009c52

Please sign in to comment.