找到元素并在元素上执行操作后,找不到元素

时间:2017-03-16 21:33:34

标签: protractor

我正在使用量角器,我遇到了一个奇怪的问题。我登录并执行一些测试并注销。这里一切都很好。我需要重新登录以使用另一个用户ID执行相同的测试。即使在各自的字段中输入了用户ID和密码并且登录成功完成但是进程退出而没有执行剩余测试并且我收到错误消息,第二次。以下是我的代码和错误

代码段:

ar testData = require('./Test Data/Users.json');

describe('SSUE Login', function() {

  it('Verifies user access', function() {


      browser.driver.get('https://url');
      browser.ignoreSynchronization = true;
      element(by.id('userInput')).sendKeys(testData[1].username);
      element(by.id('passwordInput')).sendKeys(testData[1].passwordField);
      element(by.id('login-button')).click();
      browser.driver.sleep(9000);
      browser.waitForAngular();

      element(by.css('.AtlanticIcon_header_logout')).getText().then(function(text){
        console.log('Login Successful '+text+' icon visible in UI');

      });
      if(element(by.xpath('//div[@class="walkme-custom-balloon-content-wrapper"]')).isPresent().then(function(){
              element(by.xpath('//div[@class="walkme-custom-balloon-content-wrapper"]/div[1]')).click();
      }));

      browser.driver.sleep(2000);
      }
  }, 90000);
});

以下是我的配置文件 注意我登录并执行6测试。在6个测试中的最后一个' gridFilter.js' 我有一个注销操作。下一步我使用其他用户ID通过' login2.js' 再次登录。用户成功进入,但登录后的下一个测试没有执行,浏览器自己重复加载,最后进程退出并在json中输出结果,我也在最后添加结果

exports.config = {
  seleniumAddress   : 'http://localhost:4444/wd/hub',
  specs             : ['login.js', 'userType.js', 'globalFilterOptions.js', 'languageTest.js', 'loadDatagrid.js', 'datagridicons.js', 'gridFilter.js', 'login2.js', 'userType.js', 'globalFilterOptions.js', 'languageTest.js', 'loadDatagrid.js', 'datagridicons.js', 'gridFilter.js', 'login3.js', 'userType.js', 'globalFilterOptions.js', 'languageTest.js', 'loadDatagrid.js', 'datagridicons.js', 'gridFilter.js', 'login4.js', 'userType.js', 'globalFilterOptions.js', 'languageTest.js', 'loadDatagrid.js', 'datagridicons.js', 'gridFilter.js', 'login5.js', 'userType.js', 'globalFilterOptions.js', 'languageTest.js', 'loadDatagrid.js', 'datagridicons.js', 'gridFilter.js', 'login6.js', 'userType.js', 'globalFilterOptions.js', 'languageTest.js', 'loadDatagrid.js', 'datagridicons.js', 'gridFilter.js'],
  // Exclude files if needed
  exclude: [],


  baseUrl: 'http://localhost:8000',
  rootElement: 'html',

  framework         : 'jasmine2',

  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
    ,print: function() {}
  },

  onPrepare: function() {
    var SpecReporter = require('jasmine-spec-reporter');
    // add jasmine spec reporter
    jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: true}));
  },

  onPrepare: function() {
    var JSONReporter = require('jasmine-json-test-reporter');
    jasmine.getEnv().addReporter(new JSONReporter({
        file: 'SSUE-Daily-Satus-Report.json',
        beautify: true,
        indentationLevel: 4 // used if beautify === true 
    }));
},


  // An array of capability objects
  multiCapabilities : [
    {
      browserName : 'chrome'

      // Add another set of specs for this browser only
      // specs: []
    }
  ]
};

以下是我转换为JSON的测试结果

