commit ca8c79a11c40d1ccef2cbebaeae19aacaca30524 Author: nobug Date: Sun Dec 10 20:49:54 2023 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3632033 --- /dev/null +++ b/.gitignore @@ -0,0 +1,174 @@ +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +\*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +\*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +\*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +\*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.cache +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +.cache/ + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp +.cache + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.\* + +# wrangler project + +.dev.vars +.wrangler/ + +.DS_Store \ No newline at end of file diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..0db33f0 Binary files /dev/null and b/bun.lockb differ diff --git a/fitst.ts b/fitst.ts new file mode 100644 index 0000000..1d2dd91 --- /dev/null +++ b/fitst.ts @@ -0,0 +1,59 @@ +import { Builder, By, Capabilities, WebDriver } from 'selenium-webdriver'; +// docker run --name=chrome -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:latest + +// docker run --name=seleniumChromium --rm -it -p 4444:4444 -p 5900:5900 -p 7900:7900 --shm-size 2g seleniarm/standalone-chromium:latest +// d3563738379c chromium 5.83% 118.8MiB / 903.1MiB 13.15% 199kB / 710kB 1.9GB / 422MB 72 + +// docker run --name=seleniumFirefox --rm -it -p 4444:4444 -p 5900:5900 -p 7900:7900 --shm-size 2g seleniarm/standalone-firefox:latest +// docker run --name=seleniumFirefox -d -p 4444:4444 -p 5900:5900 -p 7900:7900 --shm-size 2g seleniarm/standalone-firefox:latest +// 3dd45b3d5e1e firefox 6.39% 102.2MiB / 903.1MiB 11.31% 223kB / 88kB 2.5GB / 769MB 71 + + +(async function firstTest() { + let driver: WebDriver | null = null; + + try { + + // Selenium Server URL (Assuming your Selenium Server is running on localhost at port 4444) + const seleniumServerUrl = "http://150.230.239.12:4444/wd/hub"; + + // 使用 Chrome 浏览器 + // const capabilities = Capabilities.chrome(); + const capabilities = Capabilities.firefox(); + + // 创建一个 WebDriver 实例 + driver = new Builder() + .usingServer(seleniumServerUrl) + .withCapabilities(capabilities) + .build(); + + + // driver = await new Builder().forBrowser('chrome').build(); + await driver.get('https://www.selenium.dev/selenium/web/web-form.html'); + + let title = await driver.getTitle(); + console.debug(`title :>> `, title); + // assert.equal("Web form", title); + + await driver.manage().setTimeouts({ implicit: 500 }); + + let textBox = await driver.findElement(By.name('my-text')); + let submitButton = await driver.findElement(By.css('button')); + + await textBox.sendKeys('Selenium'); + + // await new Promise(resolve => setTimeout(resolve, 3000)); + + await submitButton.click(); + + let message = await driver.findElement(By.id('message')); + let value = await message.getText(); + console.debug(`value :>> `, value); + // assert.equal("Received!", value); + } catch (e) { + console.log(e) + } finally { + await new Promise(resolve => setTimeout(resolve, 1000)); + await driver?.quit(); + } +}()) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..841acd8 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "selenium-demo", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "mocha": "^10.2.0", + "selenium-webdriver": "^4.16.0" + }, + "devDependencies": { + "typescript": "^5.3.3", + "@types/selenium-webdriver": "^4.1.21" + } +} \ No newline at end of file diff --git a/second.ts b/second.ts new file mode 100644 index 0000000..a9f6c52 --- /dev/null +++ b/second.ts @@ -0,0 +1,33 @@ +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);