34 lines
988 B
TypeScript
34 lines
988 B
TypeScript
import { Builder, By, Capabilities, Key, until } from 'selenium-webdriver';
|
|
|
|
async function runTests() {
|
|
// Selenium Server URL (Assuming your Selenium Server is running on localhost at port 4444)
|
|
const seleniumServerUrl = "http://localhost:4444/wd/hub";
|
|
|
|
// 使用 Chrome 浏览器
|
|
const capabilities = Capabilities.chrome();
|
|
|
|
// 创建一个 WebDriver 实例
|
|
let driver = new Builder()
|
|
.usingServer(seleniumServerUrl)
|
|
.withCapabilities(capabilities)
|
|
.build();
|
|
|
|
try {
|
|
// 你的测试代码
|
|
// 例如,打开 Google 网页
|
|
await driver.get('http://www.google.com');
|
|
|
|
// 找到搜索框并输入查询词
|
|
await driver.findElement(By.name('q')).sendKeys('Hello World', Key.RETURN);
|
|
|
|
// 等待搜索结果
|
|
await driver.wait(until.titleContains('Hello World'), 1000);
|
|
|
|
} finally {
|
|
// 关闭浏览器
|
|
await driver.quit();
|
|
}
|
|
}
|
|
|
|
runTests().catch(console.error);
|