2016年7月1日金曜日

Protractorでセッションをクリアできないときの対策

以下のスクリプトでセッションをクリアしてみたら、
browser.executeScript('localStorage.clear();');
 思うようにクリアしてくれない、

 理由はpageちゃっとロード完了できていなかったみたい

以下のソースを使えばその問題を解消できます。



  function getWindowLocation() {
    return window.location;
  }

  function clearStorage() {
    window.sessionStorage.clear();
    window.localStorage.clear();
  }

  return browser.executeScript(getWindowLocation).then(function(location) {
    // NB If no page is loaded in the scneario then calling clearStorage will cause exception
    // so guard against this by checking hostname (If no page loaded then hostname == '')
    if (location.hostname.length > 0) {
      return browser.executeScript(clearStorage);
    }
    else {
      return Promise.resolve();
    }
  });

2016年5月27日金曜日

Postgresqlでselect結果をファイルに出力する方法

Postgresqlでselect結果をファイルに出力する方法は三つがあります。

方法1、psqlコマンドを使う
    psql -d dbname -t -A -F"," -c "select * from users" > output.csv
方法2、postgresのcopyコマンドを使う
    COPY (SELECT * from users) To '/tmp/output.csv' With CSV;
方法3、psql対話的なコマンドで出力する
  >psql dbname
    psql>\f ','
    psql>\a
    psql>\o '/tmp/output.csv'
    psql>SELECT * from users;
       psql>\q    

2016年5月19日木曜日

Intellijでこんなエラーになりました。Could not autowire. No beans of TestMessagingTemplate type found

新しく定義した「@Component」を使用しようとしたら、Intellijでこんなエラーになりました。

Could not autowire. No beans of TestMessagingTemplate type found


調べたところ、新しく定義したコンポーネントがスキャンできてないが原因でした。

applicationContext.xmlファイルに、component-scanのパケージ場所を追加してあげれば問題を解決できます。
例:

<context:component-scan base-package="com.test.com.framework"/>