Tag: selenium

我如何使用nodejs selenium webdriver设置elementScrollBehaviorfunction

我创build驱动程序如下: driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.firefox()).build(); 我如何设置elementScrollBehavior ?

NodeJS,fs.readFileSync逐string读取和操作。 怎么样?

对不起,这么愚蠢的问题, 我怎么可以在NodeJS从文件string读取string的一些价值,例如 – url,并最终做每个string的操作? var contents = fs.readFileSync('test.txt', 'utf8'); 那么呢? 这是需要浏览器+seleniumtesting。 我想从文件中逐个运行一些链接,并对它们进行一些操作。 更改了下面的代码:from console.log(lines[i++]) 至 line = (lines[i++]) driver.get(line); driver.getCurrentUrl() .then(function(currentUrl) { console.log(currentUrl); 但它有一次。 和 var str=fs.readFileSync('test.txt'); str.split(/\n/).forEach(function(line){}) C:\nodejstest>node test1.js C:\nodejstest\test1.js:57 str.split(/\n/).forEach(function(line){ ^ TypeError: str.split is not a function at Object.<anonymous> (C:\nodejstest\test1.js:57:5) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at […]

我怎样才能在node.js selenium-webdriver中模拟右键单击?

我使用的是nodejs的selenium-webdriver 。 我怎样才能模仿这个驱动程序的右键单击? 我在官方文档中找不到这个。

e2e与jenkins,selenium网格和量angular器testing

我正在尝试使用Jenkins,Selenium和Protractor来构build我的testing环境。 我决定使用selenium插件(selenium网格)在远程机器(节点)之间调度testing。 我到目前为止所取得的成就是build立selenium中枢与节点之间的联系。 Jenkins上安装的Node.js版本是5.12.0,量angular器是3.3.0。 我还安装了npm chromedriver并在protractor.config.js中设置了这个驱动程序的path,如下所示: chromeDriver: '/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/chromedriver/bin/chromedriver' 节点正在运行selenium独立服务器,全局安装npm。 当我执行我的protractor.config.js文件时,我有以下错误: protractor /u01/apps/jenkins/data/workspace/Servers/testApp/protractor.conf.js [14:49:08] I/direct – Using ChromeDriver directly… [14:49:08] I/launcher – Running 1 instances of WebDriver /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329 return callbackFn(this.value_); ^ Error: Server terminated early with status 127 at Error (native) at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/remote/index.js:210:20 at Promise.invokeCallback_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14) at TaskQueue.execute_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14) at TaskQueue.executeNext_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21) at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27 at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7 […]

从量angular器库中的elements.all.each获取最终值

从每个循环中获取date数组后,我有点麻烦,它完成迭代。 这是上下文的代码: this.Then(/^The details should match with Splunk data$/,function(callback){ var x=[]; page0213.expandDate(); page0213.myDates(function(id){ x.push(id); console.log("Test: "+ x); }); browser.pause(); } ); 这个函数调用一个名为page0213.myDates的函数,如下所示: this.myDates = function(results){ element.all(by.css('td[ng-bind^=dashboardSummary]')).each(function(date){ date.getText().then(function(text) { results(text); }); }); } 我已经尝试把它作为一个承诺(像这样:“.each(…)。then(callback())”),并在每个之后移动callback(因为有些来源说,每个应该同步行为)。 我也尝试了Promise.promisify(elements.each),然后把它们放入一个像这样的蓝鸟协程: this.getDates = Promise.coroutine(function*(){ try{ let dates = []; yield browser.waitForAngular(); let elements = yield Promise.resolve(element.all(by.css('td[ng-bind^=dashboardSummary]'))); return elements }catch(exception){ console.error(exception); return "nothing […]

selenium等待错误的JavaScript

我正在提交一个包含selenium和幻灯片的表单,然后通过search一个表示表单已被提交的br元素来回到上一页。 有时超时将超过30s的分配时间,并会发生错误: TimeoutError: Waiting for element to be located By(xpath,//div[@id='ContactFormBody']/div/br) Wait timed out after 30003ms 我需要处理这个错误,以便我的程序不会崩溃,如果发生这种情况。 另外如果有人想提一下selenium node.js的好文档,那就太棒了! // code generating wait error form.then(function(self){ driver.wait(until.elementLocated(By.xpath("//div[@id='ContactFormBody']/div/br")), 30000) .then(function(){ driver.navigate().back(); }); }); // attempt at handling error form.then(function(self){ try{ driver.wait(until.elementLocated(By.xpath("//div[@id='ContactFormBody']/div/br")), 30000) .then(function(){ driver.navigate().back(); }); } catch(e){ console.log("error occurred, script will continue.") } });

Firefox不会等待页面加载Webdriverio

我正在尝试使用Selenium运行我的testing,并刚刚遇到问题。 我有我为Chrome浏览器编写的testing。 现在我一直试图在Firefox浏览器中运行相同的testing,但是失败了。 我已经开始调查这个问题,并发现Firefox不会等到页面完全加载。 Chrome的作品完美。 我在Docker容器中运行Selenium 。 这是我的脚本 storeSearch(info) { let that = this; return new Promise(function (resolve, reject) { browserClient.init() .url("http://somewhere.com") .selectByVisibleText("#store","Tech") // Redirect to a new page .setValue("input[name='search']", info.searchCriteria) .selectByValue(".featured", 'MacBook') .click("button[name='info']") .element('.popup') .then(function (element) { if (element.state === 'success') { } }); }); } 它甚至不会尝试从select .selectByVisibleText("#store","Tech")select一个存储types,而只是抛出一个exception。 “一个元素不能使用给定的search参数(\”input [name ='search'] \“)。”, 我试图添加timeouts但它不工作,给我一个错误。 browserClient.init() […]

如何使用jquery和selenium在'chrome:// downloads'下访问`shadow-root`下的元素?

我想在我的seleniumJavaScript应用程序中获取最后下载的文件的名称。 我有我的selenium驱动程序导航到铬下载页面使用: driver.get('chrome://downloads'); ,但是当我到达那里时,selenium在下载页面上无法find任何元素。 Chrome下载页面“chrome:// downloads”有一堆shadow-root元素,我不知道如何获取下面的内容以访问我想要的id。 如何访问shadow-root项目下的标识符? 我想获得$(“#文件链接”)如下所示: 但是,当我使用jQuery来find它,一切都返回null(可能是因为它是在shadow-root后面) 下面是我所有的信息的全貌,包括显示“#file-link”完全存在: 我用来等待元素存在的代码与我在应用程序中使用的所有元素相同,所以我认为这已经在工作: driver.wait(until.elementLocated(By.id('downloads-manager')), 120000).then(function(){ console.log("#downloads-manager shows"); driver.findElement(By.id('downloads-manager')).then(function(dwMan){ //How do I "open" #shadow-root now? 🙁 }); }); 这是我的版本信息: Chromium v​​54.0.2840.71 节点v6.5.0 ChromeDriver v2.27.440175 selenium-Webdriver v3.4.0 类似的问题 seleniumwebdriver找不到铬://下载 (这是我有,但在Python中相同的问题) 链接 Selenium JavaScript API: https : //seleniumhq.github.io/selenium/docs/api/javascript/

如何将Docker容器端口暴露给另一个容器

我有一个docker集装箱,依靠selenium作为链接服务(也是docker集装箱)。 这个docker集装箱只是使用selenium服务作为主机来运行nightwatchJStesting无头。 selenium服务启动正常,但是当夜间testing试图在docker集装箱内运行时,我在selenium服务端口(4444)上收到拒绝的连接错误。 我可以使用curl访问此端口的selenium主机,也可以运行它的夜间testing,如果我不通过docker运行testing。 这里是我的docker撰写yaml文件: services: selenium: image: selenium/standalone-chrome ports: – "4444:4444" nightwatch: build: . volumes: – .:/home/client_test links: – selenium environment: selenium: 4444 expose: – "4444" 和我的docker文件: # #Nightwatch.js Dockerfile # FROM alpine:3.4 WORKDIR /home/client-tests ADD . /home/client-tests/ ENV NODE_PATH=/home/client-app/node_modules #RUN apk add 'firefox-esr<45.6.0-r0' #install firefox #RUN wget -c http://ftp.mozilla.org/pub/firefox/releases/45.8.0esr/firefox-45.8.0esr.linux-x86_64.sdk.tar.bz2 -P /usr/local #RUN tar […]

在多个浏览器上运行testing(按顺序)

我目前只使用Chrome(驱动程序)进行testing。 我想用Firefox和Safari来testing它。 一个接一个,不能并行。 这是我开始testing的重要任务: gulp.task('test', function() { return gulp.src('*test/features/*').pipe(cucumber({ 'steps': '*test/features/steps/*.js' })); }); 一个简单的function文件: Feature: UI Testing UI Scenario: Check the title of the page When I open the homepage Then I should see "Test – IntApp" in the title 和步骤文件: const chrome = require('selenium-webdriver/chrome'); const webdriver = require('selenium-webdriver'); const assert = require('assert'); module.exports = […]