仕事でSelenium IDEを使ってテストケースを書いていたりするのですが、
ケースを作るにあたって、javascriptでbaseUrlの値を参照したくなりました。
どこにあるんだろうと思って2~3ページ検索しましたが見当たらず。

なので、echoコマンドでseleniumオブジェクトの中身を出力して探してみました。

コマンドは以下の通り。(説明の為に改行しています)

<td>echo</td>
<td>
javascript{
    (function(o){
        var s='';
        for(var i in o){
            s = s + ' ' + i + '[' + (typeof o[i]) + ']';
        }
        return s;
    })(selenium);
}
</td>
<td></td>

実行すると、

[info] echo: browserbot[object] optionLocatorFactory[object] page[function] defaultTimeout[string] mouseSpeed[number] reset[function] doClick[function] doDoubleClick[function] doContextMenu[function] doClickAt[function] doDoubleClickAt[function] doContextMenuAt[function] doFireEvent[function] doFocus[function] doKeyPress[function] doShiftKeyDown[function] doShiftKeyUp[function] doMetaKeyDown[function] doMetaKeyUp[function] doAltKeyDown[function] doAltKeyUp[function] doControlKeyDown[function] doControlKeyUp[function] doKeyDown[function] doKeyUp[function] doMouseOver[function] doMouseOut[function] doMouseDown[function] doMouseDownRight[function] doMouseDownAt[function] doMouseDownRightAt[function] doMouseUp[function] doMouseUpRight[function] doMouseUpAt[function] doMouseUpRightAt[function] doMouseMove[function] doMouseMoveAt[function] doType[function] doTypeKeys[function] doSetSpeed[function] getSpeed[function] findToggleButton[function] doCheck[function] doUncheck[function] doSelect[function] doAddSelection[function] doRemoveSelection[function] doRemoveAllSelections[function] doSubmit[function] makePageLoadCondition[function] doOpen[function] doOpenWindow[function] doSelectWindow[function] doSelectPopUp[function] doDeselectPopUp[function] doSelectFrame[function] getWhetherThisFrameMatchFrameExpression[function] getWhetherThisWindowMatchWindowExpression[function] doWaitForPopUp[function] doChooseCancelOnNextConfirmation[function] doChooseOkOnNextConfirmation[function] doAnswerOnNextPrompt[function] doGoBack[function] doRefresh[function] doClose[function] ensureNoUnhandledPopups[function] isAlertPresent[function] isPromptPresent[function] isConfirmationPresent[function] getAlert[function] getConfirmation[function] getPrompt[function] getLocation[function] getTitle[function] getBodyText[function] getValue[function] getText[function] doHighlight[function] getEval[function] isChecked[function] getTable[function] getSelectedLabels[function] getSelectedLabel[function] getSelectedValues[function] getSelectedValue[function] getSelectedIndexes[function] getSelectedIndex[function] getSelectedIds[function] getSelectedId[function] isSomethingSelected[function] findSelectedOptionProperties[function] findSelectedOptionProperty[function] getSelectOptions[function] getAttribute[function] isTextPresent[function] isElementPresent[function] isVisible[function] findEffectiveStyleProperty[function] _isDisplayed[function] findEffectiveStyle[function] isEditable[function] getAllButtons[function] getAllLinks[function] getAllFields[function] getAttributeFromAllWindows[function] findWindow[function] doDragdrop[function] doSetMouseSpeed[function] getMouseSpeed[function] doDragAndDrop[function] doDragAndDropToObject[function] doWindowFocus[function] doWindowMaximize[function] getAllWindowIds[function] getAllWindowNames[function] getAllWindowTitles[function] getHtmlSource[function] doSetCursorPosition[function] getElementIndex[function] isOrdered[function] _isCommentOrEmptyTextNode[function] getElementPositionLeft[function] getElementPositionTop[function] getElementWidth[function] getElementHeight[function] getCursorPosition[function] getExpression[function] getXpathCount[function] getCssCount[function] doAssignId[function] doAllowNativeXpath[function] doIgnoreAttributesWithoutValue[function] doWaitForCondition[function] doSetTimeout[function] doWaitForPageToLoad[function] doWaitForFrameToLoad[function] _isNewPageLoaded[function] _abortXhrRequest[function] preprocessParameter[function] replaceVariables[function] getCookie[function] getCookieByName[function] isCookiePresent[function] doCreateCookie[function] doDeleteCookie[function] doDeleteAllVisibleCookies[function] doSetBrowserLogLevel[function] doRunScript[function] doAddLocationStrategy[function] doCaptureEntirePageScreenshot[function] doRollup[function] doAddScript[function] doRemoveScript[function] doUseXpathLibrary[function] doSendKeys[function] doPause[function] doBreak[function] doStore[function] XXXdoModalDialogTest[function] doEcho[function] _doSetSpeed[function] _getSpeed[function] assertSelected[function] assertFailureOnNext[function] assertErrorOnNext[function] doStoreText[function] doStoreAttribute[function]

