Selenium 常用代码

引用

http://release.seleniumhq.org/selenium-core/1.0.1/reference.html

速度

setSpeed 500

打开页

open /
waitForPageToLoad

验证DOM

waitForElementPresent //DIV[@id='btnDirectLr']
waitForElementPresent //DIV[text()='库存报表']
verifyElementPresent css=div#msg-div:contains("审核成功")

waitForElementPresent //DIV[@id='btnNew']
waitForElementPresent //div[contains(@class, 'x-mask-msg') and contains(@style, 'display: none')]
waitForElementNotPresent //DIV[@id='winForm' and contains(@style, 'visibility: hidden')]

单击

click //DIV[text()='库存报表']
click id=btnNew
click //DIV[@id='btnNew']/em/button
click //label[text()='仓库:']/following-sibling::div/div/div
click css='li.x-boundlist-item'

iframe

selectFrame content-iframe
waitForFrameToLoad
selectFrame relative=up

store

storeText //div[@id='grdMain']/div[2]/div/table/tbody/tr[2]/td[2]/div name
store 2 ckQty 
storeEval storedVars['oldQty']-storedVars['ckQty'] newQty
echo ${name}

verify

verifyText //div[@id='grdMain']/div[2]/div/table/tbody/tr[2]/td[2]/div ${name}
verifyText "css=div#grdMain td.x-grid-cell:nth-child(6) div" ${name}

form

type //input[@name='item[product_id]'] ${name}
keyUp //input[@name='item[product_id]'] w
waitForElementPresent //div[contains(@class, 'x-mask-msg') and contains(@style, 'display: none')]
waitForElementNotPresent //DIV[@id='blProducts' and contains(@class, 'display: none')]

click //DIV[@id='blProducts']/div/ul/li[1]/a
click //DIV[@id='btnWinLiSave']/em/button
click //DIV[@id='btnWinSave']/em/button
waitForElementPresent //div[contains(@class, 'x-mask-msg') and contains(@style, 'display: none')]

selectgridrow&audit

mouseDown //div[@id='grdMain']/div[2]/div/table/tbody/tr[2]/td
click //DIV[@id='btnAudited']/em/button
click //div[contains(@class, 'x-window x-message-box')]/div[3]/div/div[2]/em/button
waitForElementPresent //div[contains(@class, 'x-mask-msg') and contains(@style, 'display: none')]

提示

runScript msg = '<div id="selenium-msg" style="background-color: orange;border-radius: 10px;font-size: 20px;left: 500px;line-height: 50px;position: absolute;  text-align: center;top: 5px;width: 600px;z-index: 10000;"></div>'; Ext.DomHelper.insertFirst(Ext.getBody(), msg, true);  
runScript Ext.get('selenium-msg').dom.innerHTML = '测试物料出库库存变化';  
runScript Ext.get('selenium-msg').dom.innerHTML = '得到测试数据';  
runScript Ext.get('selenium-msg').dom.innerHTML = '测试完成';

Exttree加载成功

waitForCondition !selenium.browserbot.getCurrentWindow().Ext.getCmp('treMain').getStore().loading 2000

ClickExttreenode

click css=div#treMain .x-grid-row .x-grid-cell-inner:contains('库存报表')

消息框没有隐藏

waitForCondition selenium.browserbot.getCurrentWindow().Ext.MessageBox.isHidden() 1000

存/得Ext数据

storeEval selenium.browserbot.getCurrentWindow().Page.grid.getStore().data.items[0].data product 
storeEval storedVars['product'].product_code name

Extwindow显示

waitForCondition selenium.browserbot.getCurrentWindow().Page.win.isVisible() 1000

ExtCombobox处理

runScript Page.frm.getForm().findField("item[warehouse_id]").expand()  
waitForCondition selenium.browserbot.getCurrentWindow().Ext.getCmp('frmMain').getForm().findField("item[warehouse_id]").isExpanded 1000 
runScript Page.frm.getForm().findField("item[warehouse_id]").select(1)  
runScript Page.frm.getForm().findField("item[warehouse_id]").collapse()

Extrecordselect处理

type //input[@name='item[product_id]'] ${name} 
keyUp //input[@name='item[product_id]'] w 
waitForCondition selenium.browserbot.getCurrentWindow().Ext.MessageBox.isHidden() 1000 
waitForCondition selenium.browserbot.getCurrentWindow().Ext.getCmp('frmLi').getForm().findField("item[product_id]").isExpanded 1000 
click dom=selenium.browserbot.getCurrentWindow().Ext.getCmp('frmLi').getForm().findField("item[product_id]").getPicker().getNodes()[0]  
runScript Ext.getCmp('frmLi').getForm().findField("item[product_id]").collapse()

Extgrid加载完成

waitForCondition !selenium.browserbot.getCurrentWindow().Page.grid.getStore().loading 2000

得到Extgrid数据

storeEval selenium.browserbot.getCurrentWindow().Page.grid.getStore().data.items[0].data.code ckBillCode 
echo ckBillCode: ${ckBillCode}

clickExtmessageyes

click css=div#btnAudited em button  
click dom=selenium.browserbot.getCurrentWindow().Ext.MessageBox.msgButtons.yes.btnEl.dom  
verifyElementPresent css=div#msg-div:contains("审核成功")

verifyExtgridcellvalue

verifyText css=div#grdMain td.x-grid-cell:nth-child(6) div ${newQty}.0

相关推荐