ap上线ac测试下发配置roboot脚本

Zss 发表于:

在平常的工作中,经常需要用到ap上线ac,一些系列的重复性操作,索性将其依次写成一个脚本来实现

可以批量的上线多个ap,检测ap是否上线成功,并且在ac上下发配置到ap,再检测配置是否下发正确

当时在学习robot framework,那么就使用robot framework来写了,其实我觉得学习这个的成本还是较大的,

不过确实很强大,不过也有一定的缺陷,不像Python加selenium写程序来的灵活,当然学习Python的成本也是更加大的

很方便的是框架已经集成了报告的生成

———————————检测ap是否上线ac———————————

*** Settings ***
Library           Selenium2Library    timeout=45
Library           Dialogs

*** Variables ***
${name}           admin
${password}       admin
${url}            http://192.168.99.165
${care ip}        10.6.161.135
${care name}      care
${care password}    superwifi
${care url}       http://10.6.161.135

*** Test Cases ***
Ap online for care
    open browser login
    ${ap name}    ${ap mac}=    get ap name and mac
    factory
    Sleep    2
    close browser
    Sleep    250
    open browser login
    settings network
    settings care ip
    close browser
    Care login
    Network
    Ap
    Add
    Ap name    ${ap name}
    Ap mac    ${ap mac}
    Create
    Sleep    120
    ${index}    Get index    ${ap name}
    Check ap online    ${index}
    close browser

*** Keywords ***
open browser login
    Open Browser    ${url}    chrome    ap
    Wait Until Page Contains Element    //*[@id="cbi-input-user"]
    Input Text    //*[@id="cbi-input-user"]    ${name}
    Input Text    //*[@id="cbi-input-password"]    ${password}
    Click Button    //*[@id="cbi-home-button-login"]

factory
    Wait Until Page Contains Element    css=#primaryMenu > li:nth-child(3) > a
    Click Element    css=#primaryMenu > li:nth-child(3) > a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(5) > a
    Click Element    css=#keepcfg
    Click Element    //*[@name="reset.default"]
    Confirm Action

get ap name and mac
    ${ap name}    get text    //*[@id="cbid.system.product_name"]
    ${ap mac}    get text    //*[@id="cbid.interface.eth0.mac_address"]
    log    ${ap name}
    log    ${ap mac}
    [Return]    ${ap name}    ${ap mac}

settings network
    Click element    css=#primaryMenu > li:nth-child(2) > a
    Click element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(2) > a
    Select From List By Value    //*[@id="cbid.network.general.internet_connection_type"]    dhcp
    focus    css=#cbi-network > div.cbi-footer > input
    Wait Until Page Contains Element    css=#cbi-network > div.cbi-footer > input
    Click Element    css=#cbi-network > div.cbi-footer > input

settings care ip
    focus    css=#primaryMenu > li:nth-child(2) > a
    Click element    css=#primaryMenu > li:nth-child(2) > a
    Click element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(4) > a
    click element    //*[@id="cbid.thinap.sys.thinap"]
    Select From List By Value    //*[@id="cbid.thinap.sys.ac_mode"]    0
    Clear Element Text    //*[@id="cbid.thinap.sys.ac_ip"]
    input text    //*[@id="cbid.thinap.sys.ac_ip"]    ${care ip}
    click element    css=#cbi-thinap > div.cbi-footer > input
    click element    css=#changes-apply > a:nth-child(2)

Care login
    Open Browser    ${care url}    chrome    care
    Wait Until Page Contains Element    //*[@name='inputUserName']
    Input Text    //*[@name='inputUserName']    ${care name}
    Input Text    //*[@name="inputPassword"]    ${care password}
    Click Button    //div/button[@type="submit"]

Network
    Wait Until Page Contains Element    //*[@id="page-sidebar-menu"]/li[2]/a/span
    Click Element    //*[@id="page-sidebar-menu"]/li[2]/a/span

Ap
    Sleep    1
    Click Element    //ul[@id="submenu-network"]/li[1]/a/span

Add
    sleep    1
    Click Element    //p/i[@class="fa fa-plus fa-plus-icon"]

