Selenium入门03

接上一节,说一下如何进行远程测试

1、下载selenium-server-standalone的jar包
http://www.seleniumhq.org/download/

2、运行selenium-server-standalone

set JAVA_HOME=C:\NeoLanguages\Java\JDK\jdk_x86_1.8.0_77
set PATH=%JAVA_HOME%\bin;%PATH%;C:\NeoTest\TestSelenium\trunk\bin\x86\;
set webdriver.gecko.driver=C:\NeoTest\TestSelenium\trunk\bin\x86\geckodriver.exe

java -jar ../lib/selenium-server-standalone-3.3.1.jar -role standalone

pause

3、远程测试脚本
TestHelloWorldRemote.py

# !C:\Languages\Python\Python27\python.exe
# -*- coding: utf-8 -*-
'''
Created on 2016-10-22
@author: Hansen
HelloWorld sample for NeoSelenium
'''

from NeoSelenium import deInitEngine
from NeoSelenium import initEngineRemote

#一个简单的查询测试
def neohope_search_test():
    try:
        #myEngine = initEngine('ie32')
        #myEngine = initEngine('ie64')
        #myEngine = initEngine('chrome')
        #myEngine = initEngine('ff32')
        #myEngine = initEngine('ff64')
	myEngine = initEngineRemote()

        base_url = "https://www.neohope.com"
        myEngine.get(base_url + "/")
        myEngine.find_element_by_name("s").clear()
        myEngine.find_element_by_name("s").send_keys("Metabase")
        myEngine.find_element_by_css_selector("button.search-submit").click()
	myEngine.implicitly_wait(1000)
	#print(myEngine.find_elements_by_xpath("//div[@id='content']/article"))
	queryResultLenght = len(myEngine.find_elements_by_xpath("//div[@id='content']/article"))
	#print(queryResultLenght)
	#应该是1但现在是10
        assert queryResultLenght==1
    finally:
        #deInitEngine(myEngine)
	print("test end")

#start here
neohope_search_test()

NeoSelenium.py

#!C:\Languages\Python\Python27\python.exe
# -*- coding: utf-8 -*-
'''
Created on 2017-04-07
@author: Hansen
NeoSelenium
'''

import os
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

NPath = None
x86Path = "C:\NeoTest\TestSelenium\\trunk\\bin\\x86;"
x64Path = "C:\NeoTest\TestSelenium\\trunk\\bin\\x64;"

'''
selenium remote engine init
'''
def initEngineRemote():
    engine = webdriver.Remote(command_executor="http://192.168.130.178:4444/wd/hub", desired_capabilities=DesiredCapabilities.FIREFOX)
    return engine

'''
selenium engine deInit
'''
def deInitEngine(engine):
    engine.close()
    engine.quit()

Leave a Reply

Your email address will not be published. Required fields are marked *

*