67 |
68 | The **.gitignore** file defined for the project
69 | specifies that the folder is not uploaded back to GitHub.
70 | This is also the case for the npm-debug.log created in case there is an error.
71 |
72 |
73 | ## Run the app
74 |
75 | Invoke the Node.Js app
76 |
77 | ```
78 | node index.js
79 | ```
80 |
81 | The expected response is a new Terminal line.
82 |
83 |
84 | ## Git hooks
85 |
86 | The package.json file defines what Node does before Git actions.
87 |
88 | ### precommit
89 |
90 | If this is in the package.json file:
91 |
92 | ```
93 | "scripts": {
94 | "precommit": "jshint index.js"
95 | },
96 | ```
97 |
98 | jshint is invoked on index.js on `git commit` based on settings in file **.jshintrc**.
99 | The file in the repo, these errors to appear based on the index.js in the repo:
100 |
101 |
102 | index.js: line 3, col 15, Expected '===' and instead saw '=='.
103 | index.js: line 4, col 40, Missing semicolon.
104 | index.js: line 8, col 9, Expected '{' and instead saw 'doSomething'.
105 | index.js: line 8, col 22, Missing semicolon.
106 | index.js: line 11, col 35, Missing semicolon.
107 | index.js: line 14, col 2, Missing semicolon.
108 | index.js: line 3, col 9, 'num' is not defined.
109 | index.js: line 7, col 12, 'num' is not defined.
110 |
111 | 8 errors
112 |
113 | husky - pre-commit hook failed (add --no-verify to bypass)
114 |
115 |
116 |
117 | Options specified are according to
118 |
119 | http://jshint.com/docs/options
120 |
121 |
122 |
123 | ### override
124 |
125 | To commit without performing verification, use this command:
126 |
127 | ```
128 | git commit -m"update index.js" --no-verify
129 | ```
130 |
131 | ### Fix
132 |
133 | PROTIP: After you insert lines, save the file
134 | and get new line numbers in the error messages by running again.
135 |
136 |
137 | ### prepush
138 |
139 | If this is in the package.json file:
140 |
141 | ```
142 | "scripts": {
143 | "prepush": "jshint index.js"
144 | },
145 | ```
146 |
147 | jshint is invoked on index.js on `git push`.
148 |
149 | To push without performing verification,
150 | change the package.json file to:
151 |
152 | ```
153 | git push --no-verify
154 | ```
155 |
156 | ## Video
157 |
158 | A video of this is at
159 |
160 | https://www.youtube.com/watch?v=sTnatBgmYsE
161 | and blog
162 | http://www.penta-code.com/prevent-bad-git-commits-and-pushes-with-husky/
163 |
--------------------------------------------------------------------------------
/node-test1/index-error.js:
--------------------------------------------------------------------------------
1 | var myFunction = function() {
2 |
3 | if (num == 10) {
4 | console.log('The number is 10')
5 | }
6 |
7 | while (num !== 10)
8 | doSomething()
9 |
10 | function doSomething() {
11 | console.log('hello world')
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/node-test1/index-valid.js:
--------------------------------------------------------------------------------
1 | var myFunction = function() {
2 | var num;
3 |
4 | if (num === 10) {
5 | console.log('The number is 10');
6 | }
7 |
8 | while (num !== 10){
9 | doSomething();
10 | }
11 |
12 | function doSomething() {
13 | console.log('hello world');
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/node-test1/index.js:
--------------------------------------------------------------------------------
1 | var myFunction = function() {
2 |
3 | if (num == 10) {
4 | console.log('The number is 10')
5 | }
6 |
7 | while (num !== 10)
8 | doSomething()
9 |
10 | function doSomething() {
11 | console.log('hello world')
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/node-test1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Prehooks",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "precommit": "jshint index.js",
8 | "prepush": "jshint index.js"
9 | },
10 | "devDependencies": {
11 | "husky": "0.7.0",
12 | "jshint": "^2.8.0"
13 | },
14 | "author": "PentaCode",
15 | "license": "ISC"
16 | }
17 |
--------------------------------------------------------------------------------
/ps-auto-log.ps1:
--------------------------------------------------------------------------------
1 | # ps-auto-log.ps1
2 | # by wilsonmar@gmail.com
3 | # Based on http://mctexpert.blogspot.com/2012/10/automatically-create-log-of-your.html
4 | # To run on Mac:
5 | # chmod +x ps-auto-log.ps1
6 | # ./ps-auto-log.ps1
7 | #
8 | # Create a filename based on a ISO 8601 time stamp:
9 | $Filename = `
10 | ((Get-date).Year).ToString()+"-"+`
11 | ((Get-date).Month).ToString("00")+"-"+`
12 | ((Get-date).Day).ToString("00")+"T"+`
13 | ((Get-date).Hour).ToString("00")+"-"+`
14 | ((Get-date).Minute).ToString("00")+"-"+`
15 | ((Get-date).Second).ToString("00")+"-local.txt"
16 | # 12-9-2016-8-39-6.txt TODO: Add timezone.
17 | # echo $Filename
18 |
19 | # Set the storage path to a folder in $HOME/Documents:
20 | if( "$IsWindows" -eq $True ) {
21 | $Path = "C:\Users\$USER\Documents\PowerShell\Transcript"
22 | }else{ # Mac / Linux:
23 | $Path = "~/Documents/PowerShell/Transcript"
24 | }
25 |
26 | # Turn on PowerShell transcripting:
27 | Start-Transcript -Path "$Path\$Filename"
28 | # Sample output from command:
29 | # Transcript started, output file is ~/Documents/PowerShell/Transcript\2016-12-09T08-48-45-local.txt
--------------------------------------------------------------------------------
/secrets.sh:
--------------------------------------------------------------------------------
1 | #!/usr/local/bin/bash
2 | # secrets.sh in https://github.com/wilsonmar/mac-install-all
3 | # referenced by macos-install-all.sh in the same repo.
4 | # This file name secrets.sh should be specified in .gitignore so
5 | # it doesn't upload to a public GitHub/GitLab/BitBucket/etc.
6 | # Run command source secrets.sh pulls these variables in:
7 | # CAUTION: No spaces around = sign.
8 | GIT_NAME="Wilson Mar"
9 | GIT_ID="WilsonMar@gmail.com"
10 | GIT_EMAIL="WilsonMar+GitHub@gmail.com"
11 | GIT_USERNAME="hotwilson"
12 | GPG_PASSPHRASE="only you know this 2 well"
13 | GITS_PATH="~/gits"
14 | GITHUB_ACCOUNT="hotwilson"
15 | GITHUB_PASSWORD="change this to your GitHub account password"
16 | GITHUB_REPO="sample"
17 |
18 | # Lists can be specified below. The last one in a list is the Git default:
19 | MAC_TOOLS=""
20 | # mas, ansible, 1password, powershell, kindle, vmware-fusion?
21 | GIT_CLIENT=""
22 | # git, cola, github, gitkraken, smartgit, sourcetree, tower, magit, gitup
23 | GIT_EDITOR=""
24 | # atom, code, eclipse, emacs, intellij, macvim, nano, pico, sts, sublime, textmate, textedit, vim
25 | # NOTE: pico, nano, and vim are built into MacOS, so no install.
26 | # NOTE: textwrangler is a Mac app manually installed from the Apple Store.
27 | GIT_BROWSER=""
28 | # chrome, firefox, brave, phantomjs, NOT: Safari
29 | # others (flash-player, adobe-acrobat-reader, adobe-air, silverlight)
30 | GIT_TOOLS=""
31 | # none, hooks, tig, lfs, diff-so-fancy, grip, p4merge, git-flow, signing, hub
32 | GIT_LANG="python"
33 | # python, python3, java, node, go
34 | JAVA_TOOLS=""
35 | # maven, gradle, TestNG, cucumber, gcviewer, jmeter, jprofiler # REST-Assured, Spock
36 | # (Via maven, ant, or gradle: junit4, junit5, yarn, dbunit, mockito)
37 | PYTHON_TOOLS=""
38 | # virtualenv, anaconda, jupyter, ipython, numpy, scipy, matplotlib, pytest, robot
39 | # robotframework, others
40 | # See http://www.southampton.ac.uk/~fangohr/blog/installation-of-python-spyder-numpy-sympy-scipy-pytest-matplotlib-via-anaconda.html
41 | NODE_TOOLS=""
42 | # bower, gulp, gulp-cli, npm-check, jscs, less, jshint, eslint, webpack,
43 | # mocha, chai, protractor,
44 | # browserify, express, hapi, angular, react, redux
45 | # graphicmagick, aws-sdk, mongodb, redis, others
46 | DATA_TOOLS=""
47 | # mariadb, postgresql, mongodb
48 | # others (dbunit?, mysql?, evernote?)
49 | # others (google-drive-file-stream, dropbox, box, amazon-drive )
50 | MONGODB_DATA_PATH="/usr/local/var/mongodb" # default.
51 | TEST_TOOLS=""
52 | # selenium, sikulix, golum, dbunit?
53 | # Drivers for scripting language depend on what is defined in $GIT_LANG.
54 | CLOUD=""
55 | # icloud, aws, gcp, azure, cf, heroku, docker, vagrant,
56 | # terraform, serverless,
57 | # NOT: openstack
58 | AWS_ACCOUNT=""
59 | AWS_ACCESS_KEY_ID=""
60 | AWS_SECRET_ACCESS_KEY=""
61 | AWS_REGION="us-west-1"
62 |
63 | AZ_PRINCIPAL=""
64 | AZ_USER=""
65 | AZ_PASSWORD=""
66 | AZ_TENANT=""
67 | AZ_REGION=""
68 |
69 | GCP_PROJECT=""
70 | GCP_USER=""
71 | GCP_KEY=""
72 | GCP_REGION=""
73 |
74 | SAUCE_USERNAME=""
75 | SAUCE_ACCESS_KEY=""
76 | COLAB_TOOLS=""
77 | # google-hangouts, hipchat, joinme, keybase, microsoft-lync, skype, slack, teamviewer, whatsapp, sococo, zoom
78 | # NO gotomeeting (32-bit)
79 | MEDIA_TOOLS=""
80 | # others (audacity?, snagit?, camtasia?)
81 | VIZ_TOOLS=""
82 | # grafana,
83 | LOCALHOSTS=""
84 | # minikube, nginx, tomcat, jenkins, grafana,
85 | MINIKUBE_PORT="8083" # from default 8080
86 | NGINX_PORT="8086" # from default 8080
87 | TOMCAT_PORT="8087" # from default 8080
88 | JENKINS_PORT="8088" # from default 8080
89 | GRAFANA_PORT="8089" # from default 8080
90 | TRYOUT="all" # smoke tests.
91 | # all, HelloJUnit5, TODO: `virtuaenv, phantomjs, docker, hooks, jmeter, minikube, cleanup, editor
92 | TRYOUT_KEEP="jenkins"
93 |
94 | # To upgrade, add parameter in the command line:
95 | # ./mac-git-install.sh upgrade
96 |
--------------------------------------------------------------------------------
/sonar1.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | # sonar.sh From https://github.com/wilsonmar/git-utilities
3 |
4 | chmod 555 sonar-scanner
5 | ./sonar-scanner \
6 | -Dsonar.projectKey=sonarqube-1-vm \
7 | -Dsonar.sources=/Users/wilsonmar/gits/ng/angular4-docker-example \
8 | -Dsonar.host.url=http://23.236.48.147 \
9 | -Dsonar.login=7a51cb71a48ea3d16f57fe66021867fc2a98771e
--------------------------------------------------------------------------------
/temp.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # temp.py
3 |
4 | import pytz, time
5 | from datetime import datetime, tzinfo, timedelta
6 | from random import randint
7 |
8 | def iso8601_utc():
9 | class simple_utc(tzinfo):
10 | def tzname(self,**kwargs):
11 | return "UTC"
12 | def utcoffset(self, dt):
13 | return timedelta(0)
14 | return datetime.utcnow().replace(tzinfo=simple_utc()).isoformat()
15 | #print(iso8601_utc()+" = ISO8601 time at +00:00 UTC (Zulu time), with microseconds")
16 |
17 | def iso8601_local():
18 | class local_tz(tzinfo):
19 | def utcoffset(self, dt):
20 | ts = time.time()
21 | offset_in_seconds = (datetime.fromtimestamp(ts) - datetime.utcfromtimestamp(ts)).total_seconds()
22 | return timedelta(seconds=offset_in_seconds)
23 | return datetime.now().replace(microsecond=randint(0, 999999)).replace(tzinfo=local_tz()).isoformat()
24 | # print(iso8601_local()+" = ISO8601 time at local time zone offset, with random microseconds")
25 |
26 | print(iso8601_utc()+" = ISO8601 time at +00:00 UTC (Zulu time), with microseconds")
27 | print(iso8601_local()+" = ISO8601 time at local time zone offset, with random microseconds")
28 |
29 |
30 |
31 | #tz = pytz.timezone('America/Los_Angeles')
32 | #print(datetime.fromtimestamp(1463288494, tz).isoformat())
33 |
34 | #2016-05-14T22:01:34-07:00
35 |
36 | #import sys
37 | #import argparse # https://docs.python.org/2/howto/argparse.html
38 | #import time # tzinfo, timedelta
39 |
40 | #utc_offset_sec = time.altzone if time.localtime().tm_isdst else time.timezone
41 | #datetime.datetime.now().replace(tzinfo=datetime.timezone(offset=utc_offset_sec)).isoformat()
42 |
43 | #class TZ(tzinfo):
44 | # def utcoffset(self, dt): return timedelta(minutes=-399)
45 | #datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
46 |
47 | #print('jenkins_secret_chrome.py' +utc_offset_sec+ '.png')
48 |
--------------------------------------------------------------------------------
/tests/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wilsonmar/git-utilities/21f7b904833a57289bab6ee144e5ec7185361144/tests/.DS_Store
--------------------------------------------------------------------------------
/tests/HelloWorld.scala:
--------------------------------------------------------------------------------
1 | object HelloWorld extends App { println("Hello, Scala World!") }
2 |
--------------------------------------------------------------------------------
/tests/chrome-google-search-quit.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # chrome-google-search-quit.py
3 | # from https://sites.google.com/a/chromium.org/chromedriver/getting-started
4 | import time
5 | from selenium import webdriver
6 |
7 | driver = webdriver.Chrome()
8 | driver.get('http://www.google.com/xhtml');
9 | time.sleep(5) # Let the user actually see something!
10 | search_box = driver.find_element_by_name('q')
11 | search_box.send_keys('ChromeDriver')
12 | search_box.submit()
13 | time.sleep(5) # Let the user actually see something!
14 | driver.quit()
--------------------------------------------------------------------------------
/tests/chrome-headless.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # chrome_yun.py
3 | # From https://github.com/pyzzled/selenium/tree/master/headless_browser explained at
4 | # https://medium.com/@pyzzled/running-headless-chrome-with-selenium-in-python-3f42d1f5ff1d
5 |
6 | from selenium import webdriver
7 | from selenium.webdriver.chrome.options import Options
8 | import os
9 |
10 | # instantiate a chrome options object so you can set the size and headless preference
11 | chrome_options = Options()
12 | chrome_options.add_argument("--headless")
13 | chrome_options.add_argument("--window-size=1920x1080")
14 |
15 | # download the chrome driver from https://sites.google.com/a/chromium.org/chromedriver/downloads and put it in the
16 | # current directory
17 | chrome_driver = os.getcwd() +"\\chromedriver.exe"
18 |
19 | ### Launch:
20 |
21 | # go to Google and click the I'm Feeling Lucky button
22 | driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver)
23 | driver.get("https://www.google.com")
24 | lucky_button = driver.find_element_by_css_selector("[name=btnI]")
25 | lucky_button.click()
26 |
27 | # capture the screen
28 | driver.get_screenshot_as_file("capture.png")
29 |
30 | # You should now have a screenshot of the I’m Feeling Lucky page in your project folder!
31 |
32 |
--------------------------------------------------------------------------------
/tests/chrome_github_login.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # chrome_pycon_search.py
3 | # from http://selenium-python.readthedocs.io/getting-started.html#selenium-remote-webdriver
4 | from selenium import webdriver
5 | from selenium.webdriver.common.keys import Keys
6 |
7 | #driver = webdriver.Chrome()
8 | driver = webdriver.Firefox()
9 |
10 | driver.get("https://github.com")
11 | assert "The world" in driver.title
12 | #elem = driver.find_element_by_name("q")
13 | elem = driver.find_elements_by_css_selector('header div.HeaderMenu div.HeaderNavlink a')
14 | print(elem) # [ div.position-relative.js-header-wrapper > header > div > div.HeaderMenu.HeaderMenu--bright.d-lg-flex.flex-justify-between.flex-auto > div > span > div > a:nth-child(1)
16 | # XPath: /html/body/div[1]/header/div/div[2]/div/span/div/a[1]
17 | # Sign in
18 | elem[0].click()
19 | #elem.send_keys("pycon")
20 | #elem.send_keys(Keys.RETURN)
21 | assert "No results found." not in driver.page_source
22 | #driver.close()
23 |
--------------------------------------------------------------------------------
/tests/chrome_pycon_search.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # chrome_pycon_search.py
3 | # from http://selenium-python.readthedocs.io/getting-started.html#selenium-remote-webdriver
4 | from selenium import webdriver
5 | from selenium.webdriver.common.keys import Keys
6 |
7 | driver = webdriver.Chrome()
8 |
9 | #driver.get("http://www.python.org")
10 | driver.get("https://github.com")
11 | assert "Python" in driver.title
12 | elem = driver.find_element_by_name("q")
13 | elem.clear()
14 | elem.send_keys("pycon")
15 | elem.send_keys(Keys.RETURN)
16 | assert "No results found." not in driver.page_source
17 | #driver.close()
18 |
--------------------------------------------------------------------------------
/tests/firefox-google-search.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # from http://www.techbeamers.com/selenium-webdriver-python-tutorial/
3 |
4 | from selenium import webdriver
5 | from selenium.webdriver.common.keys import Keys
6 |
7 | # create a new Firefox session
8 | driver = webdriver.Firefox()
9 | driver.implicitly_wait(30)
10 | driver.maximize_window()
11 |
12 | # navigate to the application home page
13 | driver.get("http://www.google.com")
14 |
15 | # get the search textbox
16 | search_field = driver.find_element_by_id("lst-ib")
17 | search_field.clear()
18 |
19 | # enter search keyword and submit
20 | search_field.send_keys("Selenium WebDriver Interview questions")
21 | search_field.submit()
22 |
23 | # get the list of elements which are displayed after the search
24 | # currently on result page using find_elements_by_class_name method
25 | lists= driver.find_elements_by_class_name("_Rm")
26 |
27 | # get the number of elements found
28 | print ("Found " + str(len(lists)) + "searches:")
29 |
30 | # iterate through each element and print the text that is
31 | # name of the search
32 |
33 | i=0
34 | for listitem in lists:
35 | print (listitem)
36 | i=i+1
37 | if(i>10):
38 | break
39 |
40 | # close the browser window
41 | driver.quit()
--------------------------------------------------------------------------------
/tests/firefox_github_ssh_add.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # firefox_github_ssh_add.py in https://github.com/wilsonmar/git-utilities
3 | # Invokes python Firefox driver to open GitHub, SSH Keys, insert what waw pbcopy to clipboard.
4 |
5 | import time, sys, argparse # getopt
6 |
7 | from selenium import webdriver
8 | from selenium.webdriver.common.keys import Keys
9 |
10 | # https://www.python-course.eu/python3_history_and_philosophy.php
11 |
12 | #def main(argv):
13 | # parser = argparse.ArgumentParser()
14 | # parser.add_argument("square", help="display a square of a given number")
15 | # args = parser.parse_args()
16 | # print(args.square**2)
17 |
18 | # print ('Number of arguments:', len(sys.argv), 'arguments.')
19 | # print ('Argument List:', str(sys.argv))
20 |
21 | #parser = argparse.ArgumentParser(description='Process selenium.')
22 | #parser.add_argument('browser', help='browser type')
23 | #args = parser.parse_args()
24 | #parser.add_argument('integers', metavar='N', type=int, nargs='+',
25 | # help='an integer for the accumulator')
26 | #parser.add_argument('--sum', dest='accumulate', action='store_const',
27 | # const=sum, default=max,
28 | # help='sum the integers (default: find the max)')
29 |
30 | #print args.accumulate(args.integers)
31 |
32 | # Create new browser session:
33 | # for opt, arg in opts:
34 | # if opt == 'firefox':
35 | # print ("webdriver.Firefox")
36 | driver = webdriver.Firefox()
37 | # elif opt == 'chrome':
38 | # # get the path of ChromeDriverServer;
39 | # dir = os.path.dirname(__file__)
40 | # chrome_driver_path = dir + "\chromedriver.exe"
41 | # print ("webdriver.Chrome")
42 | # driver = webdriver.Chrome()
43 | # elif opt == 'ie':
44 | # # get the path of IEDriverServer
45 | # dir = os.path.dirname(__file__)
46 | # ie_driver_path = dir + "\IEDriverServer.exe"
47 | # print ("webdriver.Chrome")
48 | # driver = webdriver.Chrome()
49 |
50 |
51 | driver.implicitly_wait(1) # seconds for network delays
52 | #driver.maximize_window() # so positions are consistent across sessions.
53 |
54 | ### Navigate to the application home/landing page:
55 | driver.get("https://www.github.com/")
56 | assert "The world's leading" in driver.title
57 |
58 | #search_field = driver.find_element_by_id("lst-ib")
59 | #search_field.clear()
60 |
61 | ### get the number of elements found:
62 | #print ("Found " + str(len(lists)) + "searches:")
63 |
64 | ### Get to Sign-in page:
65 | # elem = driver.find_element_by_name("Sign in")
66 | # elem.send_keys(Keys.RETURN)
67 | # elem.clear()
68 |
69 | ### Sign-in form:
70 | #assert "Sign-in" in driver.title
71 | #elem = driver.find_element_by_name("login") # within Form
72 | #elem.clear()
73 | #elem.send_keys("UserID") # from ./secrets.sh
74 |
75 | #elem = driver.find_element_by_name("password")
76 | #elem.clear()
77 | #elem.send_keys("password") # from ./secrets.sh via MacOS Clipboard.
78 |
79 | #elem = driver.find_element_by_name("Sign In") # Green button
80 | #elem.send_keys(Keys.RETURN)
81 |
82 | ### New SSH Key:
83 | #elem = driver.find_element_by_name("SSH Key")
84 | #elem = driver.find_element_by_name("SSH key field")
85 | #elem.clear()
86 | #elem.send_keys("SSH Key") # from file (not Clipboard)
87 | #elem.send_keys(Keys.RETURN)
88 |
89 | #assert "No results found." not in driver.page_source
90 |
91 | #driver.quit()
92 |
93 | #if __name__ == "__main__":
94 | # main(sys.argv[1:])
--------------------------------------------------------------------------------
/tests/firefox_pycon_search.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # firefox_pycon_search.py
3 | # from http://selenium-python.readthedocs.io/getting-started.html#selenium-remote-webdriver
4 | from selenium import webdriver
5 | from selenium.webdriver.common.keys import Keys
6 |
7 | driver = webdriver.Firefox()
8 |
9 | driver.get("http://www.python.org")
10 | assert "Python" in driver.title
11 | elem = driver.find_element_by_name("q")
12 | elem.clear()
13 | elem.send_keys("pycon")
14 | elem.send_keys(Keys.RETURN)
15 | assert "No results found." not in driver.page_source
16 | #driver.close()
17 |
--------------------------------------------------------------------------------
/tests/firefox_unittest.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # python_firefox_unittest.py
3 | # from https://saucelabs.com/resources/articles/getting-started-with-webdriver-in-python-on-osx
4 | import unittest
5 | from selenium import webdriver
6 | from selenium.webdriver.common.by import By
7 |
8 | class WebDriverPythonBasics(unittest.TestCase):
9 | def setUp(self):
10 | self.browser = webdriver.Firefox()
11 |
12 | def test_saucelabs_homepage_header_displayed(self):
13 | self.browser.get('http://saucelabs.com')
14 | header = self.browser.find_element(By.ID, 'site-header')
15 | self.assertTrue(header.is_displayed())
16 |
17 | def tearDown(self):
18 | self.browser.close()
19 |
20 | if name == 'main':
--------------------------------------------------------------------------------
/tests/jenkins_secret_setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # jenkins_secret_chrome.py in https://github.com/wilsonmar/git-utilities/tree/master/tests/
3 | # Call pattern:
4 | # python tests/jenkins_secret_chrome.py 'chrome' $JENKINS_PORT $JENKINS_SECRET jenkins.png
5 |
6 | #import argparse # https://docs.python.org/2/howto/argparse.html
7 | import sys
8 | import pytz, time
9 | from datetime import datetime, tzinfo, timedelta
10 | from random import randint
11 |
12 | from selenium import webdriver
13 | from selenium.webdriver.common.keys import Keys
14 |
15 | # From timestamps.py
16 | def iso8601_local():
17 | class local_tz(tzinfo):
18 | def utcoffset(self, dt):
19 | ts = time.time()
20 | offset_in_seconds = (datetime.fromtimestamp(ts) - datetime.utcfromtimestamp(ts)).total_seconds()
21 | return timedelta(seconds=offset_in_seconds)
22 | return datetime.now().replace(microsecond=randint(0, 999999)).replace(tzinfo=local_tz()).isoformat()
23 | # print(iso8601_local()+" = ISO8601 time at local time zone offset, with random microseconds")
24 |
25 | driver=sys.argv[1]
26 | jenkins_port=sys.argv[2]
27 | jenkins_secret=sys.argv[3]
28 | #picture_path=sys.argv[3]
29 | print('driver=', driver, ', port=', jenkins_port, ', secret=', jenkins_secret)
30 |
31 | # TODO: #parser = argparse.ArgumentParser("simple_example")
32 | #parser.add_argument("counter", help="An integer will be increased by 1 and printed.", type=int)
33 | #args = parser.parse_args()
34 | #print(args.counter + 1)
35 |
36 | if driver == "chrome":
37 | print("chrome being used ...")
38 | driver = webdriver.Chrome()
39 | elif driver == "firefox":
40 | print("chrome being used ...")
41 | driver = webdriver.Firefox()
42 |
43 | driver.get("http://localhost:" + jenkins_port) # TODO: pass port in
44 | assert "Jenkins [Jenkins]" in driver.title # bail out if not found. Already processed.
45 | #time.sleep(5) # to see it.
46 |
47 | #
48 | secret = driver.find_element_by_id('security-token')
49 | secret.send_keys(jenkins_secret)
50 | secret.submit()
51 | time.sleep(8) # to give it time to work.
52 |
53 | # If the secret has already been processed:
54 | # INFO: Session node0vq5f7379gwo49h7hz67yatn37 already being invalidated
55 |
56 | # Take a picture (screen shot) of "Getting Started, Customize Jenkins"
57 | driver.save_screenshot('jenkins_secret_chrome.py.' +iso8601_local()+ '.png')
58 | assert "SetupWizard [Jenkins]" in driver.title
59 | #time.sleep(5) # to see it
60 |
61 | driver.dispose()
62 |
--------------------------------------------------------------------------------
/tests/phantomjs-duck-search-1120x550.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # from https://realpython.com/headless-selenium-testing-with-python-and-phantomjs/
3 | import unittest
4 | from selenium import webdriver
5 |
6 |
7 | class TestOne(unittest.TestCase):
8 |
9 | def setUp(self):
10 | self.driver = webdriver.PhantomJS()
11 | self.driver.set_window_size(1120, 550)
12 |
13 | def test_url(self):
14 | self.driver.get("http://duckduckgo.com/")
15 | self.driver.find_element_by_id(
16 | 'search_form_input_homepage').send_keys("realpython")
17 | self.driver.find_element_by_id("search_button_homepage").click()
18 | self.assertIn(
19 | "https://duckduckgo.com/?q=realpython", self.driver.current_url
20 | )
21 |
22 | def tearDown(self):
23 | self.driver.quit()
24 |
25 | if __name__ == '__main__':
26 | unittest.main()
--------------------------------------------------------------------------------
/tests/phantomjs-duck.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # from https://realpython.com/headless-selenium-testing-with-python-and-phantomjs/
3 | import unittest
4 | from selenium import webdriver
5 |
6 |
7 | class TestOne(unittest.TestCase):
8 |
9 | def setUp(self):
10 | self.driver = webdriver.PhantomJS()
11 | self.driver.set_window_size(1120, 550)
12 |
13 | def test_url(self):
14 | self.driver.get("http://duckduckgo.com/")
15 | self.driver.find_element_by_id(
16 | 'search_form_input_homepage').send_keys("realpython")
17 | self.driver.find_element_by_id("search_button_homepage").click()
18 | self.assertIn(
19 | "https://duckduckgo.com/?q=realpython", self.driver.current_url
20 | )
21 |
22 | def tearDown(self):
23 | self.driver.quit()
24 |
25 | if __name__ == '__main__':
26 | unittest.main()
--------------------------------------------------------------------------------
/tests/phantomjs-smoke.js:
--------------------------------------------------------------------------------
1 | // phantomjs-smoke.js in https://github.com/wilsonmar/git-utilities
2 | // Smoke test for installation.
3 | "use strict";
4 | console.log('Hello, from tests/phantomjs-smoke.js!');
5 | phantom.exit();
6 |
--------------------------------------------------------------------------------
/tests/timestamps.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # timestamps.py
3 |
4 | import pytz, time
5 | from datetime import datetime, tzinfo, timedelta
6 | from random import randint
7 |
8 | def iso8601_utc():
9 | class simple_utc(tzinfo):
10 | def tzname(self,**kwargs):
11 | return "UTC"
12 | def utcoffset(self, dt):
13 | return timedelta(0)
14 | return datetime.utcnow().replace(tzinfo=simple_utc()).isoformat()
15 | #print(iso8601_utc()+" = ISO8601 time at +00:00 UTC (Zulu time), with microseconds")
16 |
17 | def iso8601_local():
18 | class local_tz(tzinfo):
19 | def utcoffset(self, dt):
20 | ts = time.time()
21 | offset_in_seconds = (datetime.fromtimestamp(ts) - datetime.utcfromtimestamp(ts)).total_seconds()
22 | return timedelta(seconds=offset_in_seconds)
23 | return datetime.now().replace(microsecond=randint(0, 999999)).replace(tzinfo=local_tz()).isoformat()
24 | # print(iso8601_local()+" = ISO8601 time at local time zone offset, with random microseconds")
25 |
26 | print(iso8601_utc()+" = ISO8601 time at +00:00 UTC (Zulu time), with microseconds")
27 | print(iso8601_local()+" = ISO8601 time at local time zone offset, with random microseconds")
28 |
--------------------------------------------------------------------------------
/wm-ps-utils.psm1:
--------------------------------------------------------------------------------
1 | # wm-ps-utils.psm1 in https://github.com/wilsonmar/git-utilities
2 | # .psm1 = PowerShell module
3 | # .ps1 files using this needs to have this at the top of the file:
4 | # Import-Module wm-ps-utils.psm1
5 | # See https://msdn.microsoft.com/en-us/library/dd878284(v=vs.85).aspx
6 |
7 | <#
8 | .Synopsis
9 | Provides utilities for use with PowerShell.
10 | #>
11 |
12 | function Get-MacOsXsysteminformation {
13 | # From Stephane's http://powershelldistrict.com/powershell-mac-os-x/
14 | [xml]$infos = system_profiler -xml
15 | return $infos
16 | }
17 |
18 | Function Touch-File {
19 | $file = $args[0]
20 | if($file -eq $null) {
21 | throw "No filename supplied"
22 | }
23 |
24 | if(Test-Path $file)
25 | {
26 | (Get-ChildItem $file).LastWriteTime = Get-Date
27 | }
28 | else
29 | {
30 | echo $null > $file
31 | }
32 | }
33 |
34 | Function Color-All-Black {
35 |
36 | $strComputer = "."
37 |
38 | $colItems = get-wmiobject -class "Win32_Process" -namespace "root\CIMV2" `
39 | -computername $strComputer | write-output
40 |
41 | foreach ($objItem in $colItems) {
42 | # if ($objItem.WorkingSetSize -gt 3000000) {
43 | # write-host $objItem.Name, $objItem.WorkingSetSize -foregroundcolor "magenta" }
44 | # else {
45 | write-host $objItem.Name, $objItem.WorkingSetSize
46 | # }
47 | }
48 | }
49 |
50 | export-modulemember -function Touch-File
--------------------------------------------------------------------------------