Hi I am trying to write mocha tests for my react application that leverage selenium-webdriver.
I have a few questions but help either of them would help so I can move forward.
First of all, ideally, I would like to share the same webdriver sessions across my different tests since I do not care about what order they run. I just want to load the webpage once, run all of the tests and then close the webpage. Is this possible? I initially put my before and after cases in a different file outside of a describe and it was working fine...but then I could not access the instance of the driver in any of my test files.
If sharing the same session is not possible, then how can I solve the error below which occurs when I try to run two specFiles..
Here is the error:
$ grunt test-e2e Running "mochatest:e2e" (mochatest) task Running Mocha tests on files /Users/userName/Desktop/myReactApp/tests/e2e/testSpecOne.js /Users/userName/Desktop/myReactApp/tests/e2e/testSpecTwo.js Error: The previously configured ChromeDriver service is still running. You must shut it down before you may adjust its configuration. at Error (native) at Object.setDefaultService (/Users/userName/Desktop/myReactApp/node_modules/selenium-webdriver/chrome.js:264:11) at Object.<anonymous> (/Users/userName/Desktop/myReactApp/tests/e2e/testSpecTwo.js:8:8) at Module._compile (module.js:556:32) at loader (/Users/userName/Desktop/myReactApp/node_modules/babel-register/lib/node.js:144:5) at Object.require.extensions.(anonymous function) [as .js] (/Users/userName/Desktop/myReactApp/node_modules/babel-register/lib/node.js:154:7) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12)
A typical test looks like this:
import assert from 'assert'; import test from 'selenium-webdriver/testing'; import webdriver, {By, until} from 'selenium-webdriver'; import chrome from 'selenium-webdriver/chrome'; import chromedriver from 'chromedriver'; import helpers from './helpers.js'; chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build()); test.describe('Main page', () => { let driver = new webdriver .Builder() .withCapabilities(webdriver.Capabilities.chrome()) .build(); test.before(() => { helpers.launchTheApp(driver, 'http://localhost:8000/myApp', 'elementOne', 10000); }); test.after(() => { helpers.closeTheApp(driver); }) test.it('Test some items appear', () => { helpers.checkIfElementIsPresent(driver, By.className, 'elementOne'); helpers.checkIfElementIsPresent(driver, By.className, 'elementTwo'); helpers.checkIfElementIsPresent(driver, By.className, 'elementThree'); }); });
I am using a grunt-mocha-test to run these tests configured like this
e2e:{ options: { timeout: 3000000, ignoreLeaks: true, ui: 'bdd', run: true, log: true, reporter: typeof process.env.FUSION_BUILD_GENERATED === 'undefined' ? 'spec' : 'xunit-file', grep: grunt.option('grep') }, src: ['tests/e2e/**/**/*Spec.js'] }
0 comments:
Post a Comment