Friday, 7 April 2017

[Selenium] 4 Selenium Google WebDriver.

In this section,  You will learn how execute test case by Chrome browser and execute browser behavior by selenium.

1.  Execute test case by Chrome
1.1.Create a [BrowersDriver] folder under Python36 folder.
1.2.Download Goolge WebDriver and save into BrowersDriver folder - link1  link2 
   (P.S : You can save it  wherever you want. )



1.3. Create testChrome.py file in pyCharm IDE.

1.4. Entering the below code and execute it.


        from selenium import webdriver

        url="C:\\Programs\\Python36\\BrowersDriver\\chromedriver.exe"        driver=webdriver.Chrome(url)

        driver.get("http://www.google.com")

        # print current url        print(driver.current_url)
        # print current page title        print(driver.title)

        # Close the browser window that the driver has focus of        driver.close()
        # Call Dispose() => Release all resource.        driver.quit()


       In this test case,
          1. go to Google Website
          2. print current URL - https://www.google.com.sg/?gfe_rd=cr&ei=FlbnWJ2QIrHG8AfLz7zQDg&gws_rd=ssl
          3. print current webpage title - Google
          4. close the browser
          5. release webdriver. 


PS: If your chrome just shows blank page, WebDriver you download does not support your Chrome. 
Solution: download Chrome WebDriver which match your chrome version or 
          downgrade your chrome version. 

My Chrome Version: 57.02987.133 (64 bit)
ChromeDriver.exe version is blank. 

2. Browser Behavior 
    You will learn how to manipulate browser behavior - Go, back, forward, refresh.
2.1 Create a python file - TestDriverBehavior.py
2.2 Entering the below code and execute it.
   
    
print
(driver.current_url) # print current page titleprint(driver.title) # go to Yahoo pagedriver.get("http://www.yahoo.com") # print current urlprint(driver.current_url) # print current page titleprint(driver.title) # go back previous pagedriver.back() # print current urlprint(driver.current_url) # print current page titleprint(driver.title) # loads the next URL in the history list as same as window.history.forward() method.driver.forward() # print current urlprint(driver.current_url) # print current page titleprint(driver.title) # refresh current pagedriver.refresh() # Close the browser window that the driver has focus ofdriver.close() # Call Dispose() => Release all resource.driver.quit()



       In this test case,
          1. go to Google Website
          2. print current URL - https://www.google.com.sg/?gfe_rd=cr&ei=FlbnWJ2QIrHG8AfLz7zQDg&gws_rd=ssl
          3. print current webpage title - Google
          5. go to Yahoo website
          6. print current URL - https://sg.yahoo.com/?p=us
          7. print current webpage title -Yahoo
          8. go back privous web page (Google)
          9. print current URL - https://www.google.com.sg/?gfe_rd=cr&ei=FlbnWJ2QIrHG8AfLz7zQDg&gws_rd=ssl
          10. print current webpage title - Google
          11. go forward to next web page (Yahoo)
          12. print current URL - - https://sg.yahoo.com/?p=us
               13. print current webpage title - Yahoo
          14. refresh current page
          15. close the browser
          16. release webdriver. 
You can download my code on my github 

1 comment:

  1. Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
    Selenium Training Institute in Chennai | Selenium Training in Chennai

    ReplyDelete

how-to-recursively-create-subfolder-in-each-folder-of-a-directory-in-cmd

test.cmd: @echo off setlocal for /f "usebackq tokens=*" %%a in (`dir /b /a:d`) do ( rem enter the directory pushd %%a echo...