こんな感じで中身が表示されました。

でも、baseUrlっぽいのは見当たりません。

先ほどの無名関数の引数を selenium から selenium.page() に変更し、再度実行。

[info] echo: topWindow[object] topFrame[object] _baseUrl[string] buttonWindow[object] currentWindow[object] currentWindowName[object] allowNativeXpath[boolean] xpathEvaluator[object] isSubFrameSelected[boolean] altKeyDown[boolean] controlKeyDown[boolean] shiftKeyDown[boolean] metaKeyDown[boolean] modalDialogTest[object] recordedAlerts[object] recordedConfirmations[object] recordedPrompts[object] openedWindows[object] nextConfirmResult[boolean] nextPromptResult[string] newPageLoaded[boolean] pageLoadError[object] ignoreResponseCode[boolean] xhr[object] abortXhr[boolean] isXhrSent[boolean] isXhrDone[boolean] xhrOpenLocation[object] xhrResponseCode[object] xhrStatusText[object] shouldHighlightLocatedElement[boolean] uniqueId[string] pollingForLoad[object] permDeniedCount[object] windowPollers[object] browserbot[object] locationStrategies[object] findElementBy[function] recordPageLoad[function] isNewPageLoaded[function] setAllowNativeXPath[function] setIgnoreAttributesWithoutValue[function] setXPathEngine[function] getXPathEngine[function] proxyInjectionMode[undefined] doModalDialogTest[function] cancelNextConfirmation[function] setNextPromptResult[function] hasAlerts[function] relayBotToRC[function] relayToRC[function] resetPopups[function] getNextAlert[function] hasConfirmations[function] getNextConfirmation[function] hasPrompts[function] getNextPrompt[function] triggerMouseEvent[function] _windowClosed[function] _modifyWindow[function] selectWindow[function] selectPopUp[function] _selectTopWindow[function] _selectWindowByWindowId[function] _selectWindowByName[function] _selectWindowByTitle[function] _selectFirstNonTopWindow[function] selectFrame[function] doesThisFrameMatchFrameExpression[function] abortXhrRequest[function] onXhrStateChange[function] checkedOpen[function] openLocation[function] openWindow[function] setIFrameLocation[function] setOpenLocation[function] getCurrentPage[function] windowNeedsModifying[function] modifyWindowToRecordPopUpDialogs[function] modifySeparateTestWindowToDetectPageLoads[function] _isHTASubFrame[function] _getFrameElement[function] _getFrameElementByName[function] pollForLoad[function] _isSamePage[function] _isSameDocument[function] getReadyState[function] XXXreschedulePoller[function] reschedulePoller[function] runScheduledPollers[function] isPollingForLoad[function] getWindowByName[function] getWindowNameByTitle[function] getNonTopWindowNames[function] getCurrentWindow[function] getUserWindow[function] _handleClosedSubFrame[function] highlight[function] setShouldHighlightElement[function] _registerAllLocatorFunctions[function] getDocument[function] getTitle[function] getCookieByName[function] getAllCookieNames[function] getAllRawCookieNames[function] deleteCookie[function] _maybeDeleteCookie[function] _recursivelyDeleteCookieDomains[function] _recursivelyDeleteCookie[function] recursivelyDeleteCookie[function] findElementRecursive[function] findElementOrNull[function] findElement[function] findElementsLikeWebDriver[function] locateElementByIdentifier[function] locateElementById[function] locateElementByName[function] locateElementByDomTraversal[function] locateElementByStoredReference[function] locateElementByWebDriver[function] locateElementByXPath[function] locateElementsByXPath[function] _namespaceResolver[function] evaluateXPathCount[function] evaluateCssCount[function] locateElementByLinkText[function] findAttribute[function] selectOption[function] addSelection[function] removeSelection[function] checkMultiselect[function] replaceText[function] submit[function] clickElement[function] doubleClickElement[function] contextMenuOnElement[function] _modifyElementTarget[function] _handleClickingImagesInsideLinks[function] _getTargetWindow[function] _getFrameFromGlobal[function] bodyText[function] getAllButtons[function] getAllFields[function] getAllLinks[function] goBack[function] goForward[function] close[function] refresh[function] selectElementsBy[function] selectElements[function] locateElementByClass[function] locateElementByAlt[function] locateElementByCss[function] locateElementByUIElement[function] _fireEventOnElement[function] baseUrl[string]

というわけで、無事 baseUrl を見つけることができました!

baseUrlを参照するときは、

selenium.page().baseUrl

で良いわけですね。

まあ、こんな回りくどい方法しないでもリファレンスがどっかにあるんでしょうけどね。

参考:

Javascript: オブジェクトの属性を全部表示する