mcdcorp / opentest

Open source test automation tool for web applications, mobile apps and APIs
https://getopentest.org
MIT License
452 stars 108 forks source link

Opentest | Issue while implementing script on ios devices on BrowserStack. #191

Closed srivastavasunaina8 closed 4 years ago

srivastavasunaina8 commented 5 years ago

My scripts are not running on ios devices on browserstack, but the same is running fine on android devices. When I raised the ticket on browserstack, they said that is because of "execute async JS code" called internally by the used framework. Is there any work around by which I can execute the scripts on ios devices as they are working fine for android.

adrianth commented 5 years ago

Please provide the error information from the test session log so I can identify what is the code that fails. Did you try running your iOS tests on a local device to see if that works?

srivastavasunaina8 commented 5 years ago

Hey,

I am able to execute the same script written in JAVA on ios device, but when I try to execute it using opentest, I am not able to perform any action after launching the URL.

I have attached the log file for your reference.

PFB the snapshot of code I am using:

PFB the snapshot of code I am using: Login.yaml:

description: Portal Login actions:

Main Class: From this class I am just calling the macro.

description: Verify the first page(active page) is white, bold and underlined and left arrow is invisible on Search results pagea tags: [UI] actors:

The same code is running on android but not on ios. I am not using 'Injecting JavaScript' command with the endpoint 'execute_async' anywhere.

Can you please suggest me how I can execute the scripts on ios mobile, as the same scripts are executing on safari web as well.

Thanks, Sunaina

On Fri, Sep 6, 2019 at 10:26 PM Adrian Theodorescu notifications@github.com wrote:

Please provide the error information from the test session log so I can identify what is the code that fails. Did you try running your iOS tests on a local device to see if that works?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mcdcorp/opentest/issues/191?email_source=notifications&email_token=ANDE27G2SKE7SUAQMFZNUPTQIKDVNA5CNFSM4IUE3YA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6DNWXI#issuecomment-528931677, or mute the thread https://github.com/notifications/unsubscribe-auth/ANDE27GH7WVZXW6X2A324CLQIKDVNANCNFSM4IUE3YAQ .

Injecting JavaScriptvar callback = arguments[arguments.length - 1]; var rootSelector = '[ng-app]'; var getNg1Hooks = function(selector, injectorPlease) { function tryEl(el) { try { if (!injectorPlease && angular.getTestability) { var $$testability = angular.getTestability(el); if ($$testability) { return {$$testability: $$testability}; } } else { var $injector = angular.element(el).injector(); if ($injector) { return {$injector: $injector}; } } } catch(err) {} } function trySelector(selector) { var els = document.querySelectorAll(selector); for (var i = 0; i < els.length; i++) { var elHooks = tryEl(els[i]); if (elHooks) { return elHooks; } } } if (selector) { return trySelector(selector); } else if (window.TESTABILITYNG1_APP_ROOT_INJECTOR) { var $injector = window.TESTABILITY__NG1_APP_ROOT_INJECTOR__; var $$testability = null; try { $$testability = $injector.get('$$testability'); } catch (e) {} return {$injector: $injector, $$testability: $$testability}; } else { return tryEl(document.body) || trySelector('[ng-app]') || trySelector('[ng:app]') || trySelector('[ng-controller]') || trySelector('[ng:controller]'); } } try { if (window.angular && !(window.angular.version && window.angular.version.major > 1)) { / ng1 / var hooks = getNg1Hooks(rootSelector); if (hooks.$$testability) { hooks.$$testability.whenStable(callback); } else if (hooks.$injector) { hooks.$injector.get('$browser'). notifyWhenNoOutstandingRequests(callback); } else if (!!rootSelector) { throw new Error('Could not automatically find injector on page: "' + window.location.toString() + '". Consider using config.rootEl'); } else { throw new Error('root element (' + rootSelector + ') has no injector.' + ' this may mean it is not inside ng-app.'); } } else if (rootSelector && window.getAngularTestability) { var el = document.querySelector(rootSelector); window.getAngularTestability(el).whenStable(callback); } else if (window.getAllAngularTestabilities) { var testabilities = window.getAllAngularTestabilities(); var count = testabilities.length; var decrement = function() { count--; if (count === 0) { callback(); } }; testabilities.forEach(function(testability) { testability.whenStable(decrement); }); } else if (!window.angular) { throw new Error('window.angular is undefined. This could be either ' + 'because this is a non-angular page or because your test involves ' + 'client-side navigation, which can interfere with Protractor\'s ' + 'bootstrapping. See http://git.io/v4gXM for details'); } else if (window.angular.version >= 2) { throw new Error('You appear to be using angular, but window.' + 'getAngularTestability was never set. This may be due to bad ' + 'obfuscation.'); } else { throw new Error('Cannot get testability API for unknown angular ' + 'version "' + window.angular.version + '"'); } } catch (err) { callback(err.message); }-

