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?

More than 1 year has passed since last update.

[setup] robotframework + windows

Last updated at Posted at 2024-01-30

Outline

robotframeworkをwindowsで構築したとき、ハマったので議事録的に設定ログを残す

Environment

  • windows11

Python

Pythonのinstallerをdonwloadしてインストールする

install optionでは、all userが使えるように、そしてpathを通す。

image.png

image.png

最後に、command consoleを立ち上げ、pythonのpathが通っていることを確認する

image.png

Robotframework

上記でpipが使えるようになっているはず。
もし、pipコマンドが使えない場合、pathを確認する。

上記、defaultでpythonのinstall pathを指定した場合、

C:\Program Files\Python312\Scripts

に、pipなどが存在する。
このpathが環境設定で定義されているかを確認する。

image.png

pip install robotframework

robotを実行するために、改めてpathの設定が必要になる。
pipでinstallされたものは、個人folderにinstallされるからである。
※install時に、warningが出るはず。

%UserProfile%\AppData\Roaming\Python\Python312\Scripts

image.png

robot動作確認

robot

image.png

おまけ

もし、all userにinstallさせたい場合、以下の環境変数で、scriptsのinstall pathを指定する。
尚、この場合permission関連に注意する必要がある。

PYTHONUSERBASE

image.png

Sample Code

chromeをつかって簡単なコードを実行する

尚、chromeを使う場合、chromedriverが必要になる。
以下サイトから最新のdriver(chromeが最新であれば)をdownloadしてきて、実行可能なpath(PATHの通っている場所、もしくは実行する場所)に置く

Seleniumのrobotframeworkのkeywordsはこちら

Sample Source Code

  1. chrome open
  2. click 任意の競馬場
    image.png
  3. check 開催タイトル&出力
    image.png

sample.robot

*** Settings ***
Library  SeleniumLibrary


*** Variables ***
${BROWSER}  chrome
${TIME_FOR_STABLE}  3s


*** Keywords ***
Access WebSite
	[Arguments]  ${url}
	Log to Console  open ${BROWSER} and access ${url}
	Open Browser  ${url}  ${BROWSER}
	Sleep  ${TIME_FOR_STABLE}


*** Test Cases ***

Open Browser and Access keiba site
	Access WebSite  https://keiba.rakuten.co.jp


Go Info Page
	Click Element  xpath=//*[@id="todayRaceBox"]/ul/li[1]/div/div[1]/a/span/span
	Wait Until Element Is Visible  xpath=//*[@id="mainContainer"]/div[4]/h2  timeout=10s
	${kaisai_title} =  Get Text  xpath=//*[@id="mainContainer"]/div[4]/h2
	Log to Console  kaisai_title ${kaisai_title}
robot sample.robot

image.png

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?