Ap name
    [Arguments]    ${ap name}
    sleep    1
    input text    //*[@name="inputApName"]    ${ap name}

Ap mac
    [Arguments]    ${ap mac}
    input text    //*[@name="inputEthMac"]    ${ap mac}

Create
    sleep    1
    Click element    //div[@class="text-align-center"]/button[@ng-click="createAp()"]

Get index
    [Arguments]    ${ap name}
    Click Element    //*[@id="refresh-toggler"]/i
    sleep    1
    : FOR    ${index}    INRANGE    1    10
    \    ${xpath}    catenate    SEPARATOR=    //tbody/tr[    ${index}
    \    ${xpath}    catenate    SEPARATOR=    ${xpath}    ]/td[2]/a
    \    ${check name}    get text    ${xpath}
    \    ${test}    Run Keyword If    '${check name}'=='${ap name}'    Run Keywords    Set Variable    ${index}
    \    ...    AND    Exit For Loop
    \    ...    ELSE    Continue For Loop
    [Return]    ${index}

Check ap online
    [Arguments]    ${index}
    Switch Browser    care
    Click Element    //*[@id="refresh-toggler"]/i
    Click Element    //*[@id="refresh-toggler"]/i
    sleep    1
    ${ap xpath}    catenate    SEPARATOR=    //*[@id="simpledatatable"]/tbody/tr[    ${index}
    ${ap xpath}    catenate    SEPARATOR=    ${ap xpath}    ]/td[1]/img@data-original-title
    ${ap online}    Get Element Attribute    ${ap xpath}
    Should Be Equal    ${ap online}    Online

——————————检测ac下发配置到ap是否成功—————————-

*** Settings ***
Library           Selenium2Library    timeout=45
Library           Dialogs

*** Variables ***
${name}           admin
${password}       admin
${care ip}        10.6.161.180
${care name}      oneone
${care password}    oneone
${care url}       http://10.6.161.180
${Test-name}      Test-name
${Test-location}    Test-location
@{care 2.4g WIRELESS MODE}    11gn    11b    11bg    11gnonly    11gn40+    11g    11gn40-
...               11gnonly40+    11gnonly40-    11gn40+    11gn40-
@{care 5g WIRELESS MODE}    11anonly40+    11a    11acvht40+    11acvht    11acvht80    11anonly    11an
...               11an40+    11an40-    11acvht40-    11anonly40-

*** Test Cases ***
CareLogin-->edit//ApLogin
    Care login
    Network
    Access Point
    ${ap ip}    get ap ip
    edit
    Ap Login    ${ap ip}

Check--AP NAME-AP LOCATION
    Switch Browser    care
    set AP NAME    ${Test-name}
    set LOCATION    ${Test-location}
    Save
    Switch Browser    ap
    sleep    60
    ${Check AP NAME}    get AP NAME
    Should Be Equal    ${Check AP NAME}    ${Test-name}
    ${Check AP LOCATION}    get AP LOCATION
    Should Be Equal    ${Check AP LOCATION}    ${Test-location}

Check--COUNTRY CODE
    : FOR    ${i}    INRANGE    10
    \    ${COUNTRY CODE}    Evaluate    random.choice(['511','4','8','12','16','32','5003','51','533','5000','40','31','44','48','50','52','112','56','5002','60','64','68','70','76','96','100','854','116','5001','136','140','452','156','162','170','188','131','196','203','208','214','218','818','222','233','231','246','250','254','258','276','288','300','304','308','312','316','320','332','340','344','348','352','356','360','364','372','376','380','392','400','398','404','408','412','414','428','422','438','440','442','446','807','454','458','462','470','474','478','480','175','484','583','492','496','499','504','524','528','530','554','558','56','578','580','512','586','585','591','598','600','604','608','616','620','630','634','638','642','643','646','882','682','686','688','702','703','705','710','724','144','740','752','756','760','158','834','768','764','780','788','792','804','784','826','841','842','858','860','548','862','704','850','887','716'])    random
    \    Switch Browser    care
    \    Access Point
    \    edit
    \    sleep    0.5
    \    set 2.4g COUNTRY CODE    ${COUNTRY CODE}
    \    sleep    0.5
    \    set 5g COUNTRY CODE    ${COUNTRY CODE}
    \    sleep    2
    \    save
    \    sleep    120
    \    Switch Browser    ap
    \    ${ap 2.4g COUNTRY CODE}    get 2.4g Country Code
    \    Should Be Equal    ${ap 2.4g COUNTRY CODE}    ${COUNTRY CODE}
    \    ${ap 5g COUNTRY CODE}    get 5g Country Code
    \    Should Be Equal    ${ap 5g COUNTRY CODE}    ${COUNTRY CODE}

