我正在尝试使用Selenium
,WebDriverJS
和Jasmine
创建测试,以验证只要使用拖动li
元素向右移动-drop 选择,不应再显示。这是我的代码片段:
it('should make the card disappear when the UI is swiped right', function() {
var card1 = driver.findElement(webdriver.By.css('.slide:nth-last-child(1)'));
var card1Move = driver.executeScript('arguments[0].setAttribute("style", "right:250px")', card1);
driver.actions()
.mouseMove(card1)
.mouseDown()
.mouseMove(card1Move)
.mouseUp()
.perform();
driver.findElement(webdriver.By.css('.slide:nth-last-child(1)')).isDisplayed()
.then(function(elem) {
expect(elem).toBe(false);
});
})
该功能似乎正常,但我收到以下错误:
Failures:
1) Swiping method should make the card disappear when the UI is swiped right
Message:
TypeError: location.getRawId is not a function
Stack:
TypeError: location.getRawId is not a function
at webdriver.ActionSequence.mouseMove (/Users/.../node_modules/selenium-webdriver/lib/webdriver/actionsequence.js:108:46)
at Object.<anonymous> (/Users/.../tests/index.js:27:14)
根据测试,错误在.mouseMove(card1Move)
方法中。
你知道造成这个问题的原因和解决方法吗?提前感谢您的回复!
答案 0 :(得分:1)
将[DataMember(EmitDefaultValue = false)]
public string Title { get; set; }
替换为mouseMove(card1Move)
e.g。 mouseMove({x: offsetFromCenter, y: offsetFromCenter})
会将100px移动到card1的中心右侧。
答案 1 :(得分:1)
目前你也可以
app.get('/loadThisWeeksRevenue/:userId', function(req, res, next) {
//todays date info using momentjs
var startOfToday = moment().startOf('day');
var endOfToday = moment().endOf('day');
var oneDayAgo = moment(startOfToday).subtract(1, 'days');
var twoDaysAgo = moment(startOfToday).subtract(2, 'days');
var threeDaysAgo = moment(startOfToday).subtract(3, 'days');
var fourDaysAgo = moment(startOfToday).subtract(4, 'days');
var fiveDaysAgo = moment(startOfToday).subtract(5, 'days');
var sixDaysAgo = moment(startOfToday).subtract(6, 'days');
var sevenDaysAgo = moment(startOfToday).subtract(7, 'days');
//set variables for the past 7 days revenue
var sevenDaysAgoRevenue = 0;
var sixDaysAgoRevenue = 0;
var fiveDaysAgoRevenue = 0;
var fourDaysAgoRevenue = 0;
var threeDaysAgoRevenue = 0;
var twoDaysAgoRevenue = 0;
var oneDayAgoRevenue = 0;
var todaysRevenue = 0;
//Calculate 7 days ago revenue
Sale
.find({ owner: req.params.userId, created_at: {$gte: sevenDaysAgo, $lt: sixDaysAgo} })
.exec(function(err, sales) {
if (err) { return next(err); } //check for error
sales.map(sale => {
sevenDaysAgoRevenue += sale.total;
});
});
//Calculate 6 days ago revenue
Sale
.find({ owner: req.params.userId, created_at: {$gte: sixDaysAgo, $lt: fiveDaysAgo} })
.exec(function(err, sales) {
if (err) { return next(err); } //check for error
sales.map(sale => {
sixDaysAgoRevenue += sale.total;
});
});
//Calculate 1 day ago revenue
Sale
.find({ owner: req.params.userId, created_at: {$gte: oneDayAgo, $lt: startOfToday} })
.exec(function(err, sales) {
if (err) { return next(err); } //check for error
sales.map(sale => {
oneDayAgoRevenue += sale.total;
});
});
//Calculate today's revenue
Sale
.find({ owner: req.params.userId, created_at: { $gte: startOfToday, $lt: endOfToday}})
.exec(function(err, sales) {
if (err) { return next(err); } //check for error
sales.map(sale => {
todaysRevenue += sale.total;
});
});
var dataRowsForWeeksRevenue = [
[new Date(sevenDaysAgo), sevenDaysAgoRevenue],
[new Date(sixDaysAgo), sixDaysAgoRevenue],
[new Date(fiveDaysAgo), fiveDaysAgoRevenue],
[new Date(fourDaysAgo), fourDaysAgoRevenue],
[new Date(threeDaysAgo), threeDaysAgoRevenue],
[new Date(twoDaysAgo), twoDaysAgoRevenue],
[new Date(oneDayAgo), oneDayAgoRevenue],
[new Date(), todaysRevenue]
];
res.status(200).json(dataRowsForWeeksRevenue);
});
正是这样做的 - .dragAndDrop(card1, { x: 100, y: 0 })
请参阅here
答案 2 :(得分:1)
我在量角器中遇到了同样的错误&#34;失败:location.getRawId不是函数&#34; - 我的问题是我找不到的元素。