"suite1": {
    "id": "suite1",
    "description": "SSUE Login",
    "fullName": "SSUE Login",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec0",
            "description": "Verifies user access",
            "fullName": "SSUE Login Verifies user access",
            "failedExpectations": [],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "passed"
        }
    ]
},
"suite2": {
    "id": "suite2",
    "description": "User Details:",
    "fullName": "User Details:",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec1",
            "description": "User type and id",
            "fullName": "User Details: User type and id",
            "failedExpectations": [],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "passed"
        }
    ]
},
"suite3": {
    "id": "suite3",
    "description": "Global Filter:",
    "fullName": "Global Filter:",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec2",
            "description": "Displays User entitled customers and inventories",
            "fullName": "Global Filter: Displays User entitled customers and inventories",
            "failedExpectations": [],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "passed"
        }
    ]
},
"suite4": {
    "id": "suite4",
    "description": "Langauge Selection : ",
    "fullName": "Langauge Selection : ",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec3",
            "description": "Test check the language options",
            "fullName": "Langauge Selection :  Test check the language options",
            "failedExpectations": [],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "passed"
        }
    ]
},
"suite5": {
    "id": "suite5",
    "description": "Datagrid Load Test :",
    "fullName": "Datagrid Load Test :",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec4",
            "description": "Datagrid Clickable in LNP",
            "fullName": "Datagrid Load Test : Datagrid Clickable in LNP",
            "failedExpectations": [],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "passed"
        }
    ]
},
"suite6": {
    "id": "suite6",
    "description": "Datagrid Icons :",
    "fullName": "Datagrid Icons :",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec5",
            "description": "Displayed after the grid loads",
            "fullName": "Datagrid Icons : Displayed after the grid loads",
            "failedExpectations": [],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "passed"
        }
    ]
},
"suite7": {
    "id": "suite7",
    "description": "Group Filter Test ",
    "fullName": "Group Filter Test ",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec6",
            "description": "Testing filtering groups",
            "fullName": "Group Filter Test  Testing filtering groups",
            "failedExpectations": [],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "passed"
        }
    ]
},
"suite8": {
    "id": "suite8",
    "description": "SSUE Login",
    "fullName": "SSUE Login",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec7",
            "description": "Verifies user access",
            "fullName": "SSUE Login Verifies user access",
            "failedExpectations": [],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "passed"
        }
    ]
},
"suite9": {
    "id": "suite9",
    "description": "SSUE Login",
    "fullName": "SSUE Login",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec8",
            "description": "Verifies user access",
            "fullName": "SSUE Login Verifies user access",
            "failedExpectations": [
                {
                    "matcherName": "",
                    "message": "Failed: No element found using locator: By(css selector, *[id=\"userInput\"])",
                    "stack": "NoSuchElementError: No element found using locator: By(css selector, *[id=\"userInput\"])\n    at WebDriverError (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\error.js:27:10)\n    at NoSuchElementError (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\error.js:242:10)\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\element.js:808:27\n    at ManagedPromise.invokeCallback_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:1379:14)\n    at TaskQueue.execute_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2913:14)\n    at TaskQueue.executeNext_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2896:21)\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2775:27\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:639:7\n    at process._tickCallback (node.js:369:9)Error\n    at ElementArrayFinder.applyAction_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\element.js:461:27)\n    at ElementArrayFinder._this.(anonymous function) [as sendKeys] (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\element.js:103:30)\n    at ElementFinder.(anonymous function) [as sendKeys] (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\element.js:829:22)\n    at Object.<anonymous> (C:\\Protector\\SSUE_Daily_Status\\login3.js:11:35)\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasminewd2\\index.js:94:23\n    at new ManagedPromise (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:1082:7)\n    at controlFlowExecute (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasminewd2\\index.js:80:18)\n    at TaskQueue.execute_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2913:14)\n    at TaskQueue.executeNext_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2896:21)\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2820:25\nFrom: Task: Run it(\"Verifies user access\") in control flow\n    at Object.<anonymous> (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasminewd2\\index.js:79:14)\n    at attemptAsync (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1916:24)\n    at QueueRunner.run (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1871:9)\n    at QueueRunner.execute (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1859:10)\n    at Spec.Env.queueRunnerFactory (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:697:35)\n    at Spec.execute (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:359:10)\n    at Object.fn (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:2479:37)\n    at attemptAsync (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1916:24)\n    at QueueRunner.run (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1871:9)\n    at QueueRunner.execute (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1859:10)\nFrom asynchronous test: \nError\n    at Suite.<anonymous> (C:\\Protector\\SSUE_Daily_Status\\login3.js:6:3)\n    at addSpecsToSuite (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:833:25)\n    at Env.describe (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:802:7)\n    at jasmineInterface.describe (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:3375:18)\n    at Object.<anonymous> (C:\\Protector\\SSUE_Daily_Status\\login3.js:4:1)\n    at Module._compile (module.js:409:26)\n    at Object.Module._extensions..js (module.js:416:10)\n    at Module.load (module.js:343:32)\n    at Function.Module._load (module.js:300:12)",
                    "passed": false,
                    "expected": "",
                    "actual": ""
                }
            ],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "failed"
        }
    ]
},
"suite10": {
    "id": "suite10",
    "description": "SSUE Login",
    "fullName": "SSUE Login",
    "failedExpectations": [],
    "status": "finished",
    "specs": [
        {
            "id": "spec9",
            "description": "Verifies user access",
            "fullName": "SSUE Login Verifies user access",
            "failedExpectations": [
                {
                    "matcherName": "",
                    "message": "Failed: No element found using locator: By(css selector, *[id=\"userInput\"])",
                    "stack": "NoSuchElementError: No element found using locator: By(css selector, *[id=\"userInput\"])\n    at WebDriverError (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\error.js:27:10)\n    at NoSuchElementError (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\error.js:242:10)\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\element.js:808:27\n    at ManagedPromise.invokeCallback_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:1379:14)\n    at TaskQueue.execute_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2913:14)\n    at TaskQueue.executeNext_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2896:21)\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2775:27\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:639:7\n    at process._tickCallback (node.js:369:9)Error\n    at ElementArrayFinder.applyAction_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\element.js:461:27)\n    at ElementArrayFinder._this.(anonymous function) [as sendKeys] (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\element.js:103:30)\n    at ElementFinder.(anonymous function) [as sendKeys] (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\element.js:829:22)\n    at Object.<anonymous> (C:\\Protector\\SSUE_Daily_Status\\login4.js:13:35)\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasminewd2\\index.js:94:23\n    at new ManagedPromise (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:1082:7)\n    at controlFlowExecute (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasminewd2\\index.js:80:18)\n    at TaskQueue.execute_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2913:14)\n    at TaskQueue.executeNext_ (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2896:21)\n    at C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\selenium-webdriver\\lib\\promise.js:2820:25\nFrom: Task: Run it(\"Verifies user access\") in control flow\n    at Object.<anonymous> (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasminewd2\\index.js:79:14)\n    at attemptAsync (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1916:24)\n    at QueueRunner.run (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1871:9)\n    at QueueRunner.execute (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1859:10)\n    at Spec.Env.queueRunnerFactory (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:697:35)\n    at Spec.execute (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:359:10)\n    at Object.fn (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:2479:37)\n    at attemptAsync (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1916:24)\n    at QueueRunner.run (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1871:9)\n    at QueueRunner.execute (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:1859:10)\nFrom asynchronous test: \nError\n    at Suite.<anonymous> (C:\\Protector\\SSUE_Daily_Status\\login4.js:6:3)\n    at addSpecsToSuite (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:833:25)\n    at Env.describe (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:802:7)\n    at jasmineInterface.describe (C:\\Users\\surbhat\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\jasmine\\node_modules\\jasmine-core\\lib\\jasmine-core\\jasmine.js:3375:18)\n    at Object.<anonymous> (C:\\Protector\\SSUE_Daily_Status\\login4.js:4:1)\n    at Module._compile (module.js:409:26)\n    at Object.Module._extensions..js (module.js:416:10)\n    at Module.load (module.js:343:32)\n    at Function.Module._load (module.js:300:12)",
                    "passed": false,
                    "expected": "",
                    "actual": ""
                }
            ],
            "passedExpectations": [],
            "pendingReason": "",
            "status": "failed"
        }
    ]
},

