Selenium


New Relic Synthetic Monitoring

var assert = require('chai').assert;

// Script-wide timeout for all wait and waitAndFind functions (in ms)
var DEFAULT_ELEMENT_TIMEOUT = 190000;   //3 mins
var DEFAULT_PAGELOAD_TIMEOUT = 240000; //4 mins
var navLinks = ["css-locator-1","css-locator-2"];

//sets element load timeout to 3 mins
$browser.manage().timeouts().implicitlyWait(DEFAULT_ELEMENT_TIMEOUT);
//sets page load timoeout to 4 mins
$browser.manage().timeouts().pageLoadTimeout(DEFAULT_PAGELOAD_TIMEOUT);

//Test all the main Nav page performances
$browser.get("http://www.sitename.com").then(function(){
    return $browser.findElement($driver.By.className("site-theme-example"));
}).then(function(){
    //Verifies the nav list has loaded
    return $browser.findElement($driver.By.className("site-nav-list-example"));
}).then(function(){
   //loops through the navLinks array
   navLinks.forEach(function(val, i, arr){
    //finds and navigates to each navLink page
    return $browser.findElement($driver.By.className(navLinks[i])).click().then(function(){
       //verifies that the nav list loaded before moving on
        return $browser.findElement($driver.By.className("site-nav-list-example")).then(function(){
            //verifies that the page logo footer at bottom of page has loaded
            return $browser.findElement($driver.By.className("site-footer-logo"));
        })
     })
  })
});

install CE edition of PyCharm

install selenium using PIP (Python package manager)

pip install -U selenium

Download selenium chrome driver and unzip it to a location and include it in the code as below

webchrometest.py

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
#from selenium.webdriver.support import expected_conditions as EC
import time

# options = webdriver.ChromeOptions()
# options.add_argument('user-agent = Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36')


browser = webdriver.Chrome(r"C:\Projects\WebTest\chromedriver.exe")
#browser.implicitly_wait(30)

browser.get('https://url/login')
assert 'example' in browser.title

def test1():
wait = WebDriverWait(webdriver, 10)
elem = browser.find_element_by_name('username')# Find the field
elem2 = browser.find_element_by_name('password')  # Find the field

#assert isinstance(elem, object)
elem.clear()
elem.send_keys('KK')
elem.send_keys(Keys.RETURN)
elem2.send_keys('1234')
elem2.send_keys(Keys.RETURN)

time.sleep ( 15 )
browser.quit()

webtestfirefox.py this example will use gecokdriver

download geckodriver and install the exe in the same location as the soure python file

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

import time

browser: webdriver = webdriver.Firefox()
browser.get('http://www.google.com')

def test1():
elem = browser.find_element_by_name("q")  # Find the search box
elem.send_keys('news')
elem.send_keys(Keys.RETURN)

 return elem

time.sleep(20)
browser.quit()

These writings represent my own personal views alone.
Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.