Protractor: screen size

I use this property to define the screen width and height:

var width = 1280; var height = 600; browser.driver.manage().window().setSize(width, height); 

In the onPrepare () method, but this code is functional for some tests, and not for all of them. Why is this? I do not override the screen size in my tests.

Hello,

Johnny

Edit: My version of Node is 0.10.33 using Protactor 2.5.1.

Protocarter conf:

 // Fichier de configuration pour Angular exports.config = { sauceUser: "", sauceKey: "", capabilities: { 'browserName': 'chrome', 'name': 'Protractor Circle CI' }, specs: ["src/Bg/*Bundle/Tests/Angular/*Test.js"], exclude: ['src/Bg/*Bundle/Tests/Angular/*AuthTest.js', 'src/Bg/*Bundle/Tests/Angular/*RapideTest.js'], baseUrl: "http://bluegrey.circle.dev:8080/app_ci.php", onPrepare: function() { browser.driver.get('http://bluegrey.circle.dev:8080/app_ci.php/fr_FR/login'); browser.driver.findElement(by.id('username')).sendKeys(' user@evolunium.fr '); browser.driver.findElement(by.id('password')).sendKeys('userpass'); browser.driver.findElement(by.id('_submit')).click(); return browser.driver.wait(function() { return browser.driver.getCurrentUrl().then(function(url) { return /dashboard/.test(url); }); }, 600000); var width = 1280; var height = 600; browser.driver.manage().window().setSize(width, height); }, jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000 } }; 

