zoukankan      html  css  js  c++  java
  • CodeceptJS学习笔记-入门02

     
     
     

     

    1.打开页面

    打开页面,使用I.amOnPage(),如果URL不是以http://或者https://开始的,就则将其视为相对URL,并将其附加到配置文件 codecept.conf.js 中设置的URL后面

    // When "https://url" is url in config
    I.amOnPage('/'); // -> opens https://url/
    I.amOnPage('/user/login'); // -> opens https://url/user/login

    2.点击页面元素

    单击定位器提供的链接或按钮。如果给出了模糊定位符,则会在页面上搜索与定位符字符串匹配的按钮,链接或图像。对于按钮,将搜索“值”属性,“名称”属性和内部文本。对于链接,将搜索链接文本。对于图像,将搜索“ alt”属性和任何父链接的内部文本。

    第二个参数是上下文(CSS或XPath定位器),以缩小搜索范围。

    //使用Xpath定位
    I.click('/html/body/div/div/div[2]/div/div[2]/div[2]/div[2]/div/div/ul/li[1]/div/div[2]/div/a')
    //使用css定位
    I.click('button, html [type="button"]')
    I.click({css:'button, html [type="button"], [type="reset"], [type="submit"]'})
    //搜索链接文本
    I.click('CRM')
    //参考CSS/Xpath,缩小搜索文本的范围
    I.click('CRM','.ant-list-item-meta-description a')
     
    //doubleClick与click用法差不多
    I.doubleClick('Button');

    3.输入框输入

    //使用css定位
    I.fillField('.ant-input-affix-wrapper .ant-input:not(:first-child)', '13500000000');
    //使用Xpath定位
    I.fillField('//*[@id="root"]/div/div[2]/div/div/div/div/form/div[1]/div/div/span/span/input')
    // or by strict locator
    I.fillField({css: '.ant-input-affix-wrapper .ant-input:not(:first-child)'}, '13500000000');

    4.下拉框选项

    //发现这个只支持select,咱们triones上面都是ul/li,用的话会报错Error | Error: Element is not <select>
    I.selectOption('Choose Plan', 'Monthly'); // select by label
    I.selectOption('subscription', 'Monthly'); // match option by text
    I.selectOption('subscription', '0'); // or by value
    I.selectOption('//form/select[@name=account]','Premium');
    I.selectOption('form select[name=account]', 'Premium');
    I.selectOption({css: 'form select[name=account]'}, 'Premium');


    4.React定位

    { react: 'MyComponent' }
    { react: 'Button', props: { title: 'Click Me' }}
    { react: 'Button', state: { some: 'state' }}
    { react: 'Input', state: 'valid'}
     
    //react:标签名,props是该元素的属性
    I.click({react: 'button', props: { type: 'button',class: 'ant-btn ant-btn-primary',style :' 100%; height: 36px;' }})

    5.断言

    5.1 see

    I.see('CRM')
    I.see('CRM','.ant-list-item-meta-description a')
    I.see('CRM',{css: '.ant-list-item-meta-description a'})

    5.2 seeAttributesOnElements

    I.seeAttributesOnElements('.antd-pro-views-tenant-index-listTitle button',{type:"button"})

    5.3 seeCookie

    I.seeCookie('_access_token')

    6.等待

    //等待2s
    //等待可点击的元素出现,默认等待1s
    //等待文本出现
    I.waitForText('CRM', 5, '.ant-list-item-meta-description a');

    7.按键

    //退格键
    I.pressKey('Backspace');
    //组合键
    I.pressKey(['Control', 'Z']);

    支持的特殊键名

    Some of the supported key names are:
    'AltLeft' or 'Alt'
    'AltRight'
    'ArrowDown'
    'ArrowLeft'
    'ArrowRight'
    'ArrowUp'
    'Backspace'
    'Clear'
    'ControlLeft' or 'Control'
    'ControlRight'
    'Command'
    'CommandOrControl'
    'Delete'
    'End'
    'Enter'
    'Escape'
    'F1' to 'F12'
    'Home'
    'Insert'
    'MetaLeft' or 'Meta'
    'MetaRight'
    'Numpad0' to 'Numpad9'
    'NumpadAdd'
    'NumpadDecimal'
    'NumpadDivide'
    'NumpadMultiply'
    'NumpadSubtract'
    'PageDown'
    'PageUp'
    'Pause'
    'Return'
    'ShiftLeft' or 'Shift'
    'ShiftRight'
    'Space'
    'Tab'
  • 相关阅读:
    SQL数据库inner join ,join,left join,full join(转)
    CSRF攻击(转)
    BZOJ1853: [Scoi2010]幸运数字
    BZOJ1935: [Shoi2007]Tree 园丁的烦恼
    BZOJ3289Mato的文件管理
    树状数组
    莫队算法
    如何在win上用Linux编c++
    Hash的应用
    关于指数循环节的证明
  • 原文地址:https://www.cnblogs.com/7047-zfy/p/13231386.html
Copyright © 2011-2022 走看看