4

Ubuntu11.10で実行されているFirefox11でSelenium1.7.2を使用しています。昨日まで、document.domainJavaScriptを使用していませんでした。生成されたHTMLとjavascriptファイルの1つに追加する必要がありました。Selenium IDE Test Suiteを実行すると、次のエラーが発生します。

Error: Permission denied for <http://dev.example.com> to get property Location.href

dev.example.com私たちのアプリケーションサーバーです(Apache +mod_jkの背後にあるGlassfish3.1.2)

コメントアウトすると、document.domainすべてがうまく機能します(少なくともFirefoxでは、document.domainはIEがPIE.htcスクリプトをブロックするのを防ぐためです...ため息

ここにあるユーザー拡張スクリプトを追加してみまし

function setdom(str,doc,dom) {
  doc.domain = dom;
}

Selenium.prototype.doDocumentDomain = function(domain) {
  var lw;
  setdom('ts',frames['testSuiteFrame'].document, domain);
  setdom('tf', getTestFrame().contentWindow.document, domain);
  setdom('my', frames['myiframe'].document, domain);

  lw = LOG.getLogWindow();
  if (lw) {
    setdom('log', lw.document, domain);
    }
  setdom('doc', document, domain);
  }

しかし、これはかなり古く見え、おそらくもう互換性がありません。setdom('ts',frames['testSuiteFrame'].document,domain);回線への最初の呼び出しでエラーを返します

私はHTTPとHTTPSの間を行ったり来たりしていません。私は、StackOverflowとGoogleグループに関連する多くの質問を読みましたが、結果はありません。

document.domainIEのみを含めるようにコードを変更できますが、あまりクリーンではありません...

質問:document.domainが設定されている場合、セキュリティの問題なしにSelenium IDEを機能させるにはどうすればよいですか?または、Selenium IDE 1.7.2で動作するように、上記のユーザー拡張機能を修正するにはどうすればよいですか?ありがとうございました。

4

1 に答える 1

0

そこで、Selenium javascriptを変更して、これを使用してdocument.domainを設定できるようにすることにしました。

920行目の`chrome/ content / selenium-core / scripts / selenium-browserbot.js(バージョン1.7.2の場合):

    //Samit: Fix: open command sometimes fails if current url is chrome and new is not
    windowObject = core.firefox.unwrap(windowObject);
    // -------------- Start My Change ----------------
    updateDomain(windowObject.document);
    // -------------- End My Change ----------------
    if (this._windowClosed(windowObject)) {
        LOG.debug("pollForLoad WINDOW CLOSED (" + marker + ")");
        delete this.pollingForLoad[marker];
        return;
    }

次に、user-extensions.jsで:

var validDomain = null;

Selenium.prototype.doDocumentDomain = function(domain) {
  validDomain = domain;
}

function updateDomain(doc) {
  if(validDomain==null) {
    return;
    }
  LOG.info("Current domain: " + doc.domain);
  if(doc.domain != validDomain && (doc.domain+"").indexOf(validDomain)>0 ) {
    doc.domain = validDomain;
    }
  LOG.info("New domain: " + doc.domain);
  }

新しいドメインを設定する前に、設定したいドメインのサブドメインであることを確認します。私はSeleniumIDEでそれを使用します:

documentDomain | example.com

したがって、dev.example.comとstatic.example.comを開くと、ドメイン内で検索example.comされ、ドメインが置き換えられます。

于 2012-04-05T05:28:00.540 に答える