5
3

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 5 years have passed since last update.

webdriverjs + jasmine-nodeでWebテストをする。(各種input制御)

Posted at

やりたいこと

webdriverjsでの各種入力項目の制御方法が知りたい。

まとめ

自分で書いたHTMLならidとかclassをきちんと入れられるので問題なさそう。
基本、sendKeys()とclick()でなんとなりそう。

テストを書く

input.spec.js
var webdriver = require("/usr/local/lib/node_modules/selenium-webdriver");

var driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.chrome())
    .build();

describe('input test',function(){

	it('input',function(done){

		driver.get("http://localhost/input.html");

		//各要素を選択

		//text
		var name = driver.findElement(webdriver.By.id("name"));
		name.sendKeys("hoge");

		//radio
		var man = driver.findElement(webdriver.By.id("man"));
		man.click();

		//checkbox
		var check_a = driver.findElement(webdriver.By.id("check_a"));
		check_a.click();

		//select
		var area = driver.findElement(webdriver.By.id("area"));
		area.sendKeys("osaka");

		//submit
		var btn_submit = driver.findElement(webdriver.By.id("btn_submit"));
		btn_submit.click();

		//終わり
		driver.quit().then(function(){
			done();
		});
	});
});

テスト(制御)対象のHTML

input.html
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<form action="res.php" method="post">
name:<input type="text" id="name" name="name"><br>
man:<input type="radio" id="man" name="gender" value="man">woman:<input type="radio" id="woman" name="gender" value="woman"><br>
a:<input type="checkbox" id="check_a" value="a" name="check_a">b:<input type="checkbox" id="check_b" value="b" name="check_b"><br>
<select id="area" name="area">
	<option value="tokyo">TOKYO</option>
	<option value="osaka">OSAKA</option>
</select><br>
<input type="submit" value="send" id="btn_submit">
</form>
</body>
</html>
5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?