adrianth commented 5 years ago

OK, I know why this problem happens. OpenTest injects some JavaScript code into the browser that waits for JavaScript code to finish executing before it performs the click action. This is to account for dynamically generated HTML elements. This script is actually coming from the ngWebdriver project. I think that the BrowserStack might have a problem with this script. I will add some parameter for the OpenTest actor that can be used to control this functionality.

I am confused as to why the test fails, because the exceptions are properly handled in the test actor code (basically any potential exception that is thrown by this code is ignored). Could you please provide the complete error section from the test session log?

srivastavasunaina8 commented 5 years ago

Hey Adrian,

PFA the error log from test session.

Please let me know in case there is any work around for the execution.

Looking forward fro your positive response.

Thanks, Sunaina

On Tue, Sep 10, 2019 at 12:16 AM Adrian Theodorescu < notifications@github.com> wrote:

OK, I know why this problem happens. OpenTest injects some JavaScript code into the browser that waits for JavaScript code to finish executing before it performs the click action. This is to account for dynamically generated HTML elements. This script is actually coming from the ngWebdriver https://github.com/paul-hammant/ngWebDriver project. I think that the BrowserStack might have a problem with this script. I will add some parameter for the OpenTest actor that can be used to control this functionality.

I am confused as to why the test fails, because the exceptions are properly handled in the test actor code (basically any potential exception that is thrown by this code is ignored). Could you please provide the complete error section from the test session log?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mcdcorp/opentest/issues/191?email_source=notifications&email_token=ANDE27B4FHFESRBJLLLPMODQI2KW5A5CNFSM4IUE3YA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6IUMJQ#issuecomment-529614374, or mute the thread https://github.com/notifications/unsubscribe-auth/ANDE27DGD6OG5KPTXQBNYNDQI2KW5ANCNFSM4IUE3YAQ .