Check--WIRELESS MODE
    : FOR    ${index}    INRANGE    10
    \    Switch Browser    care
    \    Access Point
    \    edit
    \    set 2.4g WIRELESS MODE    @{care 2.4g WIRELESS MODE}[${index}]
    \    set 5g WIRELESS MODE    @{care 5g WIRELESS MODE}[${index}]
    \    Save
    \    sleep    120
    \    Switch Browser    ap
    \    ${ap 2.4g WIRELESS MODE}    get 2.4g WIRELESS MODE
    \    Should Be Equal    ${ap 2.4g WIRELESS MODE}    @{care 2.4g WIRELESS MODE}[${index}]
    \    ${ap 5g WIRELESS MODE}    get 5g WIRELESS MODE
    \    Should Be Equal    ${ap 5g WIRELESS MODE}    @{care 5g WIRELESS MODE}[${index}]

Check--HT20/HT40 SWITCH

*** Keywords ***
Care login
    Open Browser    ${care url}    chrome    care
    Wait Until Page Contains Element    //*[@name='inputUserName']
    Input Text    //*[@name='inputUserName']    ${care name}
    Input Text    //*[@name="inputPassword"]    ${care password}
    Click Button    //div/button[@type="submit"]

Network
    Wait Until Page Contains Element    //*[@id="page-sidebar-menu"]/li[2]/a/span
    Click Element    //*[@id="page-sidebar-menu"]/li[2]/a/span

Access Point
    Sleep    1
    Click Element    //ul[@id="submenu-network"]/li[1]/a/span

get ap ip
    sleep    1
    ${ap ip}    get text    //*[@id="simpledatatable"]/tbody/tr[1]/td[7]
    [Return]    ${ap ip}

edit
    Wait Until Page Contains Element    //*[@id="simpledatatable"]/tbody/tr[1]/td[13]/img[1]
    focus    //*[@id="simpledatatable"]/tbody/tr[1]/td[13]/img[1]
    Click Image    //*[@id="simpledatatable"]/tbody/tr[1]/td[13]/img[1]

set AP NAME
    [Arguments]    ${Test-name}
    Wait Until Page Contains Element    //*[@id="inputApName"]
    Input Text    //*[@id="inputApName"]    ${Test-name}

set LOCATION
    [Arguments]    ${Test-location}
    Input Text    //*[@id="inputLocation"]    ${Test-location}

set 2.4g COUNTRY CODE
    [Arguments]    ${COUNTRY CODE}
    ${COUNTRY CODE}    Catenate    SEPARATOR=    number:    ${COUNTRY CODE}
    focus    //*[@id="Apform"]/div[2]/div/div/div[2]/div/div[2]/div/span/select
    sleep    1
    Select From List By Value    //*[@id="Apform"]/div[2]/div/div/div[2]/div/div[2]/div/span/select    ${COUNTRY CODE}

set 5g COUNTRY CODE
    [Arguments]    ${COUNTRY CODE}
    ${COUNTRY CODE}    Catenate    SEPARATOR=    number:    ${COUNTRY CODE}
    focus    //*[@id="Apform"]/div[3]/div/div/div[2]/div/div[2]/div/span/select
    sleep    1
    Select From List By Value    //*[@id="Apform"]/div[3]/div/div/div[2]/div/div[2]/div/span/select    ${COUNTRY CODE}

Save
    focus    //*[@id="Apform"]/div[4]/button[1]
    Click Element    //*[@id="Apform"]/div[4]/button[1]

set 2.4g WIRELESS MODE
    [Arguments]    ${2.4g WIRELESS MODE}
    log    ${2.4g WIRELESS MODE}
    ${2.4g WIRELESS MODE}    Catenate    SEPARATOR=    string:    ${2.4g WIRELESS MODE}
    log    ${2.4g WIRELESS MODE}
    focus    //*[@id="Apform"]/div[2]/div/div/div[2]/div/div[3]/div/span/select
    Select From List By Value    //*[@id="Apform"]/div[2]/div/div/div[2]/div/div[3]/div/span/select    ${2.4g WIRELESS MODE}
    sleep    1

set 5g WIRELESS MODE
    [Arguments]    ${5g WIRELESS MODE}
    ${5g WIRELESS MODE}    Catenate    SEPARATOR=    string:    ${5g WIRELESS MODE}
    focus    //*[@id="Apform"]/div[3]/div/div/div[2]/div/div[3]/div/span/select
    Select From List By Value    //*[@id="Apform"]/div[3]/div/div/div[2]/div/div[3]/div/span/select    ${5g WIRELESS MODE}
    sleep    1

Ap Login
    [Arguments]    ${ap ip}
    ${ap url}    Catenate    SEPARATOR=    http://    ${ap ip}
    Open Browser    ${ap url}    chrome    ap
    Wait Until Page Contains Element    //*[@id="cbi-input-user"]
    Input Text    //*[@id="cbi-input-user"]    ${name}
    input text    //*[@id="cbi-input-password"]    ${password}
    click element    //*[@id="cbi-home-button-login"]

get AP NAME
    Wait Until Page Contains Element    css=#primaryMenu > li:nth-child(2) > a
    Click Element    css=#primaryMenu > li:nth-child(2) > a
    ${Check AP NAME}    Get Value    //*[@id="cbid.system.general.sys_name"]
    [Return]    ${Check AP NAME}

get AP LOCATION
    ${Check AP LOCATION}    Get Value    //*[@id="cbid.system.general.sys_location"]
    [Return]    ${Check AP LOCATION}

get 2.4g Country Code
    Click Element    css=#primaryMenu > li:nth-child(2) > a
    #閰嶇疆
    Wait Until Page Contains Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    #鏃犵嚎
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    Wait Until Page Contains Element    //*[@id="cbid.wireless.device_radio0.country_code"]
    ${ap 2.4g COUNTRY CODE}    Get Selected List Value    //*[@id="cbid.wireless.device_radio0.country_code"]
    [Return]    ${ap 2.4g COUNTRY CODE}

get 5g Country Code
    Wait Until Page Contains Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    #5g radio
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    Wait Until Page Contains Element    //*[@id="cbid.wireless.device_radio1.country_code"]
    ${ap 5g COUNTRY CODE}    Get Selected List Value    //*[@id="cbid.wireless.device_radio1.country_code"]
    [Return]    ${ap 5g COUNTRY CODE}

get 2.4g WIRELESS MODE
    Click Element    css=#primaryMenu > li:nth-child(2) > a
    Wait Until Page Contains Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l2 > li:nth-child(3) > a
    Wait Until Page Contains Element    //*[@id="cbid.wireless.device_radio0.wireless_mode"]
    ${ap 2.4g WIRELESS MODE}    Get Selected List Value    //*[@id="cbid.wireless.device_radio0.wireless_mode"]
    [Return]    ${ap 2.4g WIRELESS MODE}

get 5g WIRELESS MODE
    Wait Until Page Contains Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    #5g radio
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    sleep    2
    Click Element    css=#wrapper > div.tabmenu > ul.l3 > li:nth-child(2)>a
    Wait Until Page Contains Element    //*[@id="cbid.wireless.device_radio1.wireless_mode"]
    ${ap 5g WIRELESS MODE}    Get Selected List Value    //*[@id="cbid.wireless.device_radio1.wireless_mode"]
    [Return]    ${ap 5g WIRELESS MODE}