【发布时间】:2018-02-08 14:35:44
【问题描述】:
我正在学习使用 Protractor 作为自动化网站测试的工具。我正在测试页面:https://www.upwork.com/。我使用的是谷歌 Chrome 浏览器。
问题是:
1.当量角器转到:https://www.upwork.com时,它可以工作。
2.当我手动(将此网址粘贴到浏览器)转到https://www.upwork.com/hire/angularjs-developers/时,它可以工作。
3.当量角器首先转到:https://www.upwork.com/,然后在浏览 TOP SKILLS 部分单击文本“AngularJS Developers”时,它可以工作。
4.但是当protractor试图直接去https://www.upwork.com/hire/angularjs-developers/时,通过browser.get(url)的方法,它不起作用,出现这个消息:
“访问此网页被拒绝。
请确保您的浏览器支持 JavaScript 和 cookie,并且您没有阻止它们加载。要详细了解 Upwork 如何使用 Cookie,请查看我们的 Cookie 政策。”
我尝试使测试独立,因此我创建了 2 个测试类。一个测试 HomePage,第二个测试 HirePage。 这就是为什么我尝试直接在https://www.upwork.com/hire/angularjs-developers/ 上打开浏览器以便能够测试该站点,而无需打开主页并单击“AngularJS 开发人员”文本以转到 HirePage。
因为当第一个测试不通过时,第二个也不会通过,这意味着它们是依赖的。那我应该怎么做以及如何解决这个问题?
这是 HirePage 测试的代码:
const HirePage = require("../Pages/HirePage");
let hirePage;
const url = browser.params.HirePageURL;
const expectedHeadLine = browser.params.expectedHeadlineOnHirePage;
beforeAll(function () {
browser.get(url);
hirePage = new HirePage();
});
describe("Checks Hire page and filering the freelancers after filling
the data", function () {
it("Should have correct HeadLine", function () {
expect(hirePage.headlineUpperText()).toContain(expectedHeadLine);
});
});
这是我的 cong.js 文件:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
browserName: 'chrome',
// 'chromeOptions': { 'args': ['incognito'] }
},
onPrepare: function() {
browser.driver.manage().window().maximize();
browser.manage().timeouts().implicitlyWait(5000);
browser.manage().timeouts().pageLoadTimeout(10000);
},
specs: [
// './*/HomePageTest-spec.js',
'./*/HirePageTest-spec.js',
],
params: require('./Configuration/configurationFile')
};
我通过在控制台输入“protractor conf.js”来运行测试。
【问题讨论】:
-
您在 Firefox 上运行时遇到过同样的问题吗?一般来说,我们不需要任何与启用 javascript/cookies 相关的设置。尝试升级chromedriver。更新问题告诉我们您使用的是哪个 Chrome 和 Chromedriver?
-
我使用 Google Chrome 64.0.3282.140 和最新的 chromedriver。在 Firefox 上运行良好。
-
我使用 chromdriver 2.35 在 Chrome 63 和 64 上运行您的网址。两者都工作正常。请说明您使用的 chromedriver 的版本。
-
你能告诉我如何检查我的 chromedriver 的确切版本吗?
-
我忘了给你打电话,对不起。 @yong
标签: javascript angularjs testing protractor automated-tests