ERROR: java.lang.Exception: Failed executing test UI/JobSearch/938/JobSearch_MARCEL-T1693_FaqQuestionDownArrowClick, segment 1 at org.getopentest.base.TestActor.executeTestSegment(TestActor.java:2118) at org.getopentest.base.TestActor.runOneSession(TestActor.java:2839) at org.getopentest.base.TestActor.runOneSession(TestActor.java:2875) at org.getopentest.Main.main(Main.java:20) Caused by: java.lang.RuntimeException: There was an error while executing action no. 1 (login) in segment 1 of test UI/JobSearch/938/JobSearch_MARCEL-T1693_FaqQuestionDownArrowClick. The action definition was: { "action": "org.getopentest.base.MacroAction", "macro": "login" } at org.getopentest.base.TestActor.executeTestSegment(TestActor.java:2076) ... 3 more Caused by: java.lang.RuntimeException: Failed executing action org.getopentest.base.MacroAction (no arguments were provided) at org.getopentest.base.TestActor.executeActionByDef(TestActor.java:1773) at org.getopentest.base.TestActor.executeTestSegment(TestActor.java:2026) ... 3 more Caused by: java.lang.Exception: There was an error executing macro action login (no arguments were provided) at org.getopentest.base.TestActor.executeMacroActionByName(TestActor.java:1922) at org.getopentest.base.TestActor.executeActionByDef(TestActor.java:1653) ... 4 more Caused by: java.lang.RuntimeException: There was an error while executing action no. 2 (org.getopentest.selenium.Click) in macro login. The action definition was: { "action": "org.getopentest.selenium.Click", "args": { "locator": { "xpath": "//button[@type = 'button']" } }, "description": "Click the continue button" } at org.getopentest.base.TestActor.executeMacroActionByDef(TestActor.java:1874) at org.getopentest.base.TestActor.executeMacroActionByName(TestActor.java:1914) ... 5 more Caused by: java.lang.RuntimeException: Failed executing action org.getopentest.selenium.Click with arguments {"locator":{"xpath":"//button[@type = 'button']"}} at org.getopentest.base.TestActor.executeActionByDef(TestActor.java:1773) at org.getopentest.base.TestActor.executeMacroActionByDef(TestActor.java:1839) ... 6 more Caused by: java.lang.RuntimeException: Failed clicking on element By.xpath: //button[@type = 'button'] at org.getopentest.selenium.Click.run(Click.java:34) at org.getopentest.base.TestActor.executeAction(TestActor.java:1497) at org.getopentest.base.TestActor.executeActionByClassName(TestActor.java:1557) at org.getopentest.base.TestActor.executeActionByDef(TestActor.java:1657) ... 7 more Caused by: org.openqa.selenium.WebDriverException: Session not started or terminated (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z' System info: host: 'WKWIN7989696', ip: '10.102.70.135', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181' Driver info: org.openqa.selenium.remote.RemoteWebDriver Capabilities {64bit: false, acceptSslCert: false, acceptSslCerts: false, appium_port: 8081, automationName: XCUITest, bootstrapPath: /usr/local/.browserstack/co..., browser: iphone, browserName: safari, browser_name: safari, browser_version: 12.1, browserstack.appiumLogs: true, browserstack.debug: false, browserstack.ie.noFlash: false, browserstack.isTargetBased: false, browserstack.tunnelIdentifier: , browserstack.video: true, browserstack.video.disableWaterMark: false, databaseEnabled: false, detected_language: selenium/3.12.0 (java windows), device: iphone, deviceName: iPhone XS, deviceOrientation: portrait, javascriptEnabled: true, locationContextEnabled: false, mobile: {browser: mobile, version: iPhone XS-12.1}, networkConnectionEnabled: false, newCommandTimeout: 300, noReset: true, orientation: PORTRAIT, orig_os: ios, osVersion: 12, os_version: 12, platform: MAC, platformName: MAC, platformVersion: 12.1, proxy_type: node, realMobile: true, real_mobile: true, safariIgnoreFraudWarning: true, safariInitialUrl: http://mobile-internet-chec..., takesScreenshot: true, udid: 00008020-001269082EB8003A, useXctestrunFile: true, version: 12.1, wda_port: 8401, webStorageEnabled: false, webkitResponseTimeout: 20000} Session ID: 4a29c0ac5dfd9fadfd16765e7ec6e94491593789 *** Element info: {Using=xpath, value=//button[@type = 'button']} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166) at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:344) at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:423) at org.openqa.selenium.By$ByXPath.findElements(By.java:348) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:305) at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895) at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44) at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:183) at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:180) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248) at org.getopentest.selenium.core.SeleniumTestAction.getElement(SeleniumTestAction.java:57) at org.getopentest.selenium.core.SeleniumTestAction.getElement(SeleniumTestAction.java:49) at org.getopentest.selenium.Click.run(Click.java:29) ... 10 more

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.