import gulp from "gulp";
export default function (cb) {
console.log("Gulp running");
cb();
}Introduction to automated testing / notebook
Introduction to automated testing
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
import gulp from "gulp";
// Add any new imports here
// Our latest default export
// export default ...
// Add any new task exports here
// export function ...
// export function ... import htmltidy from "gulp-htmltidy"; export function html() {
return gulp
.src("src/index.html")
.pipe(htmltidy())
.pipe(gulp.dest("build"));
} export default html; import autoprefixer from "gulp-autoprefixer";
import csslint from "gulp-csslint"; export function css() {
return gulp
.src("src/style.css")
.pipe(csslint())
.pipe(csslint.formatter("compact"))
.pipe(
autoprefixer({
cascade: false,
}),
)
.pipe(gulp.dest("build"));
} export default gulp.series(html, css); import babel from "gulp-babel";
import jshint from "gulp-jshint"; export function js() {
return gulp
.src("src/main.js")
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(
babel({
presets: ["@babel/env"],
}),
)
.pipe(gulp.dest("build"));
} export default gulp.series(html, css, js);export function watch() {
gulp.watch("src/*.html", html);
gulp.watch("src/*.css", css);
gulp.watch("src/*.js", js);
} const axios = require("axios");
const bsUser = "BROWSERSTACK_USERNAME";
const bsKey = "BROWSERSTACK_ACCESS_KEY";
const baseUrl = `https://${bsUser}:${bsKey}@www.browserstack.com/automate/`;
function getPlanDetails() {
axios.get(`${baseUrl}plan.json`).then((response) => {
console.log(response.data);
});
/* Response:
{
automate_plan: <string>,
terminal_access: <string>.
parallel_sessions_running: <int>,
team_parallel_sessions_max_allowed: <int>,
parallel_sessions_max_allowed: <int>,
queued_sessions: <int>,
queued_sessions_max_allowed: <int>
}
*/
}
getPlanDetails();function getBuilds() {
axios.get(`${baseUrl}builds.json`).then((response) => {
console.log(response.data);
});
/* Response:
[
{
automation_build: {
name: <string>,
hashed_id: <string>,
duration: <int>,
status: <string>,
build_tag: <string>,
public_url: <string>
}
},
{
automation_build: {
name: <string>,
hashed_id: <string>,
duration: <int>,
status: <string>,
build_tag: <string>,
public_url: <string>
}
},
// …
]
*/
}function getSessionsInBuild(build) {
const buildId = build.automation_build.hashed_id;
axios.get(`${baseUrl}builds/${buildId}/sessions.json`).then((response) => {
console.log(response.data);
});
/* Response:
[
{
automation_session: {
name: <string>,
duration: <int>,
os: <string>,
os_version: <string>,
browser_version: <string>,
browser: <string>,
device: <string>,
status: <string>,
hashed_id: <string>,
reason: <string>,
build_name: <string>,
project_name: <string>,
logs: <string>,
browser_url: <string>,
public_url: <string>,
appium_logs_url: <string>,
video_url: <string>,
browser_console_logs_url: <string>,
har_logs_url: <string>,
selenium_logs_url: <string>
}
},
{
automation_session: {
// …
}
},
// …
]
*/
}function getSessionDetails(session) {
const sessionId = session.automation_session.hashed_id;
axios.get(`${baseUrl}sessions/${sessionId}.json`).then((response) => {
console.log(response.data);
});
/* Response:
{
automation_session: {
name: <string>,
duration: <int>,
os: <string>,
os_version: <string>,
browser_version: <string>,
browser: <string>,
device: <string>,
status: <string>,
hashed_id: <string>,
reason: <string>,
build_name: <string>,
project_name: <string>,
logs: <string>,
browser_url: <string>,
public_url: <string>,
appium_logs_url: <string>,
video_url: <string>,
browser_console_logs_url: <string>,
har_logs_url: <string>,
selenium_logs_url: <string>
}
}
*/
} const SauceLabs = require("saucelabs").default;
(async () => {
const myAccount = new SauceLabs({
username: "your-sauce-username",
password: "your-sauce-api-key",
});
// Get full WebDriver URL from the client depending on region:
console.log(myAccount.webdriverEndpoint);
// Get job details of last run job
const jobs = await myAccount.listJobs("your-sauce-username", {
limit: 1,
full: true,
});
console.log(jobs);
})(); const TestingBot = require("testingbot-api");
let tb = new TestingBot({
api_key: "your-tb-key",
api_secret: "your-tb-secret",
});
tb.getTests((err, tests) => {
console.log(tests);
});