Explore all Test Automation open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Test Automation

httprunner

v3.1.10

gauge-js

Gauge JS v2.4.0

jbehave-junit-runner

v2.3.1

bok-choy

Dropped support for python3.5

agent-java-testNG

Release 5.1.2

Popular Libraries in Test Automation

phantomjs

by ariya doticonc++doticon

star image 28425 doticonBSD-3-Clause

Scriptable Headless Browser

slimerjs

by laurentj doticonjavascriptdoticon

star image 2971 doticonNOASSERTION

A scriptable browser like PhantomJS, based on Firefox

httprunner

by httprunner doticongodoticon

star image 2742 doticonApache-2.0

HttpRunner 是一个开源的 API 测试工具,支持 HTTP(S) / HTTP2 / WebSocket / RPC 等网络协议,涵盖接口测试、性能测试、数字体验监测等测试类型。简单易用,功能强大,具有丰富的插件化机制和高度的可扩展能力。

php-phantomjs

by jonnnnyw doticonphpdoticon

star image 1391 doticonMIT

Execute PhantomJS commands through PHP

namazu

by osrg doticongodoticon

star image 479 doticonApache-2.0

:fish: 鯰: Programmable fuzzy scheduler for testing distributed systems

Weasel-Diesel

by mattetti doticonrubydoticon

star image 443 doticonMIT

DSL to describe, document and test web services

suave-ui

by uoziod doticoncssdoticon

star image 341 doticonMIT

UI Framework for AngularJS

AngularJS-Testing-Article

by yearofmoo-articles doticonjavascriptdoticon

star image 268 doticon

A testing repository for AngularJS

crack_gs

by ever391 doticonpythondoticon

star image 192 doticon

全国工商企业信息查询 验证码破解 滑动验证码破解示例

Trending New libraries in Test Automation

Responsible

by sbergen doticoncsharpdoticon

star image 38 doticonMIT

Reactive asynchronous automated testing utility for .NET and Unity

sangrahah

by RationaleEmotions doticonjavadoticon

star image 8 doticonApache-2.0

An annotated approach to building TestNG suites instead of working with xmls.

phantomjs-loadspeed

by danmirror doticonjavascriptdoticon

star image 4 doticon

repo loadspeed

touchdesigner-test-launcher

by magnetic-lab doticonpythondoticon

star image 4 doticon

Automated integration testing in Touch Designer from the terminal or command-line.

ApeTest

by kyubuns doticoncsharpdoticon

star image 4 doticonMIT

Smart Monkey Test for Unity

amazing-git-example

by JohnBetaCode doticonpythondoticon

star image 3 doticon

ignore this, this is just an example

staf

by Virmak doticonjavadoticon

star image 2 doticonMIT

STARK TEST AUTOMATION FRAMEWORK

delta-reporter-testng

by delta-reporter doticonjavadoticon

star image 2 doticonApache-2.0

Delta Reporter plugin for Maven testNG

robotframework-akamai

by ynohat doticonpythondoticon

star image 2 doticonMIT

Provides RobotFramework keywords for testing Akamai.

Top Authors in Test Automation

1

benfoxall

2 Libraries

star icon50

2

andris9

2 Libraries

star icon4

3

boxen

2 Libraries

star icon20

4

renatahodovan

2 Libraries

star icon36

5

getgauge

2 Libraries

star icon111

6

cyildirim

1 Libraries

star icon3

7

datakurre

1 Libraries

star icon90

8

appharbor

1 Libraries

star icon15

9

lfryc

1 Libraries

star icon6

10

ProgMiner

1 Libraries

star icon2

1

2 Libraries

star icon50

2

2 Libraries

star icon4

3

2 Libraries

star icon20

4

2 Libraries

star icon36

5

2 Libraries

star icon111

6

1 Libraries

star icon3

7

1 Libraries

star icon90

8

1 Libraries

star icon15

9

1 Libraries

star icon6

10

1 Libraries

star icon2

Trending Kits in Test Automation

No Trending Kits are available at this moment for Test Automation

Trending Discussions on Test Automation

Immediate window not executing selenium webdriver code

How to pass nested array in a postman automation test script

Firebase event tracking exclude test automation runs and qa testing events

Having issues understanding flow - HTML form data handling by vue and axios

Selenium for IntelliJ IDEA

Playwright not using the correct values from config file whilst running Mocha

Apache HTTP Client SSL how acccept all certificates for testing purposes

Eclipse-Selenium-Alternative to Thread.sleep()

Can't remove "What's New" tab from recent install of Chrome/ChromeDriver

Run step to open browser in cucumber / selenium test once before running all scenario examples then run step to close browser afterwards

QUESTION

Immediate window not executing selenium webdriver code

