使用NodeJS进行自动化的远程浏览器Selenium测试

时间:2019-07-07 19:12:03

标签: node.js selenium lambda automated-tests

我想用selenium webdriver和NodeJs测试html表单(如果它可以在所有浏览器中提交)。为此,我使用Lambda Test。我有两个问题

第一个复选框和单选按钮单击脚本不起作用。我在出现错误后继续提示

  

UnhandledPromiseRejectionWarning:WebDriverError:未知错误:   元素在点(172,643)不可单击。其他要素   将会获得点击:(会话信息:chrome = 67.0.3396.62)(驱动程序   信息:chromedriver = 2.38.552522   (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),平台= Windows NT   10.0.14393 x86_64)       在Object.checkLegacyResponse(c:+++ \ newTest \ node_modules \ selenium-webdriver \ lib \ error.js:585:15)       在parseHttpResponse(c:+++ \ selenium-webdriver \ lib \ http.js:551:13)       在Executor.execute(c:+++ \ newTest \ node_modules \ selenium-webdriver \ lib \ http.js:486:26)       在process._tickCallback(internal / process / next_tick.js:68:7)

这是单选按钮

<div class="col-3"> 
<input  class="field"  id="_applicationgenderId_1" name="_applicationgenderId"   title="Female" type="radio" value="2"  required="true"  />
  Female    </div>

这是复选框,

<label for="data_policy" id="lbl_data_policy" style="border-color: #b50303">
                            <input type="checkbox" name="checkbox" id="chk_data_policy" value="value">
I accept by clicking .....</label>* 

另一件事是不上传pdf文件就无法提交表格,因为我是通过远程计算机上的LambdaTest进行此测试的,我无法从测试目录发送pdf文件,是否可以从链接发送虚拟的pdf文件与webdriver并提交表格?前https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf

表单的html输入元素为:chk_data_policy“

这是我的js文件

/*
    LambdaTest selenium automation sample example
    Configuration
    ----------
    username: Username can be found at automation dashboard
    accessKey:  AccessKey can be generated from automation dashboard or profile section

    Result
    -------
    Execute NodeJS Automation Tests on LambdaTest Distributed Selenium Grid
*/
const webdriver = require('selenium-webdriver');

/*
    Setup remote driver
    Params
    ----------
    platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7,  macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks)
    browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge, Safari)
    version :  Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/
*/

// username: Username can be found at automation dashboard
const USERNAME = 'xxxxx';

// AccessKey:  AccessKey can be generated from automation dashboard or profile section
const KEY = 'xxxx';

// gridUrl: gridUrl can be found at automation dashboard
const GRID_HOST = 'hub.lambdatest.com/wd/hub';

function fillandsubmitform() {
    // Setup Input capabilities
    const capabilities = {
        platform: 'windows 10',
        browserName: 'chrome',
        version: '67.0',
        resolution: '1280x800',
        network: true,
        visual: true,
        console: true,
        video: true,
        name: 'Test 22', // name of the test
        build: 'NodeJS build' // name of the build
    }

    // URL: https://{username}:{accessKey}@hub.lambdatest.com/wd/hub
    const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;

    // setup and build selenium driver object
    const driver = new webdriver.Builder()
        .usingServer(gridUrl)
        .withCapabilities(capabilities)
        .build();



    // navigate to a url, search for a text and get title of page
    driver.get('https://www.....').then(function() {   
        setTimeout(function () {  
        driver.findElement(webdriver.By.id('_application_availabilityDate')).sendKeys('07.07.2019');

        driver.findElement(webdriver.By.id('_application_genderId_1')).click();
        driver.findElement(webdriver.By.id('_application_firstName')).sendKeys('NodeJS');
        driver.findElement(webdriver.By.id('_application_lastname')).sendKeys('Test');
        driver.findElement(webdriver.By.id('_application_streetAndNumber')).sendKeys('on Lambda Selenium Grid');
        driver.findElement(webdriver.By.id('_application_zip')).sendKeys('69115');
        driver.findElement(webdriver.By.id('_application_city')).sendKeys('London');        
        driver.findElement(webdriver.By.id('_application_selectedLanguage')).sendKeys('Deutschland');
        driver.findElement(webdriver.By.id('_application_email')).sendKeys('test@gmael.com');
        driver.findElement(webdriver.By.id('_application_phone')).sendKeys('017625856884');
        driver.findElement(webdriver.By.id('_application_birthDate')).sendKeys('07.07.2019');
         driver.findElement(webdriver.By.id('chk_data_policy"')).click();
        driver.findElement(webdriver.By.id('submitFormButton')).click();
        },5000);


        function check_page(){
            var promise = driver.getTitle().then(function(title){
                if(title==='Thank you for submission'){
                    console.log('Form has been send');
                    return true;
                }
                else{
                    console.log('Failed --' + title);
                }
            });
            return promise;
        }


    });
}
fillandsubmitform();

0 个答案:

没有答案