zoukankan      html  css  js  c++  java
  • CodeceptJS学习笔记-高级用法04-设置自动登录

     

    1.在codecept.conf.js中的plugins下加入以下代码

    autoLogin: {
    
          enabled: true,
          saveToFile: true,
          inject: 'loginAs', // use `loginAs` instead of login
          users: {
            user: {
              login: async (I) => {
                 I.amOnPage('/user/login');
                 I.wait({css:'.ant-input-affix-wrapper .ant-input:not(:first-child)'})
                 I.fillField({css:'.ant-input-affix-wrapper .ant-input:not(:first-child)'},'13520661550');
                 I.fillField({css:'.ant-input-affix-wrapper .ant-input:not(:last-child)'},'@12345678');
                 I.say("111");
                 // 点击登录按钮
                 I.click('button, html [type="button"]');
                 I.wait(5)
                 I.see('开通SaaS')
                 I.seeAttributesOnElements('.antd-pro-views-tenant-index-listTitle button',{type:"button"})
                 I.click('Automated_Testing')
                 I.wait(5)
              },
              check: (I) => {
                I.amOnPage('/dashboard')
              },
            },
            admin: {
              login: async (I) => {
                 I.amOnPage('/user/login');
                 I.say("222");
                 I.wait(10)
                 I.fillField({css:'.ant-input-affix-wrapper .ant-input:not(:first-child)'},'17610772739');
                 I.fillField({css:'.ant-input-affix-wrapper .ant-input:not(:last-child)'},'@12345678');
                 I.say("222");
                 // 点击登录按钮
                 I.click('button, html [type="button"]');
                 I.wait(5)
                 I.see('开通SaaS')
                 I.seeAttributesOnElements('.antd-pro-views-tenant-index-listTitle button',{type:"button"})
                 I.click('Automated_Testing')
                 I.wait(5)
              },
              check: (I) => {
                I.amOnPage('/dashboard')
              },
            },
          }
        }

    调用

    Scenario('log me in', async(I, loginAs) => {
      await loginAs('user');
      I.amOnPage('/dashboard')
      I.wait(10)
      I.see('Dashboard')
    });

    运行结果

    CodeceptJS v2.6.5
    Using test root "E:Docoumentcodeceptdemo"
     
    loginaccount --
      log me in
        Object: login
          我 在页面 "/user/login"
          我 等 10
          我 填写字段 {"css":".ant-input-affix-wrapper .ant-input:not(:first-child)"}, "13500000000"
          我 填写字段 {"css":".ant-input-affix-wrapper .ant-input:not(:last-child)"}, "12345678"
       111
          我 单击 "button, html [type="button"]"
          我 等 10
          我 看到 "开通SaaS"
          我 see attributes on elements ".antd-pro-views-tenant-index-listTitle button", {"type":"button"}
          我 单击 "Automated_Testing"
          我 等 10
        我 抓取 cookie
        我 在页面 "/dashboard"
        我 等 10
        我 看到 "Dashboard"
      √ OK in 46407ms
     
     
      OK  | 1 passed   // 49s

    再次运行,就没有了登录过程,直接使用cookie登录

    CodeceptJS v2.6.5
    Using test root "E:Docoumentcodeceptdemo"
     
    loginaccount --
      log me in
        我 在页面 "/"
        我 设置 cookie [{"name":"_tenant_avatar","value":"","domain":"*******.com","path":"/","expires":53847095461,"size":14,"httpOnly":false,"secure":false,"session":false},{"name":"_access_token","value":"ASDfArbI6V54...
        我 在页面 "/dashboard"
        我 在页面 "/dashboard"
        我 等 10
        我 看到 "Dashboard"
      √ OK in 17594ms
     
     
      OK  | 1 passed   // 20s
  • 相关阅读:
    zoj 3627#模拟#枚举
    Codeforces 432D Prefixes and Suffixes kmp
    hdu 4778 Gems Fight! 状压dp
    CodeForces 379D 暴力 枚举
    HDU 4022 stl multiset
    手动转一下田神的2048
    【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
    poj 3254 状压dp
    C++中运算符的优先级
    内存中的数据对齐
  • 原文地址:https://www.cnblogs.com/7047-zfy/p/13232231.html
Copyright © 2011-2022 走看看