0
我正在嘗試用Jasmine和selenium webdriver編寫一個簡單的UI測試。selenium webdriver不能與茉莉花一起工作
但是,我無法使它工作。下面是我使用的環境:
- 節點V6.6.0
- [email protected] -3(安裝在node_modules)
- ChromeDriver 2.25.426935(在/ usr /本地/ bin)中
- 最新谷歌chrome(版本54.0.2840.71(64位))
- 的Mac OS X 10.11.6(酋長)
的代碼是(以打字稿)很簡單:
import * as webdriver from 'selenium-webdriver';
let by = webdriver.By;
let until = webdriver.until;
describe("my suite",() => {
beforeEach(() => {
})
afterEach(() => {
})
it("should work",() => {
console.log("==========>");
let driver = new webdriver.Builder()
.forBrowser("chrome")
.build();
driver.get("https://www.google.com")
.then(s => {
return driver.getTitle();
})
.then(title => { console.log(title) })
console.log("<==========");
})
});
生成的JS代碼:
"use strict";
var webdriver = require('selenium-webdriver');
var by = webdriver.By;
var until = webdriver.until;
describe("my suite", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should work", function() {
console.log("==========>");
var driver = new webdriver.Builder()
.forBrowser("chrome")
.build();
driver.get("https://www.google.com")
.then(function (s) {
return driver.getTitle();
})
.then(function (title) { console.log(title); });
console.log("<==========");
});
});
相同的代碼可沒有任何問題作爲一個獨立的JS(與節點)運行:
"use strict";
var webdriver = require('selenium-webdriver');
var by = webdriver.By;
var until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser("chrome")
.build();
driver.get("https://www.google.com").then(function (s) {
return driver.getTitle();
})
.then(function (title) { console.log(title); });
driver.quit();
我不知道是否有任何配置茉莉花與硒一起使用所需的配置。請幫忙。
將webdriver初始化移至「beforeEach」不起作用。如果我可以使代碼工作,我會將它移動到「beforeEach」之前並在「afterEach」之後退出。
那麼它是否會爲您打印任何錯誤?或由typescript生成的代碼不起作用? – pagep
我其實是想通了。由於硒webdriver是異步操作,我必須使用茉莉花/摩卡API的異步風味。 –