0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[T-DASH] chrome profileを用いてgoogleログインした状態にしてテスト開始する

Last updated at Posted at 2025-03-13

Outline

image.png

seleniumでgoogleのログインさせたいとき、単純にはいかない。
上記のように、ログインすらさせてくれない。

T-DASHでgoogleのログイン状態から、なんらかの処理を行いたい場合、どうしたらいいか?

技術的情報

chromeを起動するときに、User Profileを指定して起動させると、そのprofileの状態からchromeを起動できる

普通にchromeを立ち上げたとき、profileはこのような状態になる。
これは、seleniumでchromeを起動都度ゼロの状態からprofileを作る。
profileは一時ファイルであり、終了すれば削除される。
そのため、このprofileで処理・設定した内容は、次回起動時には引き継がれない。

image.png

chromeの起動オプションで、すでに存在するprofileを使って起動させることもできる

–user-data-dir を指定
–profile-directory を指定

Option Mean Example
–user-data-dir ユーザープロファイルの保存先 C:\Users\LOGINUSERNAME\AppData\Local\Google\Chrome\User Data\
–profile-directory 使用するユーザープロファイル Profile 1

profileのuder data dirとprofile directoryは chromeで確認することができる

chrome起動後、URLに以下を入力

chrome://version

image.png

プロフィール パス = user data dir + profile directory になっている

T-DASH 実装

カスタム動作

以下設定ファイルを browsercustom.yaml で保存する

@browsercustom.yaml
ACT-CAT-CUSTOM-6cb0946e-0fbc-4fe0-a2a9-ea40de045bf1:
  action_category_name: ブラウザ操作カスタム
  icon: ''
  color: '#ee7312'
  custom_data:
    file_name: CusBrowser
    pip_list: []
    library_list:
    - SeleniumLibrary
    - String
  actions:
    ACT-CUSTOM-78d7b64f-6368-4b6c-a28a-ff7f0296649d:
      action_name: profileを読み込んでchromeを起動する
      action_type: operation
      action_format: profileを読み込んでchromeを起動して、URL「設定値1」にアクセスする
      action_note: ''
      action_args:
      - value1
      action_def:
      - - Set Test Variable
        - ${USER_DIR}
        - C:\\Users\\LOGINUSER\\AppData\\Local\\Google\\Chrome\\User Data\\
      - - Set Test Variable
        - ${PROFILE}
        - Profile 1
      - - '${chrome_options} = '
        - Evaluate  selenium.webdriver.ChromeOptions()
      - - Call Method
        - ${chrome_options}
        - add_argument
        - --user-data-dir\=${USER_DIR}
      - - Call Method
        - ${chrome_options}
        - add_argument
        - --profile-directory\=${PROFILE}
      - - Open Browser
        - ${value1}
        - chrome
        - options=${chrome_options}
      - - Maximize Browser Window

次に、CusBrowser.yamlをT-DASHの動作定義 -> カスタム動作 -> カスタム動作をインポート にてインポートし、実際にインポートされた設定内容を開く

作られたカスタム動作を開くと、以下のような設定になっている。
4,5行目に、chromeから取得したprofile情報を設定する(user data dir と profile directory)

image.png

テストケース

呼び出すだけでよい

image.png

テスト実行

chromeのprofileが呼び出されている事(カラーやgoogleにloginした状態)が確認できる

image.png

最後に

profileの状態から始めるため、google以外のサイトでも同様です
ログインしてクッキーを持った状態から始めることも可能です
毎回ログインからテストすると、工数がかかる場合、ログイン状態からのprofileを用いることも有効です

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?