130 likes | 148 Views
Introduction of Selenium. Eli Lu 2016/10/13. Outline. What is selenium ? Selenium Projects Selenium Sponsors Easy to use Useful Feature & Tools Useful Links Q & A. What is selenium ?. What is selenium ?
E N D
Introduction of Selenium Eli Lu 2016/10/13
Outline • What is selenium ? • Selenium Projects • Selenium Sponsors • Easy to use • Useful Feature & Tools • Useful Links • Q & A
What is selenium ? • What is selenium ? • Selenium automates browsers. That's it! What you do with that power is entirely up to you. Primarily, it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well. • Support languages • Java , csharp, python, ruby , php, perl, javascript , golang
Selenium Projects • Selenium WebDriver • Selenium WebDriver can drive a browser natively either locally or on remote machines. • Selenium Grid • Selenium Grid takes Selenium Remote Control to another level by running tests on many servers at the same time, cutting down on the time it takes to test multiple browsers or operating systems. • Selenium IDE • Selenium IDE is a Firefox add-on that makes it easy to record and playback tests in Firefox 2+. You can even use it to generate code to run the tests with Selenium Remote Control. • Selenium Remote Control • Selenium Remote Control is a client/server system that allows you to control web browsers locally or on other computers, using almost any programming language and testing framework
Selenium Sponsors • Selenium-Level Sponsors • Platinum-Level Sponsors HC360000USED
Useful Feature & Method • Class of Selenium::WebDriver::Find_Element(s) • By Class, Class Name : Class Name • By CSS : CSS Selector • By ID : ID • By Link : Link • By Link Text, Partial Link Text : Link Text • By Name ,Tag Name : Name & Tag Name • By XPATH : XPATH • Class of Selenium::WebDriver::Navigation • back : Move back a single entry in the browser's history. • forward : Move forward a single entry in the browser's history. • initialize : A new instance of Navigation. • refresh : Refresh the current page. • to : Navigate to the given URL.
Class of Selenium::WebDriver::Element • attribute : Get the value of the given attribute. • clear : Clear this element. • click : Click the element. • displayed? : Is the element displayed?. • enabled? : Is the element enabled?. • send_key : Send keystrokes to this element. • text : Get the text content of this element. • value : Get the value of this element. • Screenshot feature of Selenium::WebDriver • save_screenshot : save screenshot to PNG file • screenshot_as : save screenshot as specific format • Base64 or png
Get XPATH from chrome browser • Launch Chrome • Enable Developer Tool • Find target element • Press right click • Select Copy • Select Copy XPATH • Take full screenshot at chrome require “chromedriver-screenshot” • Add implicit timeouts wait driver.manage.timeouts.implicit_wait= 30
Set Wait time & use wait.until wait = Selenium::WebDriver::Wait.new(:timeout => 60) # seconds wait.until{ driver.find_elements(:xpath => "//*[@id='Email']" ) } • Scroll to specific element element. location_once_scrolled_into_view • Find Element Memo • Find element’s parent (:xpath => "../ol/li") • Find by content of tag (:xpath => "//h3[contains(text(),‘Yahoo')]") • Find element from element rootElement.find_element(:xpath => “//h3/h4”) childElement = rootElement.find_element(:xpath => “/h5/h6”) • Find element by attribute value (:xpath => "//*[@id='signIn']")
Useful Links • Selenium Website • http://docs.seleniumhq.org/ • Ruby Bindings • https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings • Selenium API Document for Ruby • http://www.rubydoc.info/gems/selenium-webdriver/0.0.28/Selenium/WebDriver/Driver • Ruby Website • https://www.ruby-lang.org/zh_tw/ • Example of Eli Lu • https://github.com/luyaotsung/CompanyWorkJobs/blob/master/Ruby/AndroidDeveloperConsole.rb