小编Din*_*ent的帖子

在Selenium中每个元素使用多个定位器的优点/缺点?

我正在测试一个仍在开发中的网站.

DOM中元素的id,类,文本或位置通常会发生变化.然后我一直在使用的定位器将无法再找到该元素.

但功能仍然正常运行.当没有实际的回归时,我不希望几个测试失败.

因此,我没有为每个元素设置一个定位器,而是有一组定位器.

public static final ArrayList<By> LOGIN_ANCHOR_LOCATORS = new ArrayList<By>();

static {
     LOGIN_ANCHOR_LOCATORS.add(By.id("loginLink"));
     LOGIN_ANCHOR_LOCATORS.add(By.linkText("Login"));
     LOGIN_ANCHOR_LOCATORS.add(By.xpath("/html/body/div[5]/a"));         
}
Run Code Online (Sandbox Code Playgroud)

我找到元素的方法如下所示:

public WebElement locateElement(ArrayList<By> locators){

    // create an element to return
    WebElement element = null;

    // until the desired element is found...
    while (element == null){

        // loop through the locators
        for (By locator : locators){

            // try to find by locator
            element = customWait.until(ExpectedConditions.presenceOfElementLocated(locator));

            // if not found...
            if (element == null){

                // log the failure
                logFailingLocator(locator);
            }
        }
    }
    return …
Run Code Online (Sandbox Code Playgroud)

java testing selenium automated-tests webdriver

8
推荐指数
1
解决办法
1359
查看次数

如何在 CodeceptJS 中尝试 Catch

我在我的页面对象中这样做:

try{
    I.selectOption(this.SELECT, this.OPTION);
}
catch(error){
    I.say('Option missing, but thats sometimes expected ' + error);
}
Run Code Online (Sandbox Code Playgroud)

但是当定位器与选项元素不匹配时,它仍然无法通过测试。

我想赶上并继续测试,而不会失败。

更新:

看起来这取决于 try 块中的内容。

如果我在那里放一个断言,比如I.see('something');然后不跳过 catch 块。但是 try 块中的非断言,例如I.selectOption('something')抛出未被 catch 捕获的错误。

javascript try-catch node.js webdriver-io codeceptjs

7
推荐指数
1
解决办法
2372
查看次数

无法在Java Servlet中反序列化JSON

我的端点无法理解传入的JSON.

这是端点:

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.hibernate.Query;
import org.hibernate.Session;
import org.json.JSONObject;
...

@POST
@Path("/{department}/{team}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response handleJSON(JSONObject json , @PathParam("department") String department, @PathParam("team") String team){ 

    MyObj myObj = new MyObj();

    myObj.setDepartment(department);
    myObj.setTeam(team);
    myObj.setPlatform(json.optString("platform"));

    saveObj(myObj);

  return Response.ok(true).build();

}
Run Code Online (Sandbox Code Playgroud)

我使用Postman发布包含"platform"的键/值的JSON,标题为:Content-Typeasapplication/json

但是我得到了这个例外: com.owlike.genson.JsonBindingException: Could not deserialize to type class org.json.JSONObject

看起来问题与以下内容有关: Illegal character at row 0 and column 1 expected { …

java rest json servlets jersey

6
推荐指数
1
解决办法
4298
查看次数

python3之后的离子"启动未定义错误"

当我运行时ionic start helloWorld blank,我收到以下错误:

Error with start undefined
Error Initializing app: There was an error with the spawned command: npminstall
Run Code Online (Sandbox Code Playgroud)

当我最后一次尝试(几个月前)时,上面的命令没有错误.现在我已经尝试更新ionic,但仍然是同样的错误.

我最近用Anaconda来获取python3.所以我担心这可能与此有关.我尝试了一个别名(这里建议),但仍然得到相同的错误.

我试过通过anaconda降级,用

conda install python=2.7.3
Run Code Online (Sandbox Code Playgroud)

但仍然从离子中获得相同的错误.

Running ionic info提供以下输出:

Cordova CLI: 6.5.0 
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
ios-deploy version: 1.9.0 
ios-sim version: 5.0.8 
OS: macOS
Node Version: v9.4.0
Xcode version: Xcode 9.4.1 Build version 9F2000
Run Code Online (Sandbox Code Playgroud)

跑步npm -v节目5.6.0.

python macos npm ionic-framework

6
推荐指数
1
解决办法
201
查看次数

如何在同步nodejs函数中等待promise?

我使用异步方法创建了一个包含我的用户凭据的解密文件:

  initUsers(){

    // decrypt users file
    var fs = require('fs');
    var unzipper = require('unzipper');

    unzipper.Open.file('encrypted.zip')
            .then((d) => {
                return new Promise((resolve,reject) => {
                    d.files[0].stream('secret_password')
                        .pipe(fs.createWriteStream('testusers.json'))
                        .on('finish',() => { 
                            resolve('testusers.json'); 
                        });
                });
            })
            .then(() => {
                 this.users = require('./testusers');

            });

  },
Run Code Online (Sandbox Code Playgroud)

我从同步方法调用该函数。然后我需要在同步方法继续之前等待它完成。

doSomething(){
    if(!this.users){
        this.initUsers();
    }
    console.log('the users password is: ' + this.users.sample.pword);
}
Run Code Online (Sandbox Code Playgroud)

console.log之前执行this.initUsers();完成。我怎样才能让它等待?

asynchronous callback node.js promise async-await

5
推荐指数
1
解决办法
6636
查看次数

如何从 WebDriver Sampler 中设置 JMeter Vars?

// I had previously used a CSS/JQuery extractor to get a URL from a page and add it to JMeter vars - accessing it here
var pageURL = "${valueFromJmeterVars}";

// navigate to that url
WDS.browser.get(pageURL); 

// selecting an element
var button = wait.until(pkg.ExpectedConditions.visibilityOfElementLocated(pkg.By.cssSelector(buttonLocator)));                                                                                                                                               

// log desired boolean value to console, so I can confirm is as expected
WDS.log.info('reserveASpotButton:' + reserveASpotButton.isEnabled());

// add my boolean to JMeter vars, so I can access later from beanshell post-processor (where I do my assertions) …
Run Code Online (Sandbox Code Playgroud)

javascript automated-tests webdriver jmeter jmeter-plugins

2
推荐指数
1
解决办法
4810
查看次数