1 个答案:

答案 0 :(得分:1)

您可以在代码中添加browser.pause,看看您的浏览器处于什么状态。您可能会注意到您仍然登录或用户名输入不存在(可能应用的工作流程会记住用户名) )。这不能从您的代码或堆栈跟踪中得出结论,而是尝试它。

这就是我想要的:

  • 导航到登录页面
  • 使用用户0登录
  • 注销
  • browser.pause并检查浏览器的状态

类似的东西:

describe('login and logout', () => {
  beforeEach(() => {
    // navigate to login page
  });

  it('should be logged in user 0', () => {
    element(by.id('userInput')).sendKeys(testData[0].username);
    element(by.id('passwordInput')).sendKeys(testData[0].passwordField);
    element(by.id('login-button')).click();

    // assertions about logging in
    // process to log out
    // assertions about logging out
  });

  // this spec should not run but we'll leave it in.
  it('should be logged in user 1', () => {
    element(by.id('userInput')).sendKeys(testData[1].username);
    element(by.id('passwordInput')).sendKeys(testData[1].passwordField);
    element(by.id('login-button')).click();

    // assertions about logging in
    // process to log out
    // assertions about logging out
  });

  afterEach(() => {
    // stop here to see what's going on with your browser.
    // in the window, navigate to your login page. possibly your
    // username input does not exist for various reasons. maybe this 
    // is a bug.
    browser.pause();
  });
});