gulp-protractor https://www.e-learn.cn/tag/gulp-protractor zh-hans gulp-protractor error with chrome v54 / web driver v2.25 https://www.e-learn.cn/topic/3247294 <span>gulp-protractor error with chrome v54 / web driver v2.25</span> <span><span lang="" about="/user/52" typeof="schema:Person" property="schema:name" datatype="">◇◆丶佛笑我妖孽</span></span> <span>2020-01-17 05:22:20</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Due to the latest update of chrome (v54) we've noticed our protractor tests failing. We attempted to update to the latest version of gulp-protractor (v3.0.0) which in turn downloads the latest web driver (v2.25) to resolve the issue but unfortunately a new error occurs we've been unable to resolve.</p> <p>Everything worked fine before chrome's update.</p> <p>Our protractor configuration is as follows:</p> <pre><code>exports.config = { // Capabilities to be passed to the webdriver instance. capabilities: { 'browserName': 'chrome' }, onPrepare: function () { var fs = require('fs'); var testDir = 'testresults/'; if (!fs.existsSync(testDir)) { fs.mkdirSync(testDir); } var jasmineReporters = require('jasmine-reporters'); // returning the promise makes protractor wait for the reporter config before executing tests return browser.getProcessedConfig().then(function () { // you could use other properties here if you want, such as platform and version var browserName = 'browser'; browser.getCapabilities().then(function (caps) { browserName = caps.caps_.browserName.replace(/ /g, "_"); var junitReporter = new jasmineReporters.JUnitXmlReporter({ consolidateAll: true, savePath: testDir, // this will produce distinct xml files for each capability filePrefix: 'test-protractor-' + browserName, modifySuiteName: function (generatedSuiteName) { // this will produce distinct suite names for each capability, // e.g. 'firefox.login tests' and 'chrome.login tests' return 'test-protractor-' + browserName + '.' + generatedSuiteName; } }); jasmine.getEnv().addReporter(junitReporter); }); }); }, baseUrl: 'http://localhost:3000', // Spec patterns are relative to the current working directory when // protractor is called. specs: [paths.e2e + '/**/*.js'], // Options to be passed to Jasmine-node. jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000 } }; </code></pre> <p>The error is:</p> <pre><code>[13:27:13] E/launcher - Error: Error at C:\ws\node_modules\protractor\built\util.js:55:37 at _rejected (C:\ws\node_modules\q\q.js:844:24) at C:\ws\node_modules\q\q.js:870:30 at Promise.when (C:\ws\node_modules\q\q.js:1122:31) at Promise.promise.promiseDispatch (C:\ws\node_modules\q\q.js:788:41) at C:\ws\node_modules\q\q.js:604:44 at runSingle (C:\ws\node_modules\q\q.js:137:13) at flush (C:\ws\node_modules\q\q.js:125:13) at nextTickCallbackWith0Args (node.js:420:9) at process._tickCallback (node.js:349:13) [13:27:13] E/launcher - Process exited with error code 100 </code></pre> <br /><h3>回答1:</h3><br /><p><code>onPrepare</code> is being evaluated in built/util.js in the <code>runFilenameOrFn_</code> function. The stacktrace unfortunately is not helpful but what this means is that <code>onPrepare</code> has errors. Looking at your <code>onPrepare</code> method, the error is made when assigning the browserName from the browser capabilities. In your code, <code>caps.caps_</code> is actually undefined. Because <code>caps.caps_</code> is undefined, <code>caps.caps_.browserName</code> is throwing an error. The capabilities object should be accessed as the following:</p> <pre><code>browser.getCapabilities().then(capabilities =&gt; { let browserName = capabilities.browserName.replace(/ /g, "_"); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/40295638/gulp-protractor-error-with-chrome-v54-web-driver-v2-25</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/google-chrome" hreflang="zh-hans">google-chrome</a></div> <div class="field--item"><a href="/tag/gulp" hreflang="zh-hans">gulp</a></div> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/chrome-web-driver" hreflang="zh-hans">chrome-web-driver</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Thu, 16 Jan 2020 21:22:20 +0000 ◇◆丶佛笑我妖孽 3247294 at https://www.e-learn.cn gulp-protractor error with chrome v54 / web driver v2.25 https://www.e-learn.cn/topic/3247284 <span>gulp-protractor error with chrome v54 / web driver v2.25</span> <span><span lang="" about="/user/111" typeof="schema:Person" property="schema:name" datatype="">落爺英雄遲暮</span></span> <span>2020-01-17 05:22:04</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Due to the latest update of chrome (v54) we've noticed our protractor tests failing. We attempted to update to the latest version of gulp-protractor (v3.0.0) which in turn downloads the latest web driver (v2.25) to resolve the issue but unfortunately a new error occurs we've been unable to resolve.</p> <p>Everything worked fine before chrome's update.</p> <p>Our protractor configuration is as follows:</p> <pre><code>exports.config = { // Capabilities to be passed to the webdriver instance. capabilities: { 'browserName': 'chrome' }, onPrepare: function () { var fs = require('fs'); var testDir = 'testresults/'; if (!fs.existsSync(testDir)) { fs.mkdirSync(testDir); } var jasmineReporters = require('jasmine-reporters'); // returning the promise makes protractor wait for the reporter config before executing tests return browser.getProcessedConfig().then(function () { // you could use other properties here if you want, such as platform and version var browserName = 'browser'; browser.getCapabilities().then(function (caps) { browserName = caps.caps_.browserName.replace(/ /g, "_"); var junitReporter = new jasmineReporters.JUnitXmlReporter({ consolidateAll: true, savePath: testDir, // this will produce distinct xml files for each capability filePrefix: 'test-protractor-' + browserName, modifySuiteName: function (generatedSuiteName) { // this will produce distinct suite names for each capability, // e.g. 'firefox.login tests' and 'chrome.login tests' return 'test-protractor-' + browserName + '.' + generatedSuiteName; } }); jasmine.getEnv().addReporter(junitReporter); }); }); }, baseUrl: 'http://localhost:3000', // Spec patterns are relative to the current working directory when // protractor is called. specs: [paths.e2e + '/**/*.js'], // Options to be passed to Jasmine-node. jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000 } }; </code></pre> <p>The error is:</p> <pre><code>[13:27:13] E/launcher - Error: Error at C:\ws\node_modules\protractor\built\util.js:55:37 at _rejected (C:\ws\node_modules\q\q.js:844:24) at C:\ws\node_modules\q\q.js:870:30 at Promise.when (C:\ws\node_modules\q\q.js:1122:31) at Promise.promise.promiseDispatch (C:\ws\node_modules\q\q.js:788:41) at C:\ws\node_modules\q\q.js:604:44 at runSingle (C:\ws\node_modules\q\q.js:137:13) at flush (C:\ws\node_modules\q\q.js:125:13) at nextTickCallbackWith0Args (node.js:420:9) at process._tickCallback (node.js:349:13) [13:27:13] E/launcher - Process exited with error code 100 </code></pre> <br /><h3>回答1:</h3><br /><p><code>onPrepare</code> is being evaluated in built/util.js in the <code>runFilenameOrFn_</code> function. The stacktrace unfortunately is not helpful but what this means is that <code>onPrepare</code> has errors. Looking at your <code>onPrepare</code> method, the error is made when assigning the browserName from the browser capabilities. In your code, <code>caps.caps_</code> is actually undefined. Because <code>caps.caps_</code> is undefined, <code>caps.caps_.browserName</code> is throwing an error. The capabilities object should be accessed as the following:</p> <pre><code>browser.getCapabilities().then(capabilities =&gt; { let browserName = capabilities.browserName.replace(/ /g, "_"); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/40295638/gulp-protractor-error-with-chrome-v54-web-driver-v2-25</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/google-chrome" hreflang="zh-hans">google-chrome</a></div> <div class="field--item"><a href="/tag/gulp" hreflang="zh-hans">gulp</a></div> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/chrome-web-driver" hreflang="zh-hans">chrome-web-driver</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Thu, 16 Jan 2020 21:22:04 +0000 落爺英雄遲暮 3247284 at https://www.e-learn.cn Protractor - beforeAll and afterAll undefined https://www.e-learn.cn/topic/2375670 <span>Protractor - beforeAll and afterAll undefined</span> <span><span lang="" about="/user/121" typeof="schema:Person" property="schema:name" datatype="">对着背影说爱祢</span></span> <span>2019-12-12 09:24:44</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am using Protractor with jasmine. Protractor version is <code>3.2.2</code>, I found this using the command <code>protractor --version</code>. How to find the jasmine version used by protractor. When I read the updgrade doc, I couldn't find the steps to upgrade jasmine, all I found is to add <code>jasmine2</code> in configuration file. </p> <p>My configuration file looks like this</p> <pre><code>exports.config = { framework: 'jasmine2', .... } </code></pre> <p>But I still was not able to use <code>beforeAll and afterAll</code>. Am I missing anything here. Since <code>beforeAll and afterAll</code> are undefined I think the version of jasmine used by protractor is not 2x.</p> <p>Any help is greatly appreciated.</p> <p>Thanks.</p> <br /><h3>回答1:</h3><br /><p>Protractor 3.2.2 as of <code>20th April 2016</code> is bundled with Jasmine 2.4 </p> <p>A fresh install of protractor should fetch you the 2.4 version, and you can verify this while looking at the npm install dependency tree log (the npm output after it finished installing a module), search for jasmine in that tree and you should see the 2.4 version being reported. </p> <p>Also, the correct config to be used is: </p> <p><code>framework: 'jasmine' </code></p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/36709893/protractor-beforeall-and-afterall-undefined</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/angularjs" hreflang="zh-hans">angularjs</a></div> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/angularjs-e2e" hreflang="zh-hans">angularjs-e2e</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Thu, 12 Dec 2019 01:24:44 +0000 对着背影说爱祢 2375670 at https://www.e-learn.cn Running Gulp-Angular-Protractor without gulp.src https://www.e-learn.cn/topic/2360660 <span>Running Gulp-Angular-Protractor without gulp.src</span> <span><span lang="" about="/user/215" typeof="schema:Person" property="schema:name" datatype="">我的梦境</span></span> <span>2019-12-12 05:49:33</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Gulp-Protractor and Gulp-Angular-Protractor can pass args and a config file to protractor.</p> <p>So why do I need to pass a list of files to gulp?</p> <pre><code>function runProtractor(done) { var params = process.argv; var args = params.length &gt; 3 ? [params[3], params[4]] : []; gutil.log('arguments: ' + args); gulp.src(paths.e2eFiles) .pipe(protractor({ configFile: 'protractor.local.conf.js', args: args, 'autoStartStopServer': true, 'debug': true })) .on('error', function (err) { gutil.log(gutil.colors.red("An error occurred in protractor. Did you start the webdriver?")); gutil.log(gutil.colors.red("Run cmd 'start gulp webdriver'.")); gutil.log(gutil.colors.red('error: ' + err)); // Make sure failed tests cause gulp to exit non-zero throw err; }) .on('end', function () { // Close browser sync server browserSync.exit(); done(); }); </code></pre> <p>} The problem is that protractor are not running the suites but the files in src. Is there a way to call protractor direct?</p> <br /><h3>回答1:</h3><br /><p>You can leave the gulp.src blank and pass the specs or suites as args, the documentation isn't great at explaining it but I have been able to pass any config file argument that I have tried through gulp as an arg (I think i had an issue with direct connect because it's a boolean and not a string).</p> <pre><code>gulp.task('e2e', function(cb) { gulp.src([]).pipe(protractor({ configFile: './conf/protractor.conf.js', args: [ '--baseUrl', 'http://localhost/', '--maxSessions', 1, '--suite', './specs/test-spec.js', '--params.environment', 'development' ] })).on('error', function(e) { throw e }) .on('end', cb) }); }; </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/38436507/running-gulp-angular-protractor-without-gulp-src</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/gulp" hreflang="zh-hans">gulp</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Wed, 11 Dec 2019 21:49:33 +0000 我的梦境 2360660 at https://www.e-learn.cn Protractor - Unable to access element due to fixed Top navigation bar https://www.e-learn.cn/topic/2286791 <span>Protractor - Unable to access element due to fixed Top navigation bar</span> <span><span lang="" about="/user/91" typeof="schema:Person" property="schema:name" datatype="">给你一囗甜甜゛</span></span> <span>2019-12-11 17:08:52</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm facing the following issue in protractor with jasmine</p> <p>Click/mouse hover not working because of fixed top navigation bar in my application. I need to click/perform mouse hover on a web page. Unfortunately that element is displaying behind that fixed navigation bar. So scroll till element present &amp; click by x &amp; y coordinates are not working.</p> <p>My dependencies are :</p> <p>protractor version 5.2.2</p> <p>node 8.9.3</p> <p>selenium standalone 3.13</p> <p>chrome driver-2.40</p> <p>chromebrowser v67</p> <p>OS- Windows 10</p> <p>Thanks in advance</p> <br /><h3>回答1:</h3><br /><p>Try using prototype executeScript</p> <p>Just try clicking that element from the browser console using id,name or xpath.</p> <p>For example :</p> <pre><code>var el = element(by.module('header')); var tag = browser.executeScript('return arguments[0].click()', el).then(function() { expect(something).toMatch(something); }); </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>Another way, along the same lines as what Bharath Kumar S and knowing JeffC's caveat that this approach is cheating, I had a similar issue where the App-Header kept getting in my way of clicking, and I knew I was willing to never need it (so, for instance, to find other ways to navigate or log out and not check for stuff that was on it). I, therefore, did the following, which solved the problem. Note if you refresh the screen, you have to call it again. Also note I am using a number of functions from https://github.com/hetznercloud/protractor-test-helper, which do what you would expect from their names.</p> <pre><code>var removeAppHeaderIfAny = async function() { //this function hides the app header //it is useful to avoid having covers there when Protractor worries that something else will get the click let found = false; try { found = await waitToBeDisplayed(by.className("app-header"), 2000); } catch (e) { let s: string = "" + e; if (s.search("TimeoutError") != 0) flowLog("presumably fine, cover already removed: " + e); found = false; } if (!found) return; if (found) { let coverElement = await element(by.className("app-header")); browser.executeScript( "arguments[0].style.visibility='hidden';", coverElement ); await waitToBeNotDisplayed(by.className("app-header"), 10000); } return; //note after this is called you will not see the item, so you cannot click it }; </code></pre> <p>As I look at the code, it strikes me one can probably remove the if (found) and associated brackets at the end. But I pasted in something I know has been working, so I am not messing with that.</p> <p>As indicated up front, I knew I was willing to forego use of the app-header, and it is a bit crude. </p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/51767496/protractor-unable-to-access-element-due-to-fixed-top-navigation-bar</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/selenium-webdriver" hreflang="zh-hans">selenium-webdriver</a></div> <div class="field--item"><a href="/tag/jasmine" hreflang="zh-hans">jasmine</a></div> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Wed, 11 Dec 2019 09:08:52 +0000 给你一囗甜甜゛ 2286791 at https://www.e-learn.cn Unable to launch Microsoft edge with protractor https://www.e-learn.cn/topic/2283240 <span>Unable to launch Microsoft edge with protractor</span> <span><span lang="" about="/user/89" typeof="schema:Person" property="schema:name" datatype="">巧了我就是萌</span></span> <span>2019-12-11 16:31:35</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Unable to launch edge browser on windows 10 with protractor. edge -Microsoft EdgeHTML 15.15063 downloaded the supported edge driver from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ i.e Release 15063.</p> <p>here is my protractor conf file. </p> <pre><code>module.exports = { //seleniumAddress: 'http://localhost:17556', keepAlive: true, seleniumArgs: ['-Dwebdriver.edge.driver=node_modules/protractor/node_modules/webdriver-manager/selenium/MicrosoftWebDriver.exe'], capabilities: { 'browserName': 'MicrosoftEdge', elementScrollBehavior: 1, nativeEvents: false }, framework: 'jasmine2', jasmineNodeOpts: { defaultTimeoutInterval: 200000, isVerbose: true, }, }); } }; </code></pre> <p>Error message post launch the e2e: </p> <p>[1</p> <pre><code>1:16:58] I/local - Starting selenium standalone server... [11:16:59] E/launcher - Error: Error: Server terminated early with status 1 at Error (native) at earlyTermination.catch.e (C:\code\e2e\node_modules\selenium-webdriver\remote\index.js:252:52) at process._tickCallback (internal/process/next_tick.js:109:7) Closing report [11:16:59] E/launcher - Process exited with error code 100 npm ERR! Windows_NT 10.0.15063 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "sanitytests" npm ERR! node v6.11.0 npm ERR! npm v3.10.10 npm ERR! code ELIFECYCLE npm ERR! sanitytests: `protractor protractor-sanitytest-conf.js` npm ERR! Exit status 100 npm ERR! npm ERR! Failed at the sanitytests script 'protractor protractor-sanitytests-conf.js'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the ??? package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! protractor protractor-sanitytests-conf.js </code></pre> <p>Could anyone please guide here.</p> <p>I have updated the node version, now getting unable to create a new service with edge browser.</p> <pre><code>(node:384) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. [14:17:36] I/launcher - Running 1 instances of WebDriver [14:17:36] I/local - Starting selenium standalone server... [14:17:37] I/local - Selenium standalone server started at http://192.168.1.4:61872/wd/hub [14:17:37] E/launcher - Unable to create new service: EdgeDriverService Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z' System info: host: 'DESKTOP-6VHU42F', ip: '192.168.1.4', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65' Driver info: driver.version: unknown [14:17:37] E/launcher - SessionNotCreatedError: Unable to create new service: EdgeDriverService Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z' System info: host: 'DESKTOP-6VHU42F', ip: '192.168.1.4', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65' Driver info: driver.version: unknown at Object.checkLegacyResponse (C:\code\e2e\tests\node_modules\selenium-webdriver\lib\error.js:546:15) at parseHttpResponse (C:\code\e2e\tests\node_modules\selenium-webdriver\lib\http.js:509:13) at doSend.then.response (C:\code\e2e\tests\node_modules\selenium-webdriver\lib\http.js:441:30) at &lt;anonymous&gt; at process._tickCallback (internal/process/next_tick.js:188:7) From: Task: WebDriver.createSession() at Function.createSession (C:\code\e2e\tests\node_modules\selenium-webdriver\lib\webdriver.js:769:24) at createDriver (C:\code\e2e\tests\node_modules\selenium-webdriver\index.js:170:33) at Builder.build (C:\code\e2e\tests\node_modules\selenium-webdriver\index.js:635:14) at Local.getNewDriver (C:\code\e2e\tests\node_modules\protractor\built\driverProviders\driverProvider.js:53:33) at Runner.createBrowser (C:\code\e2e\tests\node_modules\protractor\built\runner.js:195:43) at q.then.then (C:\code\e2e\tests\node_modules\protractor\built\runner.js:339:29) at _fulfilled (C:\code\e2e\tests\node_modules\q\q.js:834:54) at self.promiseDispatch.done (C:\code\e2e\tests\node_modules\q\q.js:863:30) at Promise.promise.promiseDispatch (C:\code\e2e\tests\node_modules\q\q.js:796:13) at C:\code\e2e\tests\node_modules\q\q.js:604:44 at runSingle (C:\code\e2e\tests\node_modules\q\q.js:137:13) at flush (C:\code\e2e\tests\node_modules\q\q.js:125:13) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) [14:17:37] E/launcher - Process exited with error code 199 npm ERR! code ELIFECYCLE npm ERR! errno 199 npm ERR! sanitytests: `protractor protractor-sanitytests-conf.js` npm ERR! Exit status 199 npm ERR! npm ERR! Failed at the sanitytests script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. </code></pre> <br /><h3>回答1:</h3><br /><p>You have old node version. Update to latest with command: </p> <pre><code>npm update npm -g </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/47766363/unable-to-launch-microsoft-edge-with-protractor</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javascript" hreflang="zh-hans">javascript</a></div> <div class="field--item"><a href="/tag/selenium" hreflang="zh-hans">selenium</a></div> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/microsoft-edge" hreflang="zh-hans">microsoft-edge</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Wed, 11 Dec 2019 08:31:35 +0000 巧了我就是萌 2283240 at https://www.e-learn.cn How to test Pagination feature using Protractor https://www.e-learn.cn/topic/2272484 <span>How to test Pagination feature using Protractor</span> <span><span lang="" about="/user/70" typeof="schema:Person" property="schema:name" datatype="">蹲街弑〆低调</span></span> <span>2019-12-11 14:38:30</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Please guide me how to navigate through different pages of pagination using Protractor , i followed this blog: http://seleniumhome.blogspot.com/2013/07/how-can-we-automate-pagination-using.html, unfortunately the code is not working. Here is the code from my application:</p> <pre><code>&lt;div class="vertical-align"&gt; &lt;ul class="pagination no-margins"&gt; &lt;li class="arrow unavailable" ng-class="{unavailable: currentPage === 0 || pagedRowsTotal.length == 0}"&gt; &lt;a class="ng-binding" ng-click="loadPage(0)" ng-bind-html="rsPaginatorText.first"&gt;First&lt;/a&gt; &lt;/li&gt; &lt;li class="arrow unavailable" ng-class="{unavailable: currentGroup === 1 || pagedRowsTotal.length == 0}"&gt; &lt;li class="arrow unavailable" ng-class="{unavailable: currentPage === 0 || pagedRowsTotal.length == 0}"&gt; &lt;a class="ng-binding" ng-click="loadPage(currentPage - 1)" ng-bind-html="rsPaginatorText.previous"&gt;Previous&lt;/a&gt; &lt;/li&gt; &lt;!-- ngRepeat: page in groupArray track by $index --&gt; &lt;li class="ng-scope current" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"&gt; &lt;a class="ng-binding" ng-click="loadPage(page-1)"&gt;1&lt;/a&gt; &lt;/li&gt; &lt;!-- end ngRepeat: page in groupArray track by $index --&gt; &lt;li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"&gt; &lt;a class="ng-binding" ng-click="loadPage(page-1)"&gt;2&lt;/a&gt; &lt;/li&gt; &lt;!-- end ngRepeat: page in groupArray track by $index --&gt; &lt;li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"&gt; &lt;a class="ng-binding" ng-click="loadPage(page-1)"&gt;3&lt;/a&gt; &lt;/li&gt; &lt;!-- end ngRepeat: page in groupArray track by $index --&gt; &lt;li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"&gt; &lt;a class="ng-binding" ng-click="loadPage(page-1)"&gt;4&lt;/a&gt; &lt;/li&gt; &lt;!-- end ngRepeat: page in groupArray track by $index --&gt; &lt;li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"&gt; &lt;a class="ng-binding" ng-click="loadPage(page-1)"&gt;5&lt;/a&gt; &lt;/li&gt; &lt;!-- end ngRepeat: page in groupArray track by $index --&gt; &lt;li class="arrow" ng-class="{unavailable: currentPage === pagedRowsTotal.length -1}"&gt; &lt;a class="ng-binding" ng-click="loadPage(currentPage + 1)" ng-bind-html="rsPaginatorText.next"&gt;Next&lt;/a&gt; &lt;/li&gt; &lt;li class="arrow" ng-class="{unavailable: currentGroup === groupsTotal}"&gt; &lt;li class="arrow" ng-class="{unavailable: currentPage === pagedRowsTotal.length -1}"&gt; &lt;a class="ng-binding" ng-click="loadPage(pagedRowsTotal.length - 1)" ng-bind-html="rsPaginatorText.last"&gt;Last&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>This is what i tried, but receiving an error:</p> <pre><code>this.getPaginationsize = element.all(by.repeater('page in groupArray track by $index')); summaryPage.getPaginationsize.getSize().then(function (pagination) { if (pagination &gt; 0) { for (var i = 0; i &lt; pagination; i++) { summaryPage.getPaginationsize.get(i).click(); } } else { console.log('Pagination not exists'); } }); Failed: Cannot convert object to primitive value </code></pre> <br /><h3>回答1:</h3><br /><p><code>summaryPage.getPaginationsize.getSize()</code> method will return an Object with height and width of a webelement. Instead you need to use <code>summaryPage.getPaginationsize.count()</code> to get the total number of pageSize.</p> <p>Reference:</p> <p><code>getSize()</code> : http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getSize <code>count()</code> : http://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.count</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/46183341/how-to-test-pagination-feature-using-protractor</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javascript" hreflang="zh-hans">javascript</a></div> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> <div class="field--item"><a href="/tag/protractor-net" hreflang="zh-hans">protractor-net</a></div> </div> </div> Wed, 11 Dec 2019 06:38:30 +0000 蹲街弑〆低调 2272484 at https://www.e-learn.cn Protractor - Change Browser Capabilities at RunTime https://www.e-learn.cn/topic/1909126 <span>Protractor - Change Browser Capabilities at RunTime</span> <span><span lang="" about="/user/53" typeof="schema:Person" property="schema:name" datatype="">依然范特西╮</span></span> <span>2019-12-07 08:39:14</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Is there a way to change the browser capabilities within beforeEach of the protractor suite. I need to set the Capabilities.name attribute before each spec execution.</p> <br /><h3>回答1:</h3><br /><p>To create separate instances of the desired capabilities, such as capabilities.name, you will want to try the multiCapabilities option available via Protractor. An example would look similar to what is below and reside in the conf.js file. This allows you to submit a unique name for each test session.</p> <pre><code> onPrepare: function(){ var caps = browser.getCapabilities() }, multiCapabilities: [{ browserName: 'firefox', version: '32', platform: 'OS X 10.10', name: "firefox-tests", shardTestFiles: true, maxInstances: 25 }, { browserName: 'chrome', version: '41', platform: 'Windows 7', name: "chrome-tests", shardTestFiles: true, maxInstances: 25 }], </code></pre> <p>A complete example of this can be seen here:</p> <p>https://github.com/saucelabs-sample-test-frameworks/JS-CucumberJS-Protractor3.0/blob/master/conf.js</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Here are the sauceLabs capabilities: https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options</p> <p>When you don't specify a <code>Capabilities.name</code> it looks like sauceLabs reports each test formatted as <code>browserName:specFilename</code> by default.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>You can't change the capabilities in <code>beforeEach()</code> (Jasmine hook) or <code>onPrepare()</code> (Protractor conf.js) because the browser instance has already been created and webdriver session has been started with the capabilities already sent to the Selenium server.</p> <p>Desired capabilities are set in the conf.js under <code>Capabilities</code> or <code>Multicapabilities</code>. You could set them at runtime by getting a variable before exporting in conf.js. </p> <p>One common way to do this is to set the capability using an environment variable, for example:</p> <pre><code>Capabilities: { browserName: process.env.SELENIUM_BROWSER } </code></pre> <p>You can set variables to be used in capabilities in <code>beforeLaunch()</code> but this executes one time only, before any specs are read. </p> <p>There is an excellent summary of the Protractor / Jasmine hooks here:<br /> http://timothymartin.azurewebsites.net/protractor-before-and-afters/</p> <p>I have not yet identified a way (without modifying Protractor source) to change capabilities dynamically on a per-spec or per-suite basis.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/34823248/protractor-change-browser-capabilities-at-runtime</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Sat, 07 Dec 2019 00:39:14 +0000 依然范特西╮ 1909126 at https://www.e-learn.cn '$' selector in Protractor https://www.e-learn.cn/topic/1898698 <span>&#039;$&#039; selector in Protractor</span> <span><span lang="" about="/user/15" typeof="schema:Person" property="schema:name" datatype="">假装没事ソ</span></span> <span>2019-12-07 05:40:59</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have seen in many examples like this <code>$('.selector')</code> and I am also using this. So what this <strong>$</strong> variable does. This is what I got from the protractor docs.</p> <blockquote> <p>Calls to $ may be chained to find elements within a parent.</p> </blockquote> <p>There is no example in docs which use <code>$</code> alone. We are using <code>$</code> to chain with <code>element</code> selector.</p> <p>Also <code>$('.selector')</code> itself is an element, when we does this <code>element($('.selector'))</code>, it is an error.</p> <p>So how to use this <code>$</code> selector in protractor. Does it have all the features of <code>JQuery $</code>. I tried <code>$('.selector').children</code> which says <code>children</code> is not a function.</p> <p>Any help is greatly appreciated.</p> <p>Thanks!</p> <br /><h3>回答1:</h3><br /><p>That <em>looks</em> like jQuery syntax but it is not, it's part of Protractor. That's why <code>.children</code> is throwing an error because we're not actually using jQuery. <code>$</code> is a shorthanded version of <code>element(by.css())</code> i.e. </p> <p><code>$('my-css');</code> is the exact same as <code>element(by.css('my-css'));</code></p> <p>They also have <code>$$</code> which is the same as <code>element.all(by.css())</code> </p> <p>Despite the lack of documentation, it does <strong>not</strong> <em>have to be used</em> for chaining to find child elements. i.e. using Julie's protractor demo (I modified the example):</p> <pre><code>describe('Protractor Demo App', function() { it('read the header', function() { browser.get('http://juliemr.github.io/protractor-demo/'); $('h3').getText().then(function (val) { console.log(val); }); }); }); </code></pre> <p>That prints out the title of the h3 element that I located. The <code>$</code> and <code>$$</code> are simply a shorthand for css selectors.</p> <p>Source: here for $$, here for $, and here for more</p> <p>Also this is a nice document I found (though it does not mention the use of <code>$$</code> : http://luxiyalu.com/protractor-locators-selectors/</p> <br /><br /><br /><h3>回答2:</h3><br /><p>We made updates to the Protractor's API for $. Also, there are several places in Protractor's specs that use chained $. See below (from spec/async_spec.js):</p> <pre><code> it('should work with synchronous actions', function() { var increment = $('#increment'); increment.$('.action').click(); expect(increment.$('.val').getText()).toEqual('1'); }); </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>This is the correct API doc for $:</p> <p>"Shortcut for querying the document directly with css. <code>element(by.css('.abc'))</code> is equivalent to <code>$('.abc')</code>"</p> <p>http://www.protractortest.org/#/api?view=build$</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/36791397/selector-in-protractor</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/angularjs" hreflang="zh-hans">angularjs</a></div> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/angularjs-e2e" hreflang="zh-hans">angularjs-e2e</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Fri, 06 Dec 2019 21:40:59 +0000 假装没事ソ 1898698 at https://www.e-learn.cn '$' selector in Protractor https://www.e-learn.cn/topic/1697913 <span>&#039;$&#039; selector in Protractor</span> <span><span lang="" about="/user/188" typeof="schema:Person" property="schema:name" datatype="">旧时模样</span></span> <span>2019-12-05 10:33:17</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><div class="alert alert-danger" role="alert"> <p>I have seen in many examples like this <code>$('.selector')</code> and I am also using this. So what this <strong>$</strong> variable does. This is what I got from the protractor <a href="https://angular.github.io/protractor/#/api?view=ElementFinder.prototype.$" rel="nofollow">docs</a>.</p> <blockquote> <p>Calls to $ may be chained to find elements within a parent.</p> </blockquote> <p>There is no example in docs which use <code>$</code> alone. We are using <code>$</code> to chain with <code>element</code> selector.</p> <p>Also <code>$('.selector')</code> itself is an element, when we does this <code>element($('.selector'))</code>, it is an error.</p> <p>So how to use this <code>$</code> selector in protractor. Does it have all the features of <code>JQuery $</code>. I tried <code>$('.selector').children</code> which says <code>children</code> is not a function.</p> <p>Any help is greatly appreciated.</p> <p>Thanks!</p> </div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>That <em>looks</em> like jQuery syntax but it is not, it's part of Protractor. That's why <code>.children</code> is throwing an error because we're not actually using jQuery. <code>$</code> is a shorthanded version of <code>element(by.css())</code> i.e. </p> <p><code>$('my-css');</code> is the exact same as <code>element(by.css('my-css'));</code></p> <p>They also have <code>$$</code> which is the same as <code>element.all(by.css())</code> </p> <p>Despite the lack of documentation, it does <strong>not</strong> <em>have to be used</em> for chaining to find child elements. i.e. using Julie's protractor demo (I modified the example):</p> <pre><code>describe('Protractor Demo App', function() { it('read the header', function() { browser.get('http://juliemr.github.io/protractor-demo/'); $('h3').getText().then(function (val) { console.log(val); }); }); }); </code></pre> <p>That prints out the title of the h3 element that I located. The <code>$</code> and <code>$$</code> are simply a shorthand for css selectors.</p> <p>Source: <a href="https://angular.github.io/protractor/#/api?view=ElementFinder.prototype.$$" rel="nofollow">here for $$</a>, <a href="https://angular.github.io/protractor/#/api?view=ElementFinder.prototype.$" rel="nofollow">here for $</a>, and <a href="https://github.com/angular/protractor/blob/master/docs/locators.md" rel="nofollow">here for more</a></p> <p>Also this is a nice document I found (though it does not mention the use of <code>$$</code> : <a href="http://luxiyalu.com/protractor-locators-selectors/" rel="nofollow">http://luxiyalu.com/protractor-locators-selectors/</a></p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>We made updates to the Protractor's API for <a href="http://www.protractortest.org/#/api?view=ElementFinder.prototype.$" rel="nofollow">$</a>. Also, there are several places in Protractor's specs that use chained $. See below (from <a href="https://github.com/angular/protractor/blob/master/spec/ng2/async_spec.js#L8" rel="nofollow">spec/async_spec.js</a>):</p> <pre><code> it('should work with synchronous actions', function() { var increment = $('#increment'); increment.$('.action').click(); expect(increment.$('.val').getText()).toEqual('1'); }); </code></pre> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>This is the correct API doc for $:</p> <p>"Shortcut for querying the document directly with css. <code>element(by.css('.abc'))</code> is equivalent to <code>$('.abc')</code>"</p> <p><a href="http://www.protractortest.org/#/api?view=build" rel="nofollow">http://www.protractortest.org/#/api?view=build</a>$</p> </div></div><div class="alert alert-warning" role="alert"><p>来源:<code>https://stackoverflow.com/questions/36791397/selector-in-protractor</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/angularjs" hreflang="zh-hans">angularjs</a></div> <div class="field--item"><a href="/tag/protractor" hreflang="zh-hans">protractor</a></div> <div class="field--item"><a href="/tag/angularjs-e2e" hreflang="zh-hans">angularjs-e2e</a></div> <div class="field--item"><a href="/tag/gulp-protractor" hreflang="zh-hans">gulp-protractor</a></div> </div> </div> Thu, 05 Dec 2019 02:33:17 +0000 旧时模样 1697913 at https://www.e-learn.cn