我使用此属性来定义宽度和高度的屏幕:
var width = 1280;
var height = 600;
browser.driver.manage().window().setSize(width,height);
在onPrepare()方法中,但是这个代码对于某些测试是有用的,而不是对所有测试都有用.这是为什么?我没有在测试中重新定义屏幕的大小.
问候,
约翰尼
编辑:
使用Protactor 2.5.1,我的Node版本为0.10.33.
量角器的配置:
// 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
}
};
有效的测试示例:
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);
});
});
并且测试失败:
describe('Carrière > Experience Pro',function () {
describe("Tests d'ajout et de suppression d'une experience pro",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);
});
});
编辑2:
它可能是视口的问题,而不是屏幕尺寸的问题.我试过使用SauceLabs的Chrome,Firefox,Safari,这也是同样的问题.
最佳答案
实际上,即使在调用setSize()之前,您仍然从onPrepare()函数返回:
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);
},
您应该删除“返回”,或在其之前设置浏览器窗口大小.
您还可以返回setSize()返回的承诺 – 在这种情况下,量角器会在执行测试之前等待承诺得到解决:
return browser.driver.manage().window().setSize(width,height);
他们现在甚至拥有这个“功能”documented:
onPrepare
can optionally return a promise,which Protractor will wait for before continuing execution. This can be used if the
preparation involves any asynchronous calls,e.g. interacting with the
browser. Otherwise Protractor cannot guarantee order of execution and
may start the tests before preparation finishes.