首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Selenium 惯用代码

2012-08-22 
Selenium 常用代码setSpeed 500打开页open /waitForPageToLoad验证 DOMwaitForElementPresent //DIV[@id

Selenium 常用代码
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=btnNewclick //DIV[@id='btnNew']/em/buttonclick //label[text()='仓库:']/following-sibling::div/div/divclick css='li.x-boundlist-item'


iframe
selectFrame content-iframewaitForFrameToLoadselectFrame relative=up


store
storeText //div[@id='grdMain']/div[2]/div/table/tbody/tr[2]/td[2]/div namestore 2 ckQty storeEval storedVars['oldQty']-storedVars['ckQty'] newQtyecho ${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]'] wwaitForElementPresent //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]/aclick //DIV[@id='btnWinLiSave']/em/buttonclick //DIV[@id='btnWinSave']/em/buttonwaitForElementPresent //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]/tdclick //DIV[@id='btnAudited']/em/buttonclick //div[contains(@class, 'x-window x-message-box')]/div[3]/div/div[2]/em/buttonwaitForElementPresent //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 

热点排行