Asked 2022-Apr-02 at 00:22

Verified in both VS2019 and VS2022.

I just recently started noticing that I wasn't able to execute selenium webdriver code in the immediate window anymore.

Before, I know for a fact I was able to perform different driver actions in the immediate window but now I'm just getting the following message: enter image description here

Did something change recently that's causing this with selenium? I've done the thing where I use the Watch window to perform the evaluation and I guess that works OK if I'm wanting to evaluate the specific line of code the debugger is on.

One of the great things I loved about the immediate window was being able to type in code that wasn't even in my program to do some testing if I needed to. That's immeasurably helpful with writing test automation so I don't have to stop and start my debug process every time I want to try out a new piece of code.

ANSWER

Answered 2022-Apr-02 at 00:22

Pretty sure I figured out the cause. Something with the Selenium.WebDriver nuget package with a 4.0+ version causes it. I'll have to do some more digging to figure out why tho.

I tested dropping the package version down to 3.141.0 and I was able to execute code in the immediate window again.

Source https://stackoverflow.com/questions/71710996

QUESTION

How to pass nested array in a postman automation test script

Asked 2022-Mar-23 at 12:46

I'm creating test automation scripts through postman. I want to pass a nested array in postman body

1{
2   "fruit":{{fruit}},
3   "Vehicles":[
4      {
5         "car":{{car}},
6         "bike":{{bike}}
7      }
8   ]
9}
10
11

I want to pass the vehicles array.

When I executed the APIs I get these vehicles as a empty variables. data is not passing

The Response body as follows

1{
2   "fruit":{{fruit}},
3   "Vehicles":[
4      {
5         "car":{{car}},
6         "bike":{{bike}}
7      }
8   ]
9}
10
11{
12   "fruit":"mango",
13   "Vehicles":[
14      {
15         "car":{{car}},
16         "bike":{{bike}}
17      }
18   ]
19}
20

The external json data file

1{
2   "fruit":{{fruit}},
3   "Vehicles":[
4      {
5         "car":{{car}},
6         "bike":{{bike}}
7      }
8   ]
9}
10
11{
12   "fruit":"mango",
13   "Vehicles":[
14      {
15         "car":{{car}},
16         "bike":{{bike}}
17      }
18   ]
19}
20[
21   {
22      "fruit":"mango",
23      "Vehicles":[
24         {
25            "car":"BMW",
26            "bike":"YAMAHA"
27         }
28      ]
29   }
30]
31

I'm executing this with postman collection runner and data inside the nested array is not passing.

ANSWER

Answered 2022-Mar-23 at 12:44

Your request body is not valid JSON, after the values from the file have been insterted. You don't have quotation marks araound the values.

Try this:

1{
2   "fruit":{{fruit}},
3   "Vehicles":[
4      {
5         "car":{{car}},
6         "bike":{{bike}}
7      }
8   ]
9}
10
11{
12   "fruit":"mango",
13   "Vehicles":[
14      {
15         "car":{{car}},
16         "bike":{{bike}}
17      }
18   ]
19}
20[
21   {
22      "fruit":"mango",
23      "Vehicles":[
24         {
25            "car":"BMW",
26            "bike":"YAMAHA"
27         }
28      ]
29   }
30]
31{
32   "fruit":"{{fruit}}",
33   "Vehicles":[
34      {
35         "car":"{{car}}",
36         "bike":"{{bike}}"
37      }
38   ]
39}
40

Source https://stackoverflow.com/questions/71583070

QUESTION

Firebase event tracking exclude test automation runs and qa testing events

Asked 2022-Mar-18 at 17:19

We are facing an issue, where our test automation setup spoils our analytics.
There is a solution that I found just to exclude staging flavour from testing and added a feature flag to turn it on for testing purposes.

However, I see room to improve this logic, by checking if a device is in debug-view mode and allowing test-tracking only for this case. (because devices in a debug view are automatically excluded from statistics) this is what doc says

Note: To prevent your testing and development from affecting your measurements, events logged while in debug mode will be excluded from your overall Analytics data, and will not be included in your daily BigQuery export.

adb shell setprop debug.firebase.analytics.app package_name

Is there a way to check this value?

ANSWER

Answered 2022-Mar-18 at 17:19

this is a solution that I found. Hope it would be useful for someone

1/**
2 * we read user properties and if these properties contain our application id as a selected firebase analytics app
3 * we enable tracking @see https://firebase.google.com/docs/analytics/debugview#android for more details
4 */
5private fun isDebugEnabled() = try {
6    // Run the command to get properties for debug view for firebase
7    val process = Runtime.getRuntime()
8        .exec(arrayOf("/system/bin/sh", "-l", "-c", "getprop | grep debug.firebase.analytics.app"))
9    val bufferedReader = BufferedReader(InputStreamReader(process.inputStream))
10
11    // Grab the results
12    bufferedReader.readLines().any { it.contains(applicationId) }
13} catch (e: IOException) {
14    false
15}
16

