Last active
May 7, 2021 13:24
-
-
Save raphaelrodrigues/b5f3cea0694f251e9101 to your computer and use it in GitHub Desktop.
Minium Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get alert | |
var a = page.alert(); | |
// check the message of alert | |
expect(String(a.getText())).to.be(msg); | |
// close the alert | |
a.accept(); | |
// dismiss (cancel/close) a modal | |
a.dismiss(); | |
// trying to accept an alert | |
var a = $(":root").alert(); | |
try { | |
String(a.getText()); | |
a.accept(); | |
} catch (NoAlertPresentException) { | |
// do nothing | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
browser.get("http://www.google.com"); | |
// get position of an element | |
$(":text").withName("q").apply(function () { | |
var rect = $(this).get(0).getBoundingClientRect(); | |
return { | |
left: rect.left, | |
top: rect.top, | |
right: rect.right, | |
bottom: rect.bottom | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// configurations | |
browser.configure() | |
.waitingPreset("fast").timeout(1, timeUnits.SECONDS).done() | |
.waitingPreset("very-slow").timeout(30, timeUnits.SECONDS).interval(1, timeUnits.SECONDS).done() | |
.interactionListeners() | |
.clear() | |
.add(minium.interactionListeners.onUnhandledAlert().accept().thenRetry()) | |
.add(minium.interactionListeners.onStaleElementReference().thenRetry()) | |
// get base expression | |
var base = $(":root").unless(".modal-backdrop").add(".modal-dialog"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Dimension = Packages.minium.Dimension; | |
// change dimension of the browser | |
var d = new Dimension(width, heigth); | |
browser.configure().window().setSize(d); | |
// Maximize the browser | |
browser.configure().window().maximize(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// click on a button | |
var saveBtn = $("#button").withText("Save") | |
saveBtn.click(); | |
// double click on a button | |
saveBtn.doubleClick(); | |
// Moves the mouse to the middle of the first matched element. | |
saveBtn.moveTo(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Web Drivers | |
minium: | |
webdriver: | |
desiredCapabilities: | |
browserName: chrome | |
window: | |
maximized: false | |
config: | |
baseUrl: http://www.google.com | |
slowMotionSeconds: 2 | |
fileToUpload: | |
path: ${minium.resources.dir}/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var highlightBtnListener = new JavaAdapter(DefaultInteractionListener, { | |
onBeforeEvent: function (e) { | |
$(":submit").withName("btnK").highlight(); | |
} | |
}); | |
browser.get("https://www.google.com"); | |
var root = $(":root").with(highlightBtnListener); | |
root.find("[name=q]").fill("Minium"); | |
$("[name=q]").fill("Minium"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// eval functions in the page context | |
$(":root").eval("$(this).find('title')") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hiden = $(".full").find(".strech"); | |
expect(hiden).to.exist(); | |
expect(elem).not.to.exist(); | |
var msgElem = page.mainArea.find(".ico_confirmacion > p > span").first(); | |
expect(msgElem).to.have.text("Lorum Ipsum..."); | |
expect(cells).to.have.size(12); | |
expect(myStars).to.have.attr("src", "/vgn-community-applications/skins/common/images/rating_yellow_" + n + "0.gif"); | |
// validate the URL of the section | |
expect(browser.getCurrentUrl() + "").to.be(config.baseUrl + "#/folders/" + section.toLowerCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// find elements | |
elem.find("input").rightOf(labeledFld); | |
elem.find("td :radio").withLabel(row[1]).below(tableHeader); | |
elem.find("th").withText(row[0]); | |
elem.find("input, select, textarea").withLabel(row[0]); | |
base.find(":text").withAttr("model", "remoteWebDriverUrl"); | |
base.find(".toast").filter(".toast-warning"); | |
base.find(".modal-footer .btn").withText("Open").not(":disabled"); | |
elem.withCss("font-size",size + "px"); | |
// using a regex | |
// where regex is a regular expression | |
elem.matchingText(regex); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// selectbox | |
fld.select("English"); | |
// text input | |
fld.fill("Minium"); | |
// radiobox or check box | |
fld.check(); | |
// generic way to fill a form | |
if (fld.is("select")) { | |
// selectbox | |
fld.select(val); | |
} else if (fld.is(":radio, :checkbox")) { | |
// radiobox or check box | |
fld.check(); | |
} else { | |
// text input | |
fld.fill(val); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// finds H1 element inside iframe with id myframe | |
$(":root").find("#myframe").frames().find("h1") | |
// iframes can even be nested | |
$(":root").find("#myframe").frames().find("iframe").frames(); | |
// once you've got your frame, use it like to find elements inside | |
var lowerArea = $("frame").withName("lower").frames(); | |
lowerArea.find(":input").withLabel("Name"); | |
// other frames examples | |
var desktopFrame = $(":root").find("#desktop").frames(); | |
var userFld = desktopFrame.find(".form-input").withName("username"); | |
var passFld = desktopFrame.find(".form-input").withName("password"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var LogEntries = Packages.org.openqa.selenium.logging.LogEntries; | |
var LogType = Packages.org.openqa.selenium.logging.LogType; | |
var Level = Packages.java.util.logging.Level; | |
var timeUnits = require("minium/timeunits"); | |
browser.get("http://www.google.pt"); | |
var webdriver = $(":root").nativeWebDriver(); | |
$(":root").waitTime(2, timeUnits.SECONDS); | |
var logEntries = webdriver.manage().logs().get(LogType.BROWSER).filter(Level.SEVERE); | |
if (logEntries.size() > 0) { | |
console.log("Has Errors"); | |
} else { | |
console.log("No Errors"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
var webdriver = $(":root").nativeWebDriver(); | |
var windowsHandlersIt = webdriver.getWindowHandles().iterator(); | |
var lastWindowHandle; | |
while (windowsHandlersIt.hasNext()) { | |
lastWindowHandle = windowsHandlersIt.next(); | |
} | |
var lastWindow = webdriver.switchTo().window(lastWindowHandle); | |
expect(String(lastWindow.getCurrentUrl())).to.be("https://www.google.com/"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WebDriverException = Packages.org.openqa.selenium.WebDriverException; | |
var staleElementReferenceListener, webDriverExceptionListener; | |
World(function () { | |
staleElementReferenceListener = minium.interactionListeners | |
.onStaleElementReference() | |
.thenRetry(); | |
webDriverExceptionListener = minium.interactionListeners | |
.onException(WebDriverException) | |
.thenRetry(); | |
browser.configure() | |
.interactionListeners() | |
.add(staleElementReferenceListener) | |
.add(webDriverExceptionListener); | |
}, function () { | |
browser.configure() | |
.interactionListeners() | |
.remove(staleElementReferenceListener) | |
.remove(webDriverExceptionListener); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var items = navPath.split(/\s*>\s*/); | |
items.forEach(function (text) { | |
// top menu | |
var menuItems = page.headerArea.find("#nav01 li a").waitForExistence(); | |
var leftBottomItems = page.leftMenu.find("#pie div a").waitForExistence(); | |
// may not exist | |
var leftMenuItems = page.leftMenu.find("#menuTotal li > a"); | |
if (menuItems.withText(text).checkForExistence("immediate")) { | |
menuItems.withText(text).click(); | |
} else if (leftBottomItems.withText(text).checkForExistence("immediate")) { | |
leftBottomItems.withText(text).click(); | |
} else if (leftMenuItems.withText(text).checkForExistence("immediate")) { | |
leftMenuItems.withText(text).click(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// show an element in the log | |
console.log("Uploading file: ", fullPath); | |
// view an object in log | |
console.log("user values: ", JSON.stringify(completeData)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example of a module | |
var editors = { | |
tabs : function () { | |
}, | |
console : function () { | |
var tab = editors.tabs().has(".fa-info-circle"); | |
tab.click(); | |
return editors.currentEditor(); | |
} | |
}; | |
if (typeof module !== 'undefined') module.exports = editors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var browser2 = minium.newBrowser({ | |
desiredCapabilities: { | |
browserName: 'chrome' | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var windows = $(":root").windows(); | |
var specificWindow = windows.has(windows.find("title").withText("Some title for the window")); | |
// get current url of a speficic window or tab | |
specificWindow.nativeWebDriver().getCurrentUrl(); | |
$("..").nativeWebDriver().getCurrentUrl(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// scroll to an element | |
var elem = $("#project").withText("My project"); | |
elem.scrollIntoView(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// with Css | |
var container = $(".container").withCss("display","block"); | |
// with text | |
var elem = $("a").withText("Contact us"); | |
// with attribute | |
var item = $("span").withAttr("title", "content"); | |
var input = $(":input").withAttr("placeholder", "name") | |
// below | |
var nameColumn = $("td").below($("th").withText("Name")); | |
// containingText | |
base.find(".tile-header").containingText("Settings"); | |
// right of and left of | |
var content = $("span").withAttr("title", "Channel"); | |
var item = $("a").withAttr("title", name).rightOf(typeOfContentIcon); | |
// get an element from an array | |
var comments = base.find("#social-comment"); | |
// get the first comment | |
var firstComment = comments.eq(0); | |
// Filters elements that are visible. Visibility is computed using :visible | |
browser.find("span").visible(); | |
// the above instruction will evaluate #span2 in the following scenario: | |
<span id="span1" style="display: none">Hello World</span> | |
<span id="span2">Hello World</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// send Keys | |
var keys = require("minium/keys"); | |
// send an enter in a form field | |
$("#email").sendKeys(keys.ENTER); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get the shadow DOM element to interact with elements within it | |
var shadowRoot = $(":root").applyWebElements(function () { | |
return $(document.getElementsByTagName("settings-ui")[0].shadowRoot) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When(/^I fill:$/, function (table) { | |
var hash = table.rowsHash(); | |
for (var prop in hash) { | |
var val = hash[prop]; | |
fillField(prop, val); | |
} | |
}); | |
When I fill: | |
| Tipus Operació | Ampliacions de capital amb/sense remuneració en efectiu | | |
| Nom emissió | SACYR | | |
// rows | |
Then(/^I expect to see the following folders:$/, function(datatable) { | |
datatable.raw().forEach(function (folder) { | |
var row = base.find(".items td").withText(folder); | |
expect(row).to.exist(); | |
}); | |
}); | |
Then I expect to see the following folders: | |
| Folder | | |
| Folder 1 | | |
| Folder 2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timeUnits = require("minium/timeunits"); | |
browser.configure() | |
.waitingPreset("fast") | |
.timeout(1, timeUnits.SECONDS) | |
// wait 3 seconds | |
elem.waitTime(3, timeUnits.SECONDS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var File = Packages.java.io.File; | |
var fileName = "summary.doc"; | |
var fileToUpload = new File(config.fileToUpload.path, fileName); | |
var uploadFld = $("#file"); | |
uploadFld.type(fileToUpload.getAbsolutePath()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//go to URL | |
browser.get("https://www.google.pt/"); | |
// get the current URL | |
browser.getCurrentUrl(); | |
// right click | |
browsers.contextClick(); | |
// refresh page | |
browser.navigate().refresh(); | |
// add an element | |
var link = links.withAttr("data-href", linkUrl).add(links.withAttr("href", linkUrl)); | |
// highlight an element | |
var elem = $("body"); | |
elem.highlight(); | |
// write a file | |
var File = Packages.java.io.File; | |
var FileUtils = Packages.org.apache.commons.io.FileUtils; | |
FileUtils.writeStringToFile(new File("test.txt"), "http://google.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var URL_java_net = Packages.java.net.URL; | |
var url = new URL_java_net("<url>"); | |
var http = url.openConnection(); | |
var httpResponse = String(http.getResponseCode()); | |
expect(httpResponse).to.be("200"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var floatLoading = $(".running-data .ladda-spinner [role=progressbar]"); | |
floatLoading.waitForUnexistence("very-slow"); | |
// wait for an element and fill the element | |
elem.waitForExistence("very-slow").fill("code"); | |
// check if exists immediate - | |
elem.checkForExistence("immediate") | |
var menu = elem.find("#elem li a").waitForExistence(); | |
disabledCreateBtn.waitForUnexistence("very-slow"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timeUnits = require("minium/timeunits"); | |
var base; | |
var WebDriverException = Packages.org.openqa.selenium.WebDriverException; | |
var staleElementReferenceListener, webDriverExceptionListener; | |
function retry(fn) { | |
try { | |
fn(); | |
} catch (e) { | |
browser.navigate().refresh(); | |
$(":root").waitTime(3, timeUnits.SECONDS); | |
fn(); | |
} | |
} | |
World(function () { | |
staleElementReferenceListener = minium.interactionListeners | |
.onStaleElementReference() | |
.thenRetry(); | |
webDriverExceptionListener = minium.interactionListeners | |
.onException() | |
.thenRetry(); | |
browser.configure() | |
.defaultTimeout(5, timeUnits.SECONDS) | |
.defaultInterval(100, timeUnits.MILLISECONDS) | |
.waitingPreset("fast") | |
.timeout(1, timeUnits.SECONDS) | |
.interval(100, timeUnits.MILLISECONDS) | |
.done() | |
.waitingPreset("very-slow") | |
.timeout(1, timeUnits.MINUTES) | |
.interval(1, timeUnits.SECONDS) | |
.done(); | |
browser.configure() | |
.interactionListeners() | |
.add(staleElementReferenceListener) | |
.add(webDriverExceptionListener); | |
var loading = $(".load-container").visible(); | |
var animation = $(".csui-in-transition"); | |
base = $(":root").unless(loading).unless(animation).unless(".modal-backdrop").add(".modal-dialog") | |
.with(minium.interactionListeners.onTimeout() | |
.when(loading) | |
.waitForUnexistence(loading) | |
.withWaitingPreset("very-slow") | |
.thenRetry()) | |
.with(minium.interactionListeners.slowMotion(config.slowMotionSeconds, timeUnits.SECONDS)); | |
//browser.configure().window().maximize(); | |
}, function () { | |
base = undefined; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment