ITeye博客

Selenium 常用代码

RobinWu · 2011-12-07 10:12 · Web前端 · Markdown

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

速度


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')]

select grid row & 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 = '测试完成';

Ext tree 加载成功


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

Click Ext tree node


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 

Ext window 显示


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

Ext Combobox 处理


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()  

Ext recordselect 处理


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()  

Ext grid 加载完成


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

得到 Ext grid 数据


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

click Ext message yes


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

verify Ext grid cell value


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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。