Source https://stackoverflow.com/questions/71526430

QUESTION

Having issues understanding flow - HTML form data handling by vue and axios

Asked 2022-Mar-14 at 06:30

I am new to Vue and Axios and trying to use it in Salesforce Marketing Cloud - Cloud pages. Basically there are 3 parts,

  1. HTML + vue page : this is a form page, where the user is asked to input the automation name and click on send button
  2. App.js : this is build using axios and Vue.
  3. Form-hander.js (backend) : SSJS code that runs the automation.

I referred this document to build this setup -https://ampscript.xyz/how-tos/how-to-start-status-of-automation-from-marketingcloud-form/. I understand the Form-hander.js (ssjs) code and this can be skipped.

What I am not able to understand is the flow of App.js, could anyone please explain me what is happening here. I understand that on click of send button, the function in App.js - validateForm is called. Here after I don’t understand the flow of the code. From App.js is the form-handler code called ? OR the post method used in the HTML page is directly called the form-handler page and staring the automation?

Here is the code of app.js. Can some explain to me in simple terms the flow of this code, would be really helpful.

1   new Vue({
2    el: '#app',
3    data: {
4        status: 100,
5        form: {
6            name: 'My Test Automation',
7            context: 'perform'
8        },
9        endpoint: '',
10        message: ''
11    },
12    watch: {
13        status: function () {
14            if(this.status == 201 || this.status == 102) {
15                this.form.context = 'check';
16            } else {
17                this.form.context = 'perform';
18            }
19        }
20    },
21    mounted: function() {
22        this.endpoint = this.$refs.form.getAttribute('action');
23    },
24    methods: {
25        sendFormData: function() {
26            this.status = 101;
27            var $this = this;
28            axios({
29                method: 'POST',
30                url: $this.endpoint,
31                data: $this.form,
32                validateStatus: function() { return true }
33            }).then(function(result) {
34                $this.status = result.data.Status;
35                $this.message = result.data.Message;
36                $this.checkStatus();
37            }).catch(function(error) {
38                console.error(error);
39            });
40        },
41        checkStatus: function() {
42
43            var $this = this;
44            var intervalID = setInterval(function() {
45                axios({
46                    method: 'POST',
47                    url: $this.endpoint,
48                    data: $this.form,
49                    validateStatus: function() { return true }
50                }).then(function(result) {
51                    $this.status = result.data.Status;
52                    $this.message = result.data.Message;
53                    if($this.status == 200 || $this.status == 500) {
54                        clearInterval(intervalID);
55                    }
56                }).catch(function(error) {
57                    console.error(error);
58                });
59            }, 10000); 
60
61        },
62        validateForm: function() {
63            if (this.$refs.form.checkValidity() !== false) {
64                this.sendFormData();
65            }
66            this.$refs.form.classList.add('was-validated');
67        }
68
69    }
70})
71

ANSWER

Answered 2022-Mar-13 at 21:25
  1. When the components is mounted, you run the form binded action on (submit?)

  2. The action is probably binded to the sendFormData function(in methods)

  3. Inside sendFormData, there is the setup of the axios request, followed be a then callback which handles the response from the request

  4. The checkStatus function is called inside the "then" block

  5. Sends the same data back to the server every 10 seconds if the previous response doesn't have status code other than 200 or 500.

  6. ValidateForm is may binded to some onInput or onChange event on the template
    ** The watcher is always looking for the status code and updates a form context

Source https://stackoverflow.com/questions/71460076

QUESTION

Selenium for IntelliJ IDEA

Asked 2022-Mar-10 at 22:20

I am relatively new to Selenium. Currently in my company we use Eclipse to create and run our testing automation (Maven/Cucumber/Selenium). We also use IntelliJ IDEA for Java development.
My question would be if it is possible to use IntelliJ IDEA for testing automation similarly like we use Eclipse (Maven/Cucumber/Selenium)? I mean to build test automation scripts. If yes, so you could you kindly recommend any tutorial where it is explained how build those projects for IntelliJ IDEA. Thank you in advance

ANSWER

Answered 2022-Feb-03 at 14:22

this question has a simple answer. Whatever your company does in Eclipse, you can do in InteliJ.

BOTH Eclipse and InteliJ are IDE's (An integrated development environment for building applications that combines common developer tools into a single graphical user interface). So basically, consider them both like "code editors". There is really no difference in using Eclipse or InteliJ (maybe some UI differences).

Personally, I prefer InteliJ based on cleaner UI. You pick yours.

