Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'selenium-webdriver' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
basic.execute(driver, 'sendKeys', 'h4[about="v-fs:EnterQuery"]+div[class="form-group"] input', "Cannot find input field", timeStamp);
// Нажимаем поиск и удостоверяемся что в результатах поиска появился созданный выше документ
driver.wait
(
function () {
basic.execute(driver, 'click', 'h4[about="v-fs:EnterQuery"]+div[class="form-group"] button[id="submit"]', "Cannot click on submit button");
driver.sleep(basic.FAST_OPERATION); // Иначе слишком часто щелкает поиск
return driver.findElement({css:'span[href="#params-ft"]+span[class="badge"]'}).getText().then(function (txt) {
return txt == '1';
});
},
basic.EXTRA_SLOW_OPERATION
).thenCatch(function (e) {basic.errorHandler(e, "Cannot find person, after save operation");});
driver.wait
(
webdriver.until.elementTextContains(driver.findElement({css:'div[id="search-results"] span[property="v-s:middleName"]'}),timeStamp),
basic.FAST_OPERATION
).thenCatch(function (e) {basic.errorHandler(e, "Found person differs from saved person");});
console.timeEnd("testPerson");
driver.quit();
});
driver.findElement(By.css('#addApiBacklogItemForm button')).click()
.then(function() {
driver.sleep(1000);
});
// Verify
var infoElement = driver.findElement(By.css('#addApiBacklogItemForm select + span'));
infoElement.getText().then(function(text) {
assert.equal('Priority is required', text);
});
// Close modal form
driver.findElement(By.css('[aria-labelledby="apiBacklogFormModalLabel"] button')).click()
.then(function() {
driver.sleep(1000);
});
});
test.it('10.9 should cancel delete api', function() {
// Navigate to Settings tab
driver.findElement(By.id('api-settings-tab')).click()
.then(function() {
driver.sleep(1000);
});
// Click on Delete button
driver.findElement(By.id('delete-api')).click()
.then(function() {
driver.sleep(1000);
});
// Cancel deletion
driver.findElement(By.xpath('//*[text()="Cancel"]')).click()
.then(function() {
driver.sleep(1000);
});
});
test.describe( 'Public Posts:', function() {
test.before( 'Restart app', function() {
return driverManager.resetApp();
} );
test.describe( 'Publish a Public Post', function() {
const blogPostTitle = dataHelper.randomPhrase();
const blogPostQuote = 'The foolish man seeks happiness in the distance. The wise grows it under his feet.\n— James Oppenheim';
const blogTag = 'tag-' + new Date().getTime();
test.it( 'Can log in and open post editor', function() {
let loginFlow = new LoginFlow( driver );
return loginFlow.loginAndStartNewPost();
} );
test.it( 'Can fill out title', function() {
this.editorPage = new EditorPage( driver );
return this.editorPage.enterTitle( blogPostTitle );
} );
test.xit( 'Can fill out body', function() { // Temporarily not adding a body to the post pending further troubleshooting
return this.editorPage.enterContent( blogPostQuote );
}
// Use webdriverjs to create a Selenium Client
var browserIdx = 0;
beforeEach(function () {
this.timeout(30000);
browser = new webdriver.Builder().usingServer().withCapabilities({ 'browserName': 'firefox' }).build()
browser.manage().window().maximize();
return browser.get(urlTest);
});
afterEach(function () {
return browser.quit();
});
test.describe("Firefox Test Suite", function () {
this.timeout(mochaTimeout);
test.describe("Page Load Components", function () {
test.it("Title Loaded", function () {
browser.wait(until.elementLocated(webdriver.By.className('searchHeaderText')));
browser.findElement(webdriver.By.className('searchHeaderText')).getText().then(function (text) {
expect(text).to.deep.equal("EXPLORE OUR DATA - Beta Version");
});
});
test.it("Contact Email Loaded", function () {
browser.wait(until.elementLocated(webdriver.By.id('contactEmail')));
browser.findElement(webdriver.By.id('contactEmail')).getText().then(function (text) {
expect(text).to.deep.equal("data.itsjpo@dot.gov");
});
});
// ...if that element's text matches ...
if (text === datafield_label) {
return elem.isDisplayed().then(function (is_displayed) {
// ...and that element is currently displayed...
if (is_displayed === true) {
// ...then store the content of the "for" attribute (which should be an id in this case)
return elem.getAttribute('for').then(function (id) {
return id;
});
}
});
}
});
});
webdriver.promise.all(datafields).then(function (elements) {
// The datafields variable currently is an array of all html elements matching the
// "label.ODRFieldLabel" css selector...however, every entry that didn't match
// and was not visible is currently undefined, and should be
// filtered out...
var matching_datafields = elements.filter(function (elem) {
if (typeof elem !== "undefined")
return true;
});
if (matching_datafields.length === 0)
throw('No visible datafield has the label "' + datafield_label + '"');
// console.log( matching_datafields );
// Now, for each id stored in "matching_datafields"...
matching_datafields.forEach(function (id) {
beforeEach(function (done) {
result = undefined;
sinon.stub(subject.driver, 'executeScript').onFirstCall().returns(webdriver.promise.fulfilled({coverage: 'object'}));
subject.driver.executeScript.onSecondCall().returns(webdriver.promise.rejected(new Error('error')));
var promised = expectedWrappedObject.expectedWrappedFunction('first arg', 'second arg');
promised.then(function (output) {
result = output;
done();
}); // a lack of reject path here implies (unfortunately) that this should NOT reject
});
it('calls the wrapped function with those arguments', function (done) {
BASE_URL = process.env.BASE_URL;
} else {
throw "Set BASE_URL to be the root of the compiler directory";
}
let refreshPagePerTest;
if (process.env.BROWSER_TEST_REFRESH) {
refreshPagePerTest = process.env.BROWSER_TEST_REFRESH;
} else {
refreshPagePerTest = false;
console.log("Browser tests occur in the same page instance. To refresh the page between tests, set 'BROWSER_TEST_REFRESH' to 'true'");
}
let leave_open = process.env.LEAVE_OPEN === "true" || false;
var chromeOptions = new seleniumChrome
.Options();
if (process.env.SHOW_BROWSER === "false") {
chromeOptions = chromeOptions.headless();
console.log("Running headless (may not work with Firefox). You can set SHOW_BROWSER=true to see what's going on");
}
let args = [];
const ffCapabilities = webdriver.Capabilities.firefox();
ffCapabilities.set('moz:firefoxOptions', {
binary: PATH_TO_BROWSER,
'args': args
});
// Working from https://developers.google.com/web/updates/2017/04/headless-chrome#drivers
const chromeCapabilities = webdriver.Capabilities.chrome();
async function withSelenium(test) {
const builder = new WD.Builder()
.forBrowser('firefox');
// on Travis CI we run headless; setting up Xvfb is
// just annoying and not very useful
if (process.env.TRAVIS) {
builder
.setFirefoxOptions(
new firefox.Options().headless()
)
.setChromeOptions(
new chrome.Options().headless()
);
}
const driver = builder.build();
try {
await test(driver);
} finally {
driver.quit();
}
}
function runSeleniumTests() {
const profile = new firefox.Profile(profileDir);
// Configure profile
Object.keys(autoConfig).forEach((pref) => {
console.log(`Set pref ${pref} to ${autoConfig[pref]}`);
// profile.setPreference(pref, autoConfig[pref]);
});
// Prepare chromium webdriver
const firefoxOptions = new firefox.Options()
.setProfile(profile)
.setBinary(firefoxBin);
// Enable verbose logging
const prefs = new logging.Preferences();
prefs.setLevel(logging.Type.BROWSER, logging.Level.INFO);
const caps = selenium.Capabilities.firefox();
caps.setLoggingPrefs(prefs);
// Create webdriver
const driver = new selenium.Builder()
.forBrowser('firefox')
.withCapabilities(caps)
.setFirefoxOptions(firefoxOptions)
.build();
// Wait before click and unset checkbox
await driverHelper.waitForFieldClearable( this.driver, By.css( '#siteTitle' ) );
if ( showcase === true ) {
await driverHelper.unsetCheckbox( this.driver, By.css( '#showcase' ) );
}
if ( share === true ) {
await driverHelper.unsetCheckbox( this.driver, By.css( '#share' ) );
}
if ( sell === true ) {
await driverHelper.unsetCheckbox( this.driver, By.css( '#sell' ) );
}
if ( educate === true ) {
await driverHelper.unsetCheckbox( this.driver, By.css( '#educate' ) );
}
if ( promote === true ) {
await driverHelper.unsetCheckbox( this.driver, By.css( '#promote' ) );
}
}
}