An example of a test that works:

 describe("Carrière > Centre d'interêt", function () { describe("Tests d'ajout et de suppression d'un centre d'interêt", function () { beforeEach(function () { // on compte le nombre d'element elements = element.all(by.css('.bloc__defaut')); elements.count().then(function (nbElementP) { nbElement = nbElementP; }); }, 60000); it('GET /app_ci.php/fr_FR/dashboard/career/interest', function () { browser.get('/app_ci.php/fr_FR/dashboard/career/interest'); }, 60000); it("Ajout du centre d'interêt", function () { // On clique sur ajouter element(by.css('.btn-add-js')).click(); // On remplit le formulaire browser.findElement(by.id('CentreInteret_intitule')).sendKeys('CentreInteret_intitule'); element(by.css('.u-btn-inverse')).click(); // on re-compte le nombre d'element expect(elements.count()).toEqual(nbElement+1); }, 60000); it("Suppression d'un centre d'interêt", function () { // On regarde si toutes les fenetres de suppressions sont cachés au début expect(element(by.css('.bloc__suppression')).isDisplayed()).toBeFalsy(); // On clique sur supprimer element(by.css('.u-btn-alert')).click(); // On regarde si la fenetre de confirmation de suppression est présente expect(element(by.css('.bloc__suppression')).isDisplayed()).toBeTruthy(); // On clique sur supprimer element(by.css('.btn-supprimer-js')).click(); // On regarde si l'element est caché expect(element(by.css('.bloc__suppression')).isDisplayed()).toBeFalsy(); }, 60000); }); }); 

And a test that fails:

 describe('Carrière > Experience Pro', function () { describe("Tests d'ajout et de suppression d'une experience pro", function () { beforeEach(function () { // on compte le nombre d'element elements = element.all(by.css('.bloc__defaut')); elements.count().then(function (nbElementP) { nbElement = nbElementP; }); }, 60000); it('GET /app_ci.php/fr_FR/dashboard/career/professionalexperiences', function () { browser.get('/app_ci.php/fr_FR/dashboard/career/professionalexperiences'); }, 60000); it('Vérification si lors du clique de la checkbox le champs date se désactive', function () { // On clique sur ajouter element(by.css('.btn-add-js')).click(); // On regarde si par defaut les champs ne sont pas désactivés (= active) expect(element(by.id('ExperiencePro_dateFin_day')).getAttribute('disabled')).toBeFalsy(); expect(element(by.id('ExperiencePro_dateFin_month')).getAttribute('disabled')).toBeFalsy(); expect(element(by.id('ExperiencePro_dateFin_year')).getAttribute('disabled')).toBeFalsy(); // On clique element(by.id('ExperiencePro_enPosteajout')).click(); // On regarde si les champs sont desactivés expect(element(by.id('ExperiencePro_dateFin_day')).getAttribute('disabled')).toBeTruthy(); expect(element(by.id('ExperiencePro_dateFin_month')).getAttribute('disabled')).toBeTruthy(); expect(element(by.id('ExperiencePro_dateFin_year')).getAttribute('disabled')).toBeTruthy(); // On regarde s'ils se redésactive element(by.id('ExperiencePro_enPosteajout')).click(); expect(element(by.id('ExperiencePro_dateFin_day')).getAttribute('disabled')).toBeFalsy(); expect(element(by.id('ExperiencePro_dateFin_month')).getAttribute('disabled')).toBeFalsy(); expect(element(by.id('ExperiencePro_dateFin_year')).getAttribute('disabled')).toBeFalsy(); }, 120000); it("Réglage du format de date", function () { // Format mois/année element(by.id('reglageDate-js')).click(); element(by.id('ExperiencePro_formatDate_1')).click(); expect(element(by.id('ExperiencePro_dateDebut_day')).isDisplayed()).toBeFalsy(); expect(element(by.id('ExperiencePro_dateDebut_month')).isDisplayed()).toBeTruthy(); expect(element(by.id('ExperiencePro_dateDebut_year')).isDisplayed()).toBeTruthy(); // Format année element(by.id('reglageDate-js')).click(); element(by.id('ExperiencePro_formatDate_2')).click(); expect(element(by.id('ExperiencePro_dateDebut_day')).isDisplayed()).toBeFalsy(); expect(element(by.id('ExperiencePro_dateDebut_month')).isDisplayed()).toBeFalsy(); expect(element(by.id('ExperiencePro_dateDebut_year')).isDisplayed()).toBeTruthy(); // Format année element(by.id('reglageDate-js')).click(); element(by.id('ExperiencePro_formatDate_0')).click(); expect(element(by.id('ExperiencePro_dateDebut_day')).isDisplayed()).toBeTruthy(); expect(element(by.id('ExperiencePro_dateDebut_month')).isDisplayed()).toBeTruthy(); expect(element(by.id('ExperiencePro_dateDebut_year')).isDisplayed()).toBeTruthy(); }, 60000); it("Ajout de l'experience", function () { // On remplit le formulaire browser.findElement(protractor.By.css('#ExperiencePro_dateDebut_day option[value="1"]')).click(); browser.findElement(protractor.By.css('#ExperiencePro_dateDebut_month option[value="12"]')).click(); browser.findElement(protractor.By.css('#ExperiencePro_dateDebut_year option[value="2000"]')).click(); element(by.id('ExperiencePro_enPosteajout')).click(); element(by.id('reglageDate-js')).click(); element(by.id('ExperiencePro_formatDate_0')).click(); browser.findElement(by.id('ExperiencePro_poste-ajout')).sendKeys('ExperiencePro_poste'); browser.findElement(by.id('ExperiencePro_entreprise')).sendKeys('ExperiencePro_entreprise'); browser.findElement(by.id('ExperiencePro_ville')).sendKeys('ExperiencePro_ville'); element(by.css('.u-btn-inverse')).click(); // on re-compte le nombre d'element expect(elements.count()).toEqual(nbElement+1); }, 60000); it("Suppression d'une experience", function () { expect(element(by.css('.bloc__suppression')).isDisplayed()).toBeFalsy(); // On clique sur supprimer element(by.css('.u-btn-alert')).click(); // On regarde si la fenetre de confirmation de suppression est présente expect(element(by.css('.bloc__suppression')).isDisplayed()).toBeTruthy(); // On clique sur supprimer element(by.css('.btn-supprimer-js')).click(); // On regarde si la fenetre affirmant la suppression est apparue expect(element(by.css('.bloc__suppression')).isDisplayed()).toBeFalsy(); }, 60000); }); }); 

Edit 2: This is a viewport issue, not a screen size issue. I tried Chrome, Firefox, Safari with SauceLabs, and this is the same problem.

+5
source share
3 answers

In fact, you are returning from the onPrepare() function before calling setSize() :

 onPrepare: function() { browser.driver.get('http://bluegrey.circle.dev:8080/app_ci.php/fr_FR/login'); browser.driver.findElement(by.id('username')).sendKeys(' user@evolunium.fr '); browser.driver.findElement(by.id('password')).sendKeys('userpass'); browser.driver.findElement(by.id('_submit')).click(); // HERE!! return browser.driver.wait(function() { return browser.driver.getCurrentUrl().then(function(url) { return /dashboard/.test(url); }); }, 600000); var width = 1280; var height = 600; browser.driver.manage().window().setSize(width, height); }, 

You must either remove the "refund" or set the size of the browser window in front of it.

You can also return the promise returned by setSize() - in this case, the protractor will wait for the promise to be resolved before the tests run:

 return browser.driver.manage().window().setSize(width, height); 

They now even have this "function" documented :

onPrepare may optionally return a promise that Protractor will wait to continue execution. This can be used if the preparation includes any asynchronous calls, for example. interacting with the browser. Otherwise, the Protractor cannot guarantee the execution order and can start the tests before completing the preparation.

+2
source

Can you try to control the set size using the Chrome settings? You can delete all other ads for a given size.

'browserName': 'chrome', 'chromeOptions' : { args: ['--window-size=Width,Height'] },

+1
source

This is normal with the Mac OS X platform:

 capabilities: { 'browserName': 'chrome', 'platform': 'OS X 10.11', 'name': 'Protractor Circle CI' }, 

But this is not a perfect solution, I am waiting for your notice

0
source

Source: https://habr.com/ru/post/1235812/


All Articles