Here is one useful tutorial. Good luck :) https://www.youtube.com/watch?v=JPLk4Z0U0yQ

Source https://stackoverflow.com/questions/70972807

QUESTION

Playwright not using the correct values from config file whilst running Mocha

Asked 2022-Mar-09 at 08:58

I am building a test automation framework using JS + Playwright + Mocha and Chai. I have a problem where some values of the config files are ignored. For example the screenshot is defined to be taken only after failed tests, but it takes a screenshot after every test. I am using mocha to run the tests as in the following command:

1"scripts":{
2   "test":"mocha --recursive --timeout 100000 src/tests/*spec.js --reporter mocha-multi-reporters --reporter-options configFile=reporter.json"
3}
4

Now, looking at the screenshot function which is defined in the playwright.config.js:

1"scripts":{
2   "test":"mocha --recursive --timeout 100000 src/tests/*spec.js --reporter mocha-multi-reporters --reporter-options configFile=reporter.json"
3}
4use: {
5    screenshot: 'only-on-failure',
6},
7

Everything seems fine, in theory.

However, now running the test with the following code:

1"scripts":{
2   "test":"mocha --recursive --timeout 100000 src/tests/*spec.js --reporter mocha-multi-reporters --reporter-options configFile=reporter.json"
3}
4use: {
5    screenshot: 'only-on-failure',
6},
7afterEach(async function() {
8    await page.screenshot({path: `screenshots/${new Date().toJSON().slice(0,10)}/${this.currentTest.title.replace(/\s+/g, '_')}.png`})
9})
10

The screenshot is taken after every test. It should only take screenshots after failure.

Has someone experienced this?

Thanks

ANSWER

Answered 2022-Mar-09 at 08:58

Issue was solved by migrating to the new Playwright Test Runner from Mocha.

Then the following code works:

1"scripts":{
2   "test":"mocha --recursive --timeout 100000 src/tests/*spec.js --reporter mocha-multi-reporters --reporter-options configFile=reporter.json"
3}
4use: {
5    screenshot: 'only-on-failure',
6},
7afterEach(async function() {
8    await page.screenshot({path: `screenshots/${new Date().toJSON().slice(0,10)}/${this.currentTest.title.replace(/\s+/g, '_')}.png`})
9})
10use: {
11    screenshot: 'only-on-failure',
12},
13

This allows me to avoid running screenshot function in the afterEach hook. And produces a screenshot to a test-results folder.

Source https://stackoverflow.com/questions/71350498

QUESTION

Apache HTTP Client SSL how acccept all certificates for testing purposes

Asked 2022-Mar-04 at 16:12

I have a java cucumber test automation framework that I am using for testing apis.

Previously I was using a tool called Karate that has a simple flag ( karate.configure('ssl', { trustAll: true });) that allows you to trust all certificates.

I was hoping there would be a similar flag for use with Apache HTTP Client...but all my googling leads to long and complicated code.

This is the code I have written so far to send the .pfx file to the api

1        String keyPassphrase = "";
2
3        KeyStore keyStore = KeyStore.getInstance("PKCS12");
4        keyStore.load(new FileInputStream("src/main/resources/sslCertificates/certificate.pfx"), keyPassphrase.toCharArray());
5
6        SSLContext sslContext = SSLContexts.custom()
7                .loadKeyMaterial(keyStore, null)
8                .build();
9
10
11        //This is the httpClient that you will use to send your http request
12        CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
13
14        //Send the request
15        CloseableHttpResponse response = httpClient.execute(request);
16

but it gets rejected before it is sent saying

1        String keyPassphrase = "";
2
3        KeyStore keyStore = KeyStore.getInstance("PKCS12");
4        keyStore.load(new FileInputStream("src/main/resources/sslCertificates/certificate.pfx"), keyPassphrase.toCharArray());
5
6        SSLContext sslContext = SSLContexts.custom()
7                .loadKeyMaterial(keyStore, null)
8                .build();
9
10
11        //This is the httpClient that you will use to send your http request
12        CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
13
14        //Send the request
15        CloseableHttpResponse response = httpClient.execute(request);
16 "javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
17

How can I easily accept all certificates to get around this problem? As stated I am just testing so there is no problem with doing this.

However I do have certificate files in .pfx and .crt formats and a client.key file that could potentially be used - but I don't know how.

ANSWER

Answered 2022-Mar-04 at 13:59

I used the solution mentioned in this post:

Getting Java to accept all certs over HTTPS

There, you build a custom TrustManager and HostNameVerifier to accept any certificate and domain:

Custom implementation of HostNameVerifier:

