Skip to content

Commit 838e498

Browse files
author
f.takano
committed
First Commit
0 parents  commit 838e498

File tree

8 files changed

+174
-0
lines changed

8 files changed

+174
-0
lines changed

.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry kind="lib" path="C:/Users/futeshi/Downloads/selenium-server-standalone-2.38.0.jar"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>seleniumTest</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.7
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.7

bin/com/hr/rakus/TestBase.class

1.1 KB
Binary file not shown.

bin/com/hr/rakus/TestCase.class

2.62 KB
Binary file not shown.

src/com/hr/rakus/TestBase.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.hr.rakus;
2+
import org.junit.After;
3+
import org.junit.AfterClass;
4+
import org.junit.Before;
5+
import org.junit.BeforeClass;
6+
import org.openqa.selenium.server.SeleniumServer;
7+
8+
import com.thoughtworks.selenium.SeleneseTestBase;
9+
10+
11+
public class TestBase extends SeleneseTestBase {
12+
private static SeleniumServer seleniumServer;
13+
14+
public TestBase() { super(); }
15+
16+
@BeforeClass
17+
public static void init() throws Exception {
18+
seleniumServer = new SeleniumServer();
19+
seleniumServer.start();
20+
}
21+
22+
@Before
23+
public void before() throws Exception {
24+
setUp("http://example.com/", "*googlechrome");
25+
}
26+
27+
@After
28+
public void after() throws Exception {
29+
tearDown();
30+
}
31+
32+
@AfterClass
33+
public static void finish() {
34+
seleniumServer.stop();
35+
}
36+
}

src/com/hr/rakus/TestCase.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.hr.rakus;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
6+
import org.apache.commons.io.FileUtils;
7+
import org.openqa.selenium.By;
8+
import org.openqa.selenium.OutputType;
9+
import org.openqa.selenium.TakesScreenshot;
10+
import org.openqa.selenium.WebDriver;
11+
import org.openqa.selenium.WebDriverException;
12+
import org.openqa.selenium.WebElement;
13+
import org.openqa.selenium.chrome.ChromeDriver;
14+
import org.openqa.selenium.firefox.FirefoxDriver;
15+
16+
public class TestCase extends TestBase {
17+
public static void main(String[] args) {
18+
//ブラウザ起動
19+
WebDriver driver = new FirefoxDriver();
20+
//Googleのトップページを開く
21+
driver.get("https://www.google.co.jp");
22+
sleep(1000);
23+
//検索
24+
WebElement text = driver.findElement(By.id("lst-ib"));
25+
text.sendKeys("selenium");
26+
sleep(1000);
27+
driver.findElement(By.name("btnK")).submit();
28+
sleep(1000);
29+
//URLをクリック
30+
driver.findElement(By.className("r")).click();
31+
sleep(1000);
32+
//想定通りのURLかチェック
33+
assertEquals(driver.getCurrentUrl(), "http://www.seleniumhq.org/");
34+
System.out.println(driver.getTitle());
35+
//スクリーンショット取得
36+
takeScreenShot(driver, "C:\\Users\\futeshi\\ci\\screenShot.png");
37+
//ブラウザを閉じる
38+
driver.quit();
39+
}
40+
41+
public static void sleep(int microTime) {
42+
try {
43+
Thread.sleep(microTime);
44+
}catch (InterruptedException e) {
45+
e.printStackTrace();
46+
}
47+
}
48+
49+
public static void takeScreenShot(WebDriver driver, String filePath) {
50+
try {
51+
FileUtils.copyFile(
52+
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE),
53+
new File(filePath));
54+
} catch (WebDriverException e) {
55+
e.printStackTrace();
56+
} catch (IOException e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
}

メモ.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
◯Seleniumとは?
2+
3+
Webアプリケーションのテストを自動化するためのフレームワーク。
4+
Seleniumが提供するコマンドやAPIを利用して、実際にブラウザを動かしながらWebアプリケーションの動作を確認することができる。
5+
6+
従来は手で行っていたブラウザを使用するテストをツールに実施させることにより、回帰テストのコストを減らす効果がある。
7+
8+
◯実際に使ってみる
9+
Selenium IDE(FireFoxのプラグイン)のダウンロード → 実際に動かす
10+
11+
◯Junit+Selenium
12+
実際の運用ではJunitで記述されることが多いため、Junitから実行してみる。
13+
参考:簡単・便利、ブラウザの自動操作!~Selenium WebDriver~ : アシアルブログ
14+
http://blog.asial.co.jp/1180
15+
Chromeから実行してみる時→
16+
Selenium 2でChromeDriverを使う - azuki note
17+
http://kenichiro22.hatenablog.com/entry/20110825/1314280671
18+
19+
20+
21+
22+
◯SeleniumとJenkinsを組み合わせてCI環境の構築
23+
・CIとは
24+
継続的インテグレーション。ビルド、テストを常に繰り返し実行し、開発者へフィードバックすることにより、問題の早期発見を可能にすること。
25+
26+
◯なぜCIツールを使うの?
27+
1:ビルドやテストを自動的に行うことにより、素早く同じ手順で実行できるため、手作業によるミスがなくなる。また、誰でも簡単にビルドやテストの実行を行えるようになる。
28+
2:不具合の早期発見が可能になる。
29+
3:ビルドやテストの実行結果を共有して、品質の見える化を図る。
30+
31+
◯なぜJenkinsなの?
32+
・環境構築が簡単(実態がwarファイルなので、導入しやすい)
33+
・プラグインが豊富
34+
・オープンソースである。
35+
36+
◯JenkinsとSeleniumを組み合わせると何ができるのか?
37+
1:ソースコードをSCM(ソースコード管理システム)よりチェックアウトする
38+
2:ソースコードをビルドしwarファイルを作成する
39+
3:Tomcatに作成したwarファイルをデプロイする
40+
4:Selenium2でテストを実行する
41+
42+
上記の作業をコミットと同時に行ったり、APIから実行したりできる。

0 commit comments

Comments
 (0)