Showing posts with label Chrome. Show all posts
Showing posts with label Chrome. Show all posts

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 

Tuesday, 28 March 2017

[chrome-developer-tools] how to Opening the Console in sources tab

how to Opening the Console in sources tab

Pressing Esc when on the Sources tab will let you see the a small view of the Console 

 Pressing Esc


Monday, 20 March 2017

Selenium WebDriver - Maximize window (浏览器窗口最大化)

Selenium WebDriver with python - Maximize window

FireFox : 

         self.driver = webdriver.Firefox()
      self.driver.maximize_window()

Chrome : 
   url = "C:\\Programs\\Python36\\BrowersDriver\\chromedriver.exe"
      options = webdriver.ChromeOptions()
      options.add_argument("--start-maximized")
      self.driver = webdriver.Chrome(url,chrome_options=options)

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...