1        String keyPassphrase = "";
2
3        KeyStore keyStore = KeyStore.getInstance("PKCS12");
4        keyStore.load(new FileInputStream("src/main/resources/sslCertificates/certificate.pfx"), keyPassphrase.toCharArray());
5
6        SSLContext sslContext = SSLContexts.custom()
7                .loadKeyMaterial(keyStore, null)
8                .build();
9
10
11        //This is the httpClient that you will use to send your http request
12        CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
13
14        //Send the request
15        CloseableHttpResponse response = httpClient.execute(request);
16 "javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
17import javax.net.ssl.HostnameVerifier;
18import javax.net.ssl.SSLSession;
19
20public class TrustAllHostNameVerifier implements HostnameVerifier {
21
22    public boolean verify(String hostname, SSLSession session) {
23        return true;
24    }
25}
26

Https connection creation:

1        String keyPassphrase = "";
2
3        KeyStore keyStore = KeyStore.getInstance("PKCS12");
4        keyStore.load(new FileInputStream("src/main/resources/sslCertificates/certificate.pfx"), keyPassphrase.toCharArray());
5
6        SSLContext sslContext = SSLContexts.custom()
7                .loadKeyMaterial(keyStore, null)
8                .build();
9
10
11        //This is the httpClient that you will use to send your http request
12        CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
13
14        //Send the request
15        CloseableHttpResponse response = httpClient.execute(request);
16 "javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
17import javax.net.ssl.HostnameVerifier;
18import javax.net.ssl.SSLSession;
19
20public class TrustAllHostNameVerifier implements HostnameVerifier {
21
22    public boolean verify(String hostname, SSLSession session) {
23        return true;
24    }
25}
26// Create a trust manager that does not validate certificate chains
27TrustManager[] trustAllCerts = new TrustManager[]{
28    new X509TrustManager() {
29        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
30            return null;
31        }
32        public void checkClientTrusted(
33            java.security.cert.X509Certificate[] certs, String authType) {
34        }
35        public void checkServerTrusted(
36            java.security.cert.X509Certificate[] certs, String authType) {
37        }
38    }
39};
40
41// Install the all-trusting trust manager
42try {
43    SSLContext sc = SSLContext.getInstance("SSL");
44    sc.init(null, trustAllCerts, new java.security.SecureRandom());
45    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
46    HttpsURLConnection.setHostnameVerifier(new TrustAllHostNameVerifier())
47} catch (Exception e) {
48  :
49  :
50}
51

Although you clarified that it's for testing purposes, it's important to remember that this is an extremely insecure solution where you lose all the protection given by the use of SSL.

Source https://stackoverflow.com/questions/71352172

QUESTION

Eclipse-Selenium-Alternative to Thread.sleep()

Asked 2022-Feb-28 at 16:38

I am relatively new to the Test Automation and in particular to the Selenium. I am using Selenium Web-driver, Eclipse. One of the biggest problems I am experiencing is that our scripts are crashing due to the Internet speed or server performance. I currently use Thread.sleep() to solve the problem. However it is not a secret that Thread.sleep() enforces waiting time till the timer is completed. I tried to find an optimised solution in example for the script below. Having looked through the posts on Stackoverflow I found solution which is provided below in the for() loop. It was suggested to use:

1jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete");
2

to ensure that action (click on the button) is completed, and if not, so to wait a little bit and to try again during the next iteration.
In my case below there would be 6 attempts as per loop. However the code brings up an error:

"Failure: Cannot invoke "Object.toString()" because the return value of "org.openqa.selenium.JavascriptExecutor.executeScript(String, Object[])" is null"

The code is:

1jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete");
2  public void SignSupportFormOnOrder() throws InterruptedException {
3        JavascriptExecutor jse = (JavascriptExecutor)GlobalVariables._browser.currentDriver;
4        ExplicitWait.until(ExpectedConditions.visibilityOf(Order_SignSupportingForms));
5        actions.moveToElement(Order_SignSupportingForms).click().perform();
6        
7        //Code working but using Thread.sleep():
8        //Thread.sleep(10000); //Need to look for an alternative solution
9        //jse.executeScript("arguments[0].click();", button_Sign);
10        /////////////////////////////////////////////////////////////////////////////////////////
11        
12        //try as alternative to Thread.sleep(...):
13        
14        for(int i=0; i < 5; i++){   
15            if(jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete"))
16                break;
17            else
18                Thread.sleep(1000);
19            }
20
21        //Thread.sleep(10000);
22    }
23

Can somebody kindly give me a suggestion what I am doing wrong and how it would be possible to overcome using Thread.sleep();

ANSWER

Answered 2022-Feb-28 at 16:38

Since clicking the button_Sign is closing some pop-up we can do some code like the following.

1jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete");
2  public void SignSupportFormOnOrder() throws InterruptedException {
3        JavascriptExecutor jse = (JavascriptExecutor)GlobalVariables._browser.currentDriver;
4        ExplicitWait.until(ExpectedConditions.visibilityOf(Order_SignSupportingForms));
5        actions.moveToElement(Order_SignSupportingForms).click().perform();
6        
7        //Code working but using Thread.sleep():
8        //Thread.sleep(10000); //Need to look for an alternative solution
9        //jse.executeScript("arguments[0].click();", button_Sign);
10        /////////////////////////////////////////////////////////////////////////////////////////
11        
12        //try as alternative to Thread.sleep(...):
13        
14        for(int i=0; i < 5; i++){   
15            if(jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete"))
16                break;
17            else
18                Thread.sleep(1000);
19            }
20
21        //Thread.sleep(10000);
22    }
23public boolean clickVisibleDisappearsLoop(String xpath1, String xpath2){
24    waitForElementToBeVisible(xpath1);
25    int counter = 0;
26    while (counter<10) {
27        try {
28            clickOnElement(xpath1);
29            waitForElementToDisappear(xpath2,4);
30            return true;
31        } catch (Throwable throwable) {
32            wait(400);
33            counter++;
34        }
35    }
36    return false;
37}
38

Methods I have used here are:

1jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete");
2  public void SignSupportFormOnOrder() throws InterruptedException {
3        JavascriptExecutor jse = (JavascriptExecutor)GlobalVariables._browser.currentDriver;
4        ExplicitWait.until(ExpectedConditions.visibilityOf(Order_SignSupportingForms));
5        actions.moveToElement(Order_SignSupportingForms).click().perform();
6        
7        //Code working but using Thread.sleep():
8        //Thread.sleep(10000); //Need to look for an alternative solution
9        //jse.executeScript("arguments[0].click();", button_Sign);
10        /////////////////////////////////////////////////////////////////////////////////////////
11        
12        //try as alternative to Thread.sleep(...):
13        
14        for(int i=0; i < 5; i++){   
15            if(jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete"))
16                break;
17            else
18                Thread.sleep(1000);
19            }
20
21        //Thread.sleep(10000);
22    }
23public boolean clickVisibleDisappearsLoop(String xpath1, String xpath2){
24    waitForElementToBeVisible(xpath1);
25    int counter = 0;
26    while (counter<10) {
27        try {
28            clickOnElement(xpath1);
29            waitForElementToDisappear(xpath2,4);
30            return true;
31        } catch (Throwable throwable) {
32            wait(400);
33            counter++;
34        }
35    }
36    return false;
37}
38
39public void wait(int delay) {
40    Uninterruptibles.sleepUninterruptibly(delay, TimeUnit.MILLISECONDS);
41}
42
43public boolean waitForElementToDisappear(String xpath){
44    try {
45        wait.until((ExpectedConditions.invisibilityOf(By.xpath(xpath))));
46        return true;
47    }catch (Throwable t){
48        return false;
49    }
50}
51

Here you can pass the XPath locator of button_Sign element as xpath1 and the XPath locator of pop-up that should close by clicking on button_Sign as xpath2.
Also, accordingly to Java conventions you should name the button_Sign as buttonSign. I would suggest naming it as signBtn or signButton.
Also, you dont have to return Booleans here, so you can simplify these methods making them void.

Source https://stackoverflow.com/questions/71296620

QUESTION

Can't remove "What's New" tab from recent install of Chrome/ChromeDriver

Asked 2022-Feb-04 at 11:18

I recently had a new VM created for Windows 10 and our test automation suite.

After I got everything installed, I ran some of our tests. However, every single time that Selenium launches ChromeDriver, I still see the "What's New" / chrome://Whats-new tab in the browser, then our tests launch in a new tab. The tests seem to work just fine, however, if I do have a failing test, we take a desktop screenshot, and of course, all we see is the What's New tab, not our actual site-under-test.

I do not see the tab when launching Chrome manually, on any user that logs into the box. It only happens with the Selenium-ChromeDriver launched browsers. Even closing the tab while a test is running doesn't permanently remove that tab.

I have never encountered this problem with ChromeDriver before and it's a difficult question to search for answers.

Chrome / ChromeDriver versions: 98.0.4758.82 (which was released on 2/2, but it also happened on the previous version)

Has anyone solved this problem recently?

ANSWER

Answered 2022-Feb-04 at 11:18

Try to use chromeOptions.AddArgument("--disable-features=ChromeWhatsNewUI");

Source https://stackoverflow.com/questions/70977605

QUESTION

Run step to open browser in cucumber / selenium test once before running all scenario examples then run step to close browser afterwards

Asked 2022-Feb-03 at 14:19

Apologies for poorly worded question. I am new to test automation and selenium / cucumber BDD and am trying to create a demo project that runs some maths expressions using google and validates the results. I want to use a scenario outline so have ..

1Scenario Outline: Enter a maths expression
2    Given User enters the maths expression <expression>
3    When the user clicks the Search button
4    Then The result of <expectedResult> is returned  
5Examples: 
6    | expression | expectedResult |
7    | 4+4 | 8 | 
8    | 5^3 | 125 |  
9

I had my steps to open the chrome browser and navigate to google in the @Before method like ..

1Scenario Outline: Enter a maths expression
2    Given User enters the maths expression <expression>
3    When the user clicks the Search button
4    Then The result of <expectedResult> is returned  
5Examples: 
6    | expression | expectedResult |
7    | 4+4 | 8 | 
8    | 5^3 | 125 |  
9@Before
10public void setup() throws Throwable {
11    System.setProperty("webdriver.chrome.driver","C:\xxx\\chromedriver.exe");
12    this.driver = new ChromeDriver();
13    this.driver.manage().window().maximize();
14    this.driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
15    this.driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
16    driver.get("https://google.com");
17    Thread.sleep(2000);
18    //agrees to the terms and conditions
19    driver.findElement(By.xpath("//*[@id=\"L2AGLb\"]/div")).click();
20}
21

When I run my feature it works but for every example in the Scenario Outline it runs the before steps (as appears to be expected behaviour from reading online) i.e. browser opens and closes for each example.

Ideally I would want the browser to open once at start, run through all examples and then close at end. Is there an appropriate method annotation that I can use to achieve this. I have tried to find the answer online but not had any luck. One post mentioned using @BeforeSuite but I just for errors when I tried to use this. Also I tried to use the @Background annotation but this did the same thing as it seems this runs for every scenario example.

Any help would be much appreciated.

ANSWER

Answered 2022-Feb-03 at 14:19

You are correct in your assertion. The Cucumber Hook @Before will execute methods tagged with this annotation before the first step of each scenario [See: Cucumber Reference]. Obviously, if you do not want to open and close the browser before and after each scenario, then you can't add that code there. Unfortunately, Cucumber does not have a hook to run "Before Suite" like JUnit or TestNG have. So, you cannot run something before all or after all like you can on those unit test platforms.

A trick I have used is to initialize the driver and then store it as a global variable in a utility class. This way, I can reuse the same instance for an entire test session. Also, you can create an init scenario and run that will your scenarios.

1Scenario Outline: Enter a maths expression
2    Given User enters the maths expression <expression>
3    When the user clicks the Search button
4    Then The result of <expectedResult> is returned  
5Examples: 
6    | expression | expectedResult |
7    | 4+4 | 8 | 
8    | 5^3 | 125 |  
9@Before
10public void setup() throws Throwable {
11    System.setProperty("webdriver.chrome.driver","C:\xxx\\chromedriver.exe");
12    this.driver = new ChromeDriver();
13    this.driver.manage().window().maximize();
14    this.driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
15    this.driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
16    driver.get("https://google.com");
17    Thread.sleep(2000);
18    //agrees to the terms and conditions
19    driver.findElement(By.xpath("//*[@id=\"L2AGLb\"]/div")).click();
20}
21@StartBrowser
22Scenario: Start browser session
23  When I initialize driver
24  Then open browser
25

In the code...

1Scenario Outline: Enter a maths expression
2    Given User enters the maths expression <expression>
3    When the user clicks the Search button
4    Then The result of <expectedResult> is returned  
5Examples: 
6    | expression | expectedResult |
7    | 4+4 | 8 | 
8    | 5^3 | 125 |  
9@Before
10public void setup() throws Throwable {
11    System.setProperty("webdriver.chrome.driver","C:\xxx\\chromedriver.exe");
12    this.driver = new ChromeDriver();
13    this.driver.manage().window().maximize();
14    this.driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
15    this.driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
16    driver.get("https://google.com");
17    Thread.sleep(2000);
18    //agrees to the terms and conditions
19    driver.findElement(By.xpath("//*[@id=\"L2AGLb\"]/div")).click();
20}
21@StartBrowser
22Scenario: Start browser session
23  When I initialize driver
24  Then open browser
25public class BrowserInitStepDefinitions {
26    @When("I initialize driver")
27    public void initializeDriver() {
28        System.setProperty("webdriver.chrome.driver","C:\xxx\\chromedriver.exe");
29        WebDriverUtils.setDriver(new ChromeDriver());
30    }
31
32    @Then ("open browser")
33    public void openBrowser() {
34        WebDriver driver = WebDriverUtils.getDriver();
35        driver.get("https://www.yourwebsite.com");
36    }
37
38    @Then ("close browser")
39    public void closeBrowser() {
40        WebDriver driver = WebDriverUtils.getDriver();
41        driver.quit();
42    }
43}
44
1Scenario Outline: Enter a maths expression
2    Given User enters the maths expression <expression>
3    When the user clicks the Search button
4    Then The result of <expectedResult> is returned  
5Examples: 
6    | expression | expectedResult |
7    | 4+4 | 8 | 
8    | 5^3 | 125 |  
9@Before
10public void setup() throws Throwable {
11    System.setProperty("webdriver.chrome.driver","C:\xxx\\chromedriver.exe");
12    this.driver = new ChromeDriver();
13    this.driver.manage().window().maximize();
14    this.driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
15    this.driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
16    driver.get("https://google.com");
17    Thread.sleep(2000);
18    //agrees to the terms and conditions
19    driver.findElement(By.xpath("//*[@id=\"L2AGLb\"]/div")).click();
20}
21@StartBrowser
22Scenario: Start browser session
23  When I initialize driver
24  Then open browser
25public class BrowserInitStepDefinitions {
26    @When("I initialize driver")
27    public void initializeDriver() {
28        System.setProperty("webdriver.chrome.driver","C:\xxx\\chromedriver.exe");
29        WebDriverUtils.setDriver(new ChromeDriver());
30    }
31
32    @Then ("open browser")
33    public void openBrowser() {
34        WebDriver driver = WebDriverUtils.getDriver();
35        driver.get("https://www.yourwebsite.com");
36    }
37
38    @Then ("close browser")
39    public void closeBrowser() {
40        WebDriver driver = WebDriverUtils.getDriver();
41        driver.quit();
42    }
43}
44public class WebDriverUtils {
45    private static WebDriver driver;
46    public static void setDriver(WebDriver webDdriver) {
47        if (driver == null) {
48            driver = webDdriver;
49        }
50    }
51    public static WebDriver getDriver() {
52        if (driver == null) {
53            throw new AssertionError("Driver is null. Initialize driver before calling this method.");
54        }
55        return driver;
56    }
57}
58

Lastly, when you call your scenarios, just remember to include these scenarios first.

1Scenario Outline: Enter a maths expression
2    Given User enters the maths expression <expression>
3    When the user clicks the Search button
4    Then The result of <expectedResult> is returned  
5Examples: 
6    | expression | expectedResult |
7    | 4+4 | 8 | 
8    | 5^3 | 125 |  
9@Before
10public void setup() throws Throwable {
11    System.setProperty("webdriver.chrome.driver","C:\xxx\\chromedriver.exe");
12    this.driver = new ChromeDriver();
13    this.driver.manage().window().maximize();
14    this.driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
15    this.driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
16    driver.get("https://google.com");
17    Thread.sleep(2000);
18    //agrees to the terms and conditions
19    driver.findElement(By.xpath("//*[@id=\"L2AGLb\"]/div")).click();
20}
21@StartBrowser
22Scenario: Start browser session
23  When I initialize driver
24  Then open browser
25public class BrowserInitStepDefinitions {
26    @When("I initialize driver")
27    public void initializeDriver() {
28        System.setProperty("webdriver.chrome.driver","C:\xxx\\chromedriver.exe");
29        WebDriverUtils.setDriver(new ChromeDriver());
30    }
31
32    @Then ("open browser")
33    public void openBrowser() {
34        WebDriver driver = WebDriverUtils.getDriver();
35        driver.get("https://www.yourwebsite.com");
36    }
37
38    @Then ("close browser")
39    public void closeBrowser() {
40        WebDriver driver = WebDriverUtils.getDriver();
41        driver.quit();
42    }
43}
44public class WebDriverUtils {
45    private static WebDriver driver;
46    public static void setDriver(WebDriver webDdriver) {
47        if (driver == null) {
48            driver = webDdriver;
49        }
50    }
51    public static WebDriver getDriver() {
52        if (driver == null) {
53            throw new AssertionError("Driver is null. Initialize driver before calling this method.");
54        }
55        return driver;
56    }
57}
58@RunWith(Cucumber.class)
59@CucumberOptions(plugin = {"pretty", "html:target/cucumber-report.html"},
60        features= "features",
61        glue= {"whatever"},
62        tags= "@StartBrowser or @MyTest1 or @MyTest2"
63        )
64public class TestRunner {
65    // code omitted
66}
67

You could (and most likely should) create a scenario to close your browser and reclaim any resources that you might've used during the execution of your tests.

Source https://stackoverflow.com/questions/70944060

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in Test Automation

Tutorials and Learning Resources are not available at this moment for Test Automation

Share this Page

share link

Get latest updates on Test Automation