使用Node.js的硒页面对象异步模式 [英] Page Object Pattern asynchronous using node.js selenium

查看:131
本文介绍了使用Node.js的硒页面对象异步模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很难试图调整使用node.js中对异步我使用硒的webdriver和页面对象图形时,遇到了一个问题。我觉得有些事情必须做自动化测试或因为你在插入数据之前单击一个按钮你的测试失败时要同步。我有类似这样的问题。我想补充的员工,然后搜索员工,但员工搜索被执行之前添加的雇员。

I am having a hard time trying to adjust to asynchronous using node.js. I ran into an issue when using selenium-webdriver and the page object pattern. I feel like somethings have to be synchronous when doing automation testing or your tests will fail because you clicked a button before inserting data. I am having an issue similar to this. I want to add an employee and then search for the employee, but the search for employee is performing before add employee.

var employee = new Employee('grimlek', 'Charles', 'Sexton', 'TitleTitle',
    'Upper Management', 'Company Admin', 'Contractor', '-7', 'Remote',
    '05212016', '3369407787', '3368791234', 'charles@example.com',
    'charles.sexton', 'Skype', 'abcdefgh');

driver.get('https://website.com/login')
.then(function() {
     //This behaves as intended
     loginPage.login('company.admin', 'password') })
.then(function() {
      //Add employee
      employeePage.addEmployee(employee) })
.then(function() {
     //Search for employee after employee is added 
     employeePage.searchEmployee(employee)});

EmployeePage对象

EmployeePage Object

var EmployeePage = function (driver) {

this.addEmployee = function (employee) {
    driver.findElement(webdriver.By.css('button[class=\'btn btn-default\']')).then(function (element) {
        //
        //Search employee function is done before the line below this
        //
        element.click();
    }).then(function () {
        setTimeout(function () {
            driver.findElement(webdriver.By.id('employee_username')).then(function (element) {
                element.sendKeys(employee.username);
            });

            driver.findElement(webdriver.By.id('employee_first_name')).then(function (element) {
                element.sendKeys(employee.firstName);
            });

            driver.findElement(webdriver.By.id('employee_last_name')).then(function (element) {
                element.sendKeys(employee.lastName);
            });

            driver.findElement(webdriver.By.id('employee_title_id')).then(function (element) {
                element.sendKeys(employee.title);
            });

            driver.findElement(webdriver.By.id('employee_role')).then(function (element) {
                element.sendKeys(employee.role);
            });
        }, 5000);
    });
//
//
//Search employee should occur when the thread leaves the function
//
};

this.searchEmployee = function (employee) {
    driver.findElement(webdriver.By.css('input[class=\'form-control ng-pristine ng-valid\']')).then(function(element) {
       element.sendKeys(employee.firstName + ' ' + employee.lastName); 
    });
};

};

module.exports = EmployeePage;

module.exports = EmployeePage;

我知道,无论searchEmployee和addEmployee函数不返回一个承诺,我想他们链条的。然后作用。我不相信这是八九不离十我的问题,但我需要它应该怎么做帮助,而不是怎么可以操纵它。我应该使用回调?我已经在这个问题上的工作现在正在进行四小时我曾尝试使用Google,做各种主题的研究。如果我没有提供足够的code,请让我知道,我会提供一个简化的可运行的例子。

I know that both searchEmployee and addEmployee functions don't return a promise and I am trying to chain them with the .then function. I do believe this is sorta my problem but I need help with how it should be done and not how I can rig it. Should I use callbacks? I have worked on this problem for going on four hours now and I have tried googling and doing research on various topics. If I didn't provide enough code please let me know and I will provide a simplified runnable example.

推荐答案

一个值得称赞的目标是让每一个独立的测试。如果进行了更改应用程序(E,G,bug修复)只影响测试(S)提出需要执行。此外,它使移动到电网可以想象的。

A laudable goal is to make each test independent. If a change is made to the application (e,g, bug fix) only the impacted test(s) need to be executed. Also, it makes moving to grid thinkable.

但是,这是在实践中难以实现的。您的测试必须包括满足$ P所需要的所有测试$ prequisites。

But this is difficult to achieve in practice. Your test has to include all tests needed to satisfy the prerequisites.

黄瓜具有功能文件,其中包括场景每个场景是一个考验。场景在它们在特征文件中列出的顺序执行。因此,要整理东西的一种方法是包括所有的prerequisite方案之前,请在要素文件测试,您可以添加的标签(S)要素语句之前,这样当你执行该代码整个特征文件运行。也许是第一个场景重置(的子集)数据库中一个已知的状态。

Cucumber has feature files that include scenarios Each scenario is a test. Scenarios are executed in the order they are listed in the feature file. So one way to organize things is to include all the prerequisite scenarios before your test in a feature file, You can add tag(s) before the Feature statement so that when you execute that tag the entire feature file runs. Perhaps the first scenario resets (a subset of) the database to a know state.

的技巧是在多台机器上并行运行的特点。如果指向那些多个客户到同一服务器提防该特征不应该创建或更新重叠实体时写入到由服务器数据库可能碰撞。例如。 你是什么意思'嗵'已存在的用户?每个要素需要创建一个唯一的用户名。

The trick would be to run features in parallel on multiple machines. If you point those multiple clients to the same server beware that the features should not create or update overlapping entities that could collide when written to the database by the server. E.g. "What do you mean that user 'tom' already exists?" Each feature needs to create a unique user name.

这篇关于使用Node.js的